ProgrammingVery hard
The number of comparisons a merge of two sorted arrays of sizes 4 and 6 makes in the worst case is at most?
- A. 10
- B. 8
- C. 5
- D. 9
Correct answer: D. 9
Each comparison outputs one element, and the last element needs no comparison, so at most 4 + 6 - 1 = 9.
More C Programming questions
- struct P { int a[3]; }; struct P p = {{1, 2, 3}}; struct P q = &p; printf("%d", (q->a + 2)); What is printed?
- char words[] = {"ab", "cd", "ef"}; char pp = words + 1; printf("%s", pp + 1); What is printed?
- int a[] = {10, 20, 30}; int p = a; p++; printf("%d", p + p[1]); What is printed?
- int x = 1, y = 2; int p = &x, pp = &p; pp = &y; printf("%d %d", x, p); What is printed?
- int inc(int n) { return n + 1; } int dbl(int n) { return n 2; } int (f[2])(int) = {inc, dbl}; printf("%d", f[1](f[0](3))); What is printed?
- int x = 2; switch (x) { case 2: x += 1; case 3: x += 10; break; default: x = 0; } printf("%d", x); What is printed?