LearnFrenzy
Sign in Take a free test

Data Structures in Java · Data Structures in Java MCQ · Question 18

Cost of offer on a binary heap Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links