0
0
DSA Goprogramming~5 mins

Binary Search Iterative Approach in DSA Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main idea behind the binary search iterative approach?
It repeatedly divides the sorted list in half to find the target value, by comparing the middle element and narrowing the search range until the target is found or the range is empty.
Click to reveal answer
beginner
In binary search iterative approach, what happens if the middle element is less than the target?
The search continues in the right half of the list, so the start index is moved to mid + 1.
Click to reveal answer
beginner
Why is binary search only applicable on sorted lists?
Because it relies on comparing the target with the middle element to decide which half to search next, which only works if the list is sorted.
Click to reveal answer
intermediate
What is the time complexity of the binary search iterative approach?
O(log n), where n is the number of elements in the list, because the search space halves each step.
Click to reveal answer
beginner
Show the key variables used in the binary search iterative approach and their roles.
start: the beginning index of the current search range; end: the ending index of the current search range; mid: the middle index calculated as start + (end - start) / 2; target: the value to find.
Click to reveal answer
What does the binary search iterative approach do when the middle element equals the target?
AReturns the middle index as the target position
BSearches the left half of the list
CSearches the right half of the list
DEnds with failure
Which condition ends the binary search iterative loop without finding the target?
Astart == end
Bstart > end
Cmid == target
Dstart < end
How is the middle index calculated in binary search iterative approach to avoid overflow?
Amid = end - start
Bmid = (start + end) / 2
Cmid = start * end
Dmid = start + (end - start) / 2
What is the first step in the binary search iterative approach?
ACheck if the list is sorted
BReturn -1 if list is empty
CInitialize start and end indexes
DCalculate mid index
If the target is smaller than the middle element, what does the binary search iterative approach do?
AMoves end to mid - 1
BMoves start to mid + 1
CReturns mid
DEnds search
Explain step-by-step how the binary search iterative approach finds a target in a sorted list.
Think about how the search range changes each step.
You got /5 concepts.
    Describe why binary search iterative approach is more efficient than linear search on large sorted lists.
    Consider how many elements are checked in each method.
    You got /4 concepts.