Alorithms · Class 12 · CBSE · Science Computer Science
Explain why binary search cannot generally be applied directly to an unsorted array. Also state the worst-case time complexity of linear search and b…
Practice question from Alorithms (Class 12 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.
hard · Subjective · Q-1AA8E4
Explain why binary search cannot generally be applied directly to an unsorted array. Also state the worst-case time complexity of linear search and binary search for an array of n elements.
Solution
Binary search can eliminate half the remaining elements at each step only when the array is sorted. Linear search may inspect every element, giving O(n) time, whereas binary search repeatedly halves the search space, giving O(log n) time.
More from Alorithms
- Which condition is necessary before applying binary search to an array?
- What is the array after the first complete pass of selection sort in ascending order on [29, 10, 14, 37, 13]?
- Which statement correctly describes the worst-case time complexity of insertion sort and the situation in which it performs efficiently?
- Explain why merge sort is generally preferred over selection sort for sorting a large collection of data. State the time complexity of both…
Practise more Computer Science
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed