LOGBOOK

HELP

Quiz Entry - updated: 2026.12.01

Tracing an adaptable priority queue: after e1 = insert(5,A), e2 = insert(3,B), e3 = insert(7,C), what do min(), key(e2), remove(e1), replaceKey(e2, 9), replaceValue(e3, D) and remove(e2) return, and what is left at the end?

min() → e2; key(e2) → 3; remove(e1) → e1; replaceKey(e2, 9) → 3 (the old key); replaceValue(e3, D) → C (the old value); remove(e2) → e2. What is left is the single entry (7, D).

Operation Returns Contents (sorted by key)
insert(5,A) e1 (5,A)
insert(3,B) e2 (3,B), (5,A)
insert(7,C) e3 (3,B), (5,A), (7,C)
min() e2 unchanged
key(e2) 3 unchanged
remove(e1) e1 (3,B), (7,C)
replaceKey(e2,9) 3 (7,C), (9,B)
replaceValue(e3,D) C (7,D), (9,B)
remove(e2) e2 (7,D)

The interesting step is replaceKey(e2, 9). Entry e2 was the minimum with key 3; with key 9 it must move behind (7,C), so the queue reorders itself, and the minimum is now e3. replaceValue never reorders, because the value has no influence on position. And remove(e1) took out an entry that was not the minimum, something a plain priority queue cannot do.

From Quiz: ADS / Priority Queues and Heaps | Updated: Dec 01, 2026