GATE Computer ScienceHardGATE CSE · NIELIT
A binary search (loop while low ≤ high, mid = ⌊(low+high)/2⌋) runs on a sorted array of 1000 elements. The maximum number of loop iterations over all searches, successful or not, is
- A. 9
- B. 11
- C. 10
- D. 12
Correct answer: C. 10
The range roughly halves each time until empty: ⌊log2 1000⌋ + 1 = 10.
More Algorithms questions
- Keys 1..7 are inserted into an initially empty BST (no balancing) in some order. For how many of the 7! insertion orders does the…
- Keys 1..8 are inserted into an empty BST in each of the 8! possible orders. In how many orders is the resulting tree a single path (height…
- For X = "ABCBDAB" and Y = "BDCABA", how many DISTINCT strings are longest common subsequences of X and Y?
- An undirected weighted graph on vertices 0..6 has edges, written (u, v, weight): (0,1,2), (0,2,2), (1,2,2), (1,3,3), (2,3,3), (3,4,1)…
- A directed graph has edges S→A (4), S→B (2), B→A (−3), A→C (2), B→D (3), D→C (−5). Dijkstra's algorithm is run from S: each extracted…
- Lomuto partition (pivot = last element, i starts at −1, for each j with A[j] ≤ pivot do i++ and swap A[i], A[j]; finally swap A[i+1] with…