Grokking 75: Top Coding Interview Questions
Vote

0% completed

​

Introduction to Heap

Heaps are a specialized data structure and are based on binary trees. They are of the following two types:

  • In a max heap, every parent node has a value bigger than or equal to its children.
  • In a min heap, every parent node has a value smaller than or equal to its children.

This ordering property allows heaps to efficiently support operations like finding the maximum or minimum element.

Some key characteristics of heaps:

  • Heaps are commonly implemented as binary heaps, which are binary trees represented using arrays.

.....

.....

.....

Like the course? Get enrolled and start learning!
A

Anonymous

· 3 years ago

n a binary min heap, every node must be smaller than or equal to its children. The iterative approach only checks and maintains this property for the inserted node and its parent, but it doesn't check the sibling of the inserted node. This could lead to a situation where a node is smaller than one child but larger than the other.

So, while the iterative approach is a valid start, it's not a complete implementation of a binary min heap. The recurrsion approach is a complete and correct implementation.

Reading Progress

0%


Vote for new content