0
0
DSA Typescriptprogramming~5 mins

Binary Search as Divide and Conquer in DSA Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main idea behind the divide and conquer approach in binary search?
Divide the problem into smaller parts by splitting the array into halves, then solve the smaller part where the target might be, repeating until found or empty.
Click to reveal answer
beginner
In binary search, what condition tells you to search the left half of the array?
If the target value is less than the middle element, search the left half because the array is sorted.
Click to reveal answer
beginner
Why does binary search require the array to be sorted?
Because it decides which half to search based on comparisons, sorting ensures the target is only in one half, making the search efficient.
Click to reveal answer
intermediate
What is the time complexity of binary search and why?
O(log n) because each step cuts the search space in half, quickly reducing the number of elements to check.
Click to reveal answer
intermediate
Show the recursive step in binary search as divide and conquer.
Check middle element; if target equals middle, return index; else recursively search left or right half depending on comparison.
Click to reveal answer
What does binary search do at each step?
ASplits the array into two halves and searches one half
BChecks every element one by one
CSorts the array first
DSearches both halves simultaneously
Which condition means you should search the right half in binary search?
ATarget is less than middle element
BTarget is equal to middle element
CTarget is greater than middle element
DArray is unsorted
What is the base case for the recursive binary search?
AWhen the target is greater than all elements
BWhen the array is sorted
CWhen the array size is odd
DWhen the array is empty or target is found
Why is binary search faster than linear search on sorted arrays?
ABecause it checks elements randomly
BBecause it halves the search space each step
CBecause it sorts the array first
DBecause it uses more memory
What must be true about the array for binary search to work correctly?
AIt must be sorted
BIt must have unique elements
CIt must be unsorted
DIt must be empty
Explain how binary search uses divide and conquer to find a target in a sorted array.
Think about cutting the problem size in half each time.
You got /4 concepts.
    Describe the base case and recursive step in a recursive binary search function.
    Focus on when the function stops and how it calls itself.
    You got /2 concepts.