ProgrammingHardGATE CS · Campus placements
Merge sort merges two halves with n element comparisons, so T(n) = 2T(n/2) + n and T(1) = 0. What is T(8)?
- A. 8
- B. 12
- C. 24
- D. 16
Correct answer: C. 24
T(2) = 2, T(4) = 2*2 + 4 = 8, and T(8) = 2*8 + 8 = 24. There are three levels of n comparisons each.
More C Programming questions
- unsigned int x = 1u; x = ~x; What is x?
- unsigned int u = 5u; int s = -5; printf("%s", (u + s == 0) ? "yes" : "no"); What is printed?
- uint32t mask = 0; for (int i = 0; i <= 30; i += 3) mask |= 1u << i; How many set bits does mask have?
- unsigned int v = (unsigned int)(-2); printf("%X", v); What is printed?
- int a[3] = {1, 2, 3}; int p = a; int (q)[3] = &a; printf("%d", (q + 2) + (p + 1)); What is printed?
- unsigned char x = 0; x--; What is x?