Menu

Search Algorithms

Card 1 of 15 0 got it 0 still learning
Question
TapClick or press space to see the answer
Answer
Search Algorithms exam questions14 questions with mark schemes and example answers
All 15 cards in this set
What is the main advantage of using a linear search algorithm?
It can be used on unordered arrays
In what scenario is a binary search algorithm more efficient than a linear search?
When searching for an item in a large, ordered array
Why can't a binary search be used on an unordered array?
Because it relies on the array being ordered to eliminate half of the search space at each step
What is the worst-case scenario for a linear search algorithm?
Finding the desired item last in the array
How does a binary search algorithm find a value in a sorted array?
By repeatedly dividing the search interval in half
What is a key limitation of the binary search algorithm?
It requires the array to be sorted
Which algorithm would be best for searching a small, unordered list of names?
Linear search
How is the middle element of the array found in a binary search algorithm?
By calculating the midpoint of the current search interval
What happens after each comparison in a binary search?
The search space is halved
Which search algorithm would you use for a dataset that changes frequently and does not remain sorted?
Linear search
What is the best case performance scenario for a linear search algorithm?
Finding the desired item on the first check
Why might a linear search be preferred over binary search in some cases?
Because of its simplicity and lack of requirement for the array to be sorted
In a binary search, if the middle value is greater than the value being searched for, what is the next step?
Create a new array with values to the left of the middle and repeat the search
What makes binary search more performant than linear search on large, sorted arrays?
Its ability to eliminate half of the search space with each comparison
How is performance generally measured for search algorithms?
By the number of comparisons or iterations needed to find the target value