GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Binary search (lo = 0, hi = n - 1, mid = (lo + hi) / 2 with integer division) is run on a sorted array of the 100 elements 1..100 once for each key from 1 to 100. For how many keys does the search need the maximum number of loop iterations, and what is that maximum?
- A. 37 keys need 7 iterations
- B. 43 keys need 7
- C. 37 keys need 8
- D. 28 keys need 6
Correct answer: A. 37 keys need 7 iterations
A decision tree of 100 nodes has 7 levels; the last level holds 100 - (2^6 - 1) = 37 nodes.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- rot(a, n, k) does: reverse(a, 0, k-1); reverse(a, k, n-1); reverse(a, 0, n-1), where reverse(a, i, j) reverses a[i..j] in place. The array…
- int x = 10; void f() { static int x = 1; x += 2; { int x = 100; x++; } printf("%d ", x); } int main() { f(); f(); { extern int x…
- unsigned char rev(unsigned char x) { unsigned char r = 0; for (int i = 0; i < 8; i++) { r = (r << 1) | (x & 1); x >>= 1; } return r; }…
- Assume 4-byte int and 8-byte pointers. char s[] = "ab0cd"; char p = "ab0cd"; int a[3][4]; printf("%zu %zu %zu %zu %zu", sizeof(s)…
- For a BST built from distinct keys (deletion of a node with two children uses its inorder successor), consider: I. Inserting a new key and…
- A directed graph has adjacency lists (visited in the order listed): A: B, C; B: D, E; C: E, F; D: G; E: D, H; F: H, B; G: none; H: G, A…