What is a Heap ?


A heap is a tree with some special properties. The basic requirement of a heap is that the value of  a node must be greater than equal to  (or  less than equal to) to the values of its children. That is called heap property. Additional property of heap – all leaves should be at h or h-1 (where h is the height of the tree) levels for some h>0 (complete binary tree). That means heap should form a complete binary tree.

Types of Heap :-
   →  Min Heap : The value of a node must be less than or equal to the values                             of its children.
   →  Max Heap : The value of a node must be greater than or equal to the                                  values of its children.

Declaration of Heap :-

public class Heap
{
      int[] array;
      int capacity;
      int count;
      int Heap(int capacity);

}

Creating Heap :-

public Heap(int capacity)
{
      this.count = 0;
      this.capacity = capacity;
      this.array = new int[capacity];
}

Comments

Popular posts from this blog

How to Build REST API Using PHP

AVL Tree Rotations

Disjoint Set (Union-Find)