Heaps Flashcards
Learn
How do you create a min-heap from a list?
Use a built-in heapify function to arrange the list into heap order.
What’s the heap property in a min-heap?
Every parent node is less than or equal to its children.
What does popping from a min-heap do?
Removes and returns the smallest element at the root.
What is the time complexity for insert and delete in a heap?
O(log n) for both operations.
How do you simulate a max-heap using a min-heap?
Insert negative values and interpret them accordingly.
What does pushing to a heap do?
Adds an item and maintains heap order.
Why is heapify O(n) instead of O(n log n)?
It builds the heap efficiently by working from the bottom up.
How does the heap array change with operations?
Insertions bubble up; deletions bubble down.
What’s a real-world use case for heaps?
Priority queues, like task scheduling or event handling.