ProgrammingHard
A singly linked list of 2 x 10^5 nodes receives 2 x 10^5 insertions at the front and 2 x 10^5 deletions from the front. What is the total cost if each is O(1)?
- A. About 4 x 10^10 steps
- B. About 2 x 10^5 steps
- C. About 4 x 10^5 pointer updates
- D. About 8 x 10^5 steps
Correct answer: C. About 4 x 10^5 pointer updates
O(1) operations on a list of this size cost a constant number of pointer updates each, about 4 x 10^5 in total.
More C Programming questions
- A doubly linked list deletes its head by setting new head = head->next and then new head->prev = NULL. What happens if the list had only…
- printf("%d", (5 & 3) << 2 | 1); What is printed?
- int x = 16; printf("%d", x >> 2 ^ 3); What is printed?
- unsigned v = 12; printf("%u", v & -v); What is printed?
- printf("%u", (0u - 1u) % 10); What is printed with 32-bit unsigned int?
- printf("%d", 10 % 3 2 ^ 1); What is printed?