• Tutorials
  • Courses
  • Tracks

Q8.

Last Updated :
Discuss
Comments

You need to find the k smallest elements in an unsorted array of size n. Which approach is optimal using a heap?

Build a min-heap of all elements and extract k times

Build a max-heap of size k

Use a min-priority queue to keep track of k smallest

Build a max-heap of all elements

Share your thoughts in the comments