ProgrammingVery hard
Merging two sorted singly linked lists of length 3 each with the standard merge, what is the largest number of key comparisons needed?
- A. 5
- B. 6
- C. 3
- D. 4
Correct answer: A. 5
Each comparison outputs one node, and the last node of the first list ends the merge without a comparison. So at most 3 + 3 - 1 = 5 comparisons.
More C Programming questions
- With a 4-byte int and an 8-byte pointer, natural alignment, what is sizeof(struct N) for struct N { int v; struct N next; };?
- A linked list is built by appending n nodes one by one, each time walking from the head to the last node. About how many node visits does…
- A stack is implemented with a singly linked list, pushing at the head. The operations are push 1, push 2, pop, push 3, push 4, pop, pop…
- A queue is kept as a singly linked list with head and tail pointers. Enqueue 1, 2, 3, dequeue twice, enqueue 4, then dequeue once. Which…
- Which loop correctly frees every node of a singly linked list whose head is p?
- A recursive function prints a list after its recursive call returns, as in print(n) { if (!n) return; print(n->next); putchar(n->v + '0')…