LearnFrenzy
Sign in Take a free test

Data Structures in Java · Data Structures in Java MCQ · Question 20

Cost of building a heap from n elements Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 20 Back to Exercise

new PriorityQueue<>(collection) builds the heap with bottom-up heapify. What is its time complexity?

  • A O(n) Correct
  • B O(n log n)
  • C O(log n)
  • D O(n²)
Correct Answer: Option A

Most nodes are near the bottom and sift down only a level or two; the total work sums to O(n), better than n separate offers.

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