2 BINARY SEARCH Flashcards

1
Q

What is binary search?

A

An algorithm for efficiently searching a sorted list by repeatedly dividing the list in half.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does binary search discard during its process?

A

It discards the half of the list that does not contain the target value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or False: Binary search can be applied to unsorted data.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the primary advantage of binary search over linear scan?

A

Binary search is more efficient as it reduces the search space by half each iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define linear scan.

A

An algorithm that searches for a target value by testing each value in a list one by one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the worst-case time complexity of linear scan?

A

O(N)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In what scenario is linear scan guaranteed to find the target?

A

When the item is in the data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a key characteristic of binary search regarding data?

A

It works only on sorted data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does IndexLow represent in binary search?

A

The lowest index of the current search space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does IndexHigh represent in binary search?

A

The highest index of the current search space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does binary search determine the midpoint?

A

IndexMid = Floor((IndexHigh + IndexLow) / 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens if A[IndexMid] < target in binary search?

A

Adjust IndexLow to IndexMid + 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does binary search return if the target is not found?

A

-1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the time complexity of binary search?

A

O(log N)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What indicates the end of the search in binary search?

A

When IndexHigh < IndexLow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Fill in the blank: The binary search algorithm can be implemented using a single ______.

A

WHILE loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How can binary search be adapted for continuous data?

A

By using high and low bounds on the values themselves.

18
Q

What is the significance of binary search in computer science?

A

It illustrates the interaction between data structures and algorithms.

19
Q

True or False: Binary search guarantees both speed and correctness.

20
Q

What type of data structure does binary search utilize effectively?

A

Sorted arrays or lists.

21
Q

What is an example of a practical application of binary search?

A

Searching for a word in a dictionary.

22
Q

What do we mean by ‘absent values’ in the context of binary search?

A

Values that are not present in the list being searched.

23
Q

What is the primary concept of binary search?

A

Binary search is a method for finding a target value within a sorted array by repeatedly dividing the search interval in half.

24
Q

In the context of coffee brewing, what are the upper and lower bounds for the optimal amount of coffee grounds?

A

LowerBound = 0 tablespoons, UpperBound = 5 tablespoons.

25
What is the purpose of defining a midpoint in a binary search?
To test whether the target value lies above or below the midpoint, thus refining the search bounds.
26
What is the significance of the condition 'UpperBound – LowerBound < threshold' in binary search?
It determines when to terminate the search once the range is sufficiently small.
27
True or False: A linear scan through options is more efficient than binary search.
False.
28
What is a key advantage of binary search compared to a linear scan?
Binary search has a logarithmic runtime, significantly reducing the number of comparisons needed for large datasets.
29
What is the worst-case runtime of a linear scan?
Linear with the size of the data, requiring N comparisons.
30
What is the worst-case runtime of binary search?
Logarithmic with the size of the data set, proportional to log2 N.
31
Fill in the blank: Bisection search finds the zero of a function by tracking bounds where the function is _______ and _______.
above zero, below zero.
32
What is the relationship between problem structure and algorithm efficiency?
Designing algorithms by using the structure in the problems themselves helps create efficient solutions.
33
What happens during a bisection search?
The interval is repeatedly divided in half at the midpoint to zoom in on the value of x where the function equals zero.
34
How does binary search maintain better precision compared to a linear scan?
It narrows down the search range by halving it, allowing for more precise targeting of the optimal value.
35
Why is binary search considered a fundamental concept in computer science?
It exemplifies how to efficiently utilize data structure properties to enhance algorithm performance.
36
What is the main drawback of using a linear scan for searching?
It can be time-consuming due to the need to check every single value.
37
True or False: Binary search requires a sorted array to function.
True.
38
What is an example of a practical application of binary search beyond finding values in an array?
Determining optimal quantities, such as the ideal amount of coffee grounds.
39
What is the significance of the term 'threshold' in binary search?
It defines how small the range must be to conclude the search.
40
How does binary search differ in approach compared to linear search?
Binary search divides the search space in half at each step, while linear search examines each possible value sequentially.