What is the name of the search algorithm that loops over every item in the list to check if it contains the sought item? The binary search method is faster than searching all items but has an additional constraint. What is required of a list to use binary search?
Metropolitan State University
ICS 140 Computational Thinking with Programming
Class Exercise 11
Lecture Section
- What is the name of the search algorithm that loops over every item in the list to check if it contains the sought item?
- The binary search method is faster than searching all items but has an additional constraint. What is required of a list to use binary search?
- What does big O notation represent?
- Describe the Selection Sort algorithm.
- Describe the Insertion Sort algorithm.
- Describe the Bubble Sort algorithm.
- Describe the Merge Sort algorithm.
- For the sort algorithms above, which one will generally be the most efficient as lists grown larger?
- In addition to the increase in processing required as list grow, name another resource constraint to watch for.
- Coding sorting algorithms requires a way to swap values between 2 places in a list. Choose one of the methods that can be used and write the python code for swapping values below.
Coding Search Algorithms
Write python function that implements the sequential and binary search algorithms. Use the provided search_algorithms.py file provided to complete this exercise. In the search_algorithms.py file, you will find some functions already built that will help test out the performance of the algorithms. I have also copied the pseudocode from the assigned reading to help simplify the coding process. Write functions with the names and inputs of the routines in the commented pseudocode.
Note: Some lines of the pseudocode are not relevant to python. For example, there is no end if statement like there is in other programming languages. Lines like this can be deleted or commented out.
The output should like something like this:
Smaller lists will be very close in speed. If we test out a larger number, we should see the binary search pull away with dramatically.
Once you have coded the functions, paste the code for the 2 functions in their designated area below and take a few screenshots of your program running with different sizes of lists similar to the screenshots above.