Check your understanding of the previous reading: sorting and searching, binary search, and Insertion Sort.
Which is faster, sorting a list of elements or searching the same list of elements?
Select one answer, then check.
True or False: time that an algorithm takes is always dependent on the size of the input, not on the actual values of the input.
Select one answer, then check.
True or False: binary search would not work on an unsorted list of numbers.
Select one answer, then check.
True or False: binary search only works on numbers, because you cannot order strings.
Select one answer, then check.
"apple" < "banana" is True, and sorted sorts a list of strings.sorted works on strings too), so a sorted list of strings can be searched with binary search.Why is binary search faster than iterative search?
Select one answer, then check.
Each time a search algorithm considers a possible item in a list, that is considered a “check”.
| # | Question | Checks |
|---|---|---|
| 1 | In the best case, how many checks would iterative search need to find an item in a list of 100 numbers? | |
| 2 | In the worst case, how many checks would iterative search need to find an item in a list of 100 numbers? | |
| 3 | In the best case, how many checks would binary search need to find an item in a list of 100 numbers? | |
| 4 | In the worst case, how many checks would binary search need to find an item in a list of 100 numbers? |
The best case is when the item is the first one the search looks at. For the worst case of binary search, use the formula from the reading: log₂(number of elements), plus one final check for the element you land on.
1 1 check: the item is the first element. 2 100 checks: the item is the last element, so every element is checked. 3 1 check: the item is right at the midpoint. 4 7 checks: log₂(100) is about 6.6, so the search halves the list 6 times, and the element it lands on still has to be checked.
Which of the following is an accurate summary of Insertion Sort?
We recommend you check out this page: https://visualgo.net/en/sorting
Select one answer, then check.
while loop drags the current element back to its place among them.for loop.Which of the following are valid reasons that Computer Scientists study sorting and searching so much?
Select every answer that applies, then check.
sorted function, for example.