Save
...
computational thinking
mod3
binary
Save
Share
Learn
Content
Leaderboard
Share
Learn
Created by
emily d
Visit profile
Cards (29)
Binary Search
continuously divides the
sorted
list, comparing the middle element with the
target
value
What is binary search?
A fundamental search
algorithm
View source
How does binary search find a target value?
It eliminates
half
of the remaining values
View source
How do you calculate the middle value in binary search?
Average of
leftmost
and
rightmost
indices
View source
What happens if the middle value is greater than the target?
Eliminate
it and values greater
View source
What happens if the middle value is less than the target?
Eliminate it and
values
less
View source
What is the final step if the target is found?
Return the
index
of the target
View source
How is the binary search represented in a binary tree format?
Root node: middle element of the
array
Left child: middle of the lower half
Right child: middle of the upper half
Follow similar pattern for remaining nodes
View source
What does the height of the binary search tree represent?
Floor
of
log base 2
of n
plus one
View source
What does each iteration of the while loop in binary search do?
Descend one level down the
tree
View source
What should you do if the target is not found in the array?
Return
negative one
View source
What are the key components of the binary search algorithm code?
Initialize
left
pointer to
zero
Initialize
right
pointer to
last element
While loop
: iterate while left ≤ right
Calculate
mid
: average of left and right
Update pointers based on comparison with
target
Return
index
if found, else return -1
View source
What is the purpose of a binary search?
To find an item in a
sorted
list
View source
How does a binary search reach its end?
It finds the
item
or exhausts the search
View source
What does a binary search do when it finds the target?
It
identifies
the
target
item in the
list
View source
What is the process of dividing in a binary search?
It repeatedly
halves
the search space
View source
What does a binary search compare?
The
target
item and the
middle
item
View source
What happens if the target item is less than the middle item?
The search continues in the
left half
View source
If the target item is greater than the middle item, what does the binary search do?
It
searches
in the
right
half
of the list
View source
What is the significance of keeping the list in order during a binary search?
It ensures the search method works
correctly
View source
What should be done if the item is not found in a binary search?
The
search
concludes without
finding
the
item
View source
What is the role of the middle item in a binary search?
It acts as a
reference point
for comparison
View source
How does a binary search handle larger or smaller items?
It adjusts the
search space
accordingly
View source
What is the final step in a binary search?
To confirm whether the
item
was found
View source
What are the steps involved in a binary search?
Start with a
sorted
list.
Compare the
target
with the middle item.
If equal, return the item.
If less, search the left half.
If greater, search the right half.
Repeat until found or exhausted.
View source
What is the initial condition for a binary search?
The list must be
sorted
View source
Why is it important to divide the search space in binary search?
To
efficiently
narrow down the possible locations
View source
What should you do if the list is not sorted before performing a binary search?
Sort the list before
searching
View source
How does the efficiency of binary search compare to linear search?
Binary search is generally
faster
View source