Recall & Review
beginner
What is a linear search algorithm?
Linear search is a method of finding a target value by checking each element in a list one by one from start to end until the target is found or the list ends.
Click to reveal answer
beginner
What condition must be true for binary search to work?
The list must be sorted in order (either ascending or descending) before performing a binary search.
Click to reveal answer
intermediate
How does binary search reduce the search area?
Binary search compares the target with the middle element of the list. If the target is smaller, it searches the left half; if larger, it searches the right half. This halves the search area each time.
Click to reveal answer
beginner
Which search algorithm is faster for large sorted lists: linear or binary search?
Binary search is faster for large sorted lists because it reduces the search area by half each step, while linear search checks elements one by one.
Click to reveal answer
intermediate
Explain the worst-case time complexity of linear and binary search.
Linear search worst-case time is O(n), meaning it may check every element. Binary search worst-case time is O(log n), meaning it divides the search area repeatedly, making it much faster on large lists.
Click to reveal answer
Which search algorithm requires the list to be sorted?
✗ Incorrect
Binary search only works correctly if the list is sorted. Linear search works on any list.
In linear search, what happens if the target is not in the list?
✗ Incorrect
Linear search checks each element until the end if the target is not found.
What is the main advantage of binary search over linear search?
✗ Incorrect
Binary search is faster on large sorted lists because it halves the search area each step.
If a list has 16 elements, how many steps does binary search take in the worst case?
✗ Incorrect
Binary search takes log2(16) = 4 steps in the worst case.
Which search algorithm checks elements one by one?
✗ Incorrect
Linear search checks each element one by one until it finds the target or reaches the end.
Describe how linear search works using a real-life example.
Think about looking for a book on a messy shelf.
You got /3 concepts.
Explain the steps of binary search and why the list must be sorted.
Imagine searching for a word in a dictionary.
You got /4 concepts.