Question 18
Back to Exercise
What is the worst-case time of PriorityQueue.offer with n elements already in the queue?
- A O(1)
- B O(log n) Correct
- C O(n)
- D O(n log n)
Correct Answer: Option B
The new element sifts up at most the height of a complete binary tree, about log₂ n levels.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!