2 BINARY SEARCH Flashcards
What is binary search?
An algorithm for efficiently searching a sorted list by repeatedly dividing the list in half.
What does binary search discard during its process?
It discards the half of the list that does not contain the target value.
True or False: Binary search can be applied to unsorted data.
False
What is the primary advantage of binary search over linear scan?
Binary search is more efficient as it reduces the search space by half each iteration.
Define linear scan.
An algorithm that searches for a target value by testing each value in a list one by one.
What is the worst-case time complexity of linear scan?
O(N)
In what scenario is linear scan guaranteed to find the target?
When the item is in the data.
What is a key characteristic of binary search regarding data?
It works only on sorted data.
What does IndexLow represent in binary search?
The lowest index of the current search space.
What does IndexHigh represent in binary search?
The highest index of the current search space.
How does binary search determine the midpoint?
IndexMid = Floor((IndexHigh + IndexLow) / 2)
What happens if A[IndexMid] < target in binary search?
Adjust IndexLow to IndexMid + 1.
What does binary search return if the target is not found?
-1
What is the time complexity of binary search?
O(log N)
What indicates the end of the search in binary search?
When IndexHigh < IndexLow.
Fill in the blank: The binary search algorithm can be implemented using a single ______.
WHILE loop
How can binary search be adapted for continuous data?
By using high and low bounds on the values themselves.
What is the significance of binary search in computer science?
It illustrates the interaction between data structures and algorithms.
True or False: Binary search guarantees both speed and correctness.
True
What type of data structure does binary search utilize effectively?
Sorted arrays or lists.
What is an example of a practical application of binary search?
Searching for a word in a dictionary.
What do we mean by ‘absent values’ in the context of binary search?
Values that are not present in the list being searched.
What is the primary concept of binary search?
Binary search is a method for finding a target value within a sorted array by repeatedly dividing the search interval in half.
In the context of coffee brewing, what are the upper and lower bounds for the optimal amount of coffee grounds?
LowerBound = 0 tablespoons, UpperBound = 5 tablespoons.