0
0
DSA C++programming~5 mins

Why Binary Search and What Sorted Order Gives You in DSA C++ - Quick Recap

Choose your learning style9 modes available
Recall & Review
beginner
What is the main advantage of using binary search over linear search?
Binary search is much faster because it repeatedly divides the search space in half, reducing the number of comparisons from linear (n) to logarithmic (log n).
Click to reveal answer
beginner
Why must the data be sorted to use binary search?
Binary search relies on the data being sorted so it can decide which half of the data to ignore after each comparison, ensuring the search space shrinks correctly.
Click to reveal answer
beginner
What does 'sorted order' mean in the context of binary search?
Sorted order means the elements are arranged in increasing or decreasing order, so each element is in a predictable position relative to others.
Click to reveal answer
intermediate
How does sorted order help in reducing the search time?
Sorted order allows binary search to eliminate half of the remaining elements after each comparison, quickly narrowing down the possible location of the target.
Click to reveal answer
intermediate
What is the time complexity of binary search and why?
The time complexity is O(log n) because the search space is halved with each step, leading to a logarithmic number of steps relative to the number of elements.
Click to reveal answer
Why can binary search only be used on sorted data?
ABecause it needs to know which half to discard after each comparison
BBecause it compares every element one by one
CBecause it works only on numbers
DBecause it requires data to be in random order
What happens to the search space after each step in binary search?
AIt doubles
BIt stays the same
CIt halves
DIt becomes empty
What is the best case time complexity of binary search?
AO(log n)
BO(1)
CO(n)
DO(n log n)
Which of these is NOT a requirement for binary search?
AData must be sorted
BData must be in an array or list
CData must allow random access
DData must be unique
If you have 1,000,000 sorted elements, about how many steps does binary search take in the worst case?
A20
B1,000,000
C100
D10,000
Explain why sorted order is essential for binary search and how it helps reduce search time.
Think about how knowing order helps decide which part to ignore.
You got /3 concepts.
    Describe the step-by-step process of binary search on a sorted list.
    Imagine looking for a word in a dictionary.
    You got /4 concepts.