ProgrammingModerate
A linked list of length n is reversed in place with a loop. How much extra memory is used?
- A. O(n), a new node for each element
- B. O(n log n), for a sorting buffer
- C. O(n^2), for a copy of each suffix
- D. O(1), only a few pointer variables
Correct answer: D. O(1), only a few pointer variables
The three-pointer loop reuses the nodes, so only constant extra space is needed.
More C Programming questions
- unsigned int h = 0; for (const char p = "ab"; p; p++) h = h 31 + p; printf("%u", h); What is printed (ASCII, 32-bit unsigned)?
- unsigned int x = 0b11011010; printf("%u", (x >> 3) & 7); What is printed?
- With 32-bit unsigned arithmetic, what does (unsigned)-5 >> 1 print?
- What is the value of ~5 & 0xF in C, with int of 32 bits?
- What is the value of (3 ^ 5) & ~1 in C?
- What is printed by printf("%d", 7 13 % 5 3 % 4);?