WikiGalaxy

Personalize

Types of Heap

Binary Heap

Definition:

A binary heap is a complete binary tree that satisfies the heap property. It can be of two types: Max-Heap and Min-Heap.

Max-Heap:

In a Max-Heap, for any given node I, the value of I is greater than or equal to the values of its children.

Min-Heap:

In a Min-Heap, for any given node I, the value of I is less than or equal to the values of its children.


class MaxHeap {
    private int[] Heap;
    private int size;
    private int maxsize;

    public MaxHeap(int maxsize) {
        this.maxsize = maxsize;
        this.size = 0;
        Heap = new int[this.maxsize + 1];
        Heap[0] = Integer.MAX_VALUE;
    }
    
    // Add more methods for heap operations
}
    

Console Output:

MaxHeap initialized.

Fibonacci Heap

Definition:

A Fibonacci heap is a collection of trees satisfying the minimum heap property. It has a better amortized time complexity for decrease key and delete operations compared to binary heaps.

Use Case:

Fibonacci heaps are used in graph algorithms like Dijkstra's shortest path and Prim's minimum spanning tree.


class FibonacciHeap {
    private Node minNode;
    private int size;

    public FibonacciHeap() {
        minNode = null;
        size = 0;
    }
    
    // Add more methods for heap operations
}
    

Console Output:

FibonacciHeap initialized.

Binomial Heap

Definition:

A binomial heap is a collection of binomial trees that are linked together. It supports efficient merging of two heaps.

Structure:

Each binomial tree in a binomial heap follows the min-heap property, where the key of a node is greater than or equal to the key of its parent.


class BinomialHeap {
    private Node head;

    public BinomialHeap() {
        head = null;
    }
    
    // Add more methods for heap operations
}
    

Console Output:

BinomialHeap initialized.

Leftist Heap

Definition:

A leftist heap is a variant of binary heap where the priority is on the left subtree having the shortest path to a leaf. It ensures efficient merging of heaps.

Property:

The rank of a node is the length of the shortest path from the node to a leaf, and for each node, the rank of the left child is at least as large as the rank of the right child.


class LeftistHeap {
    private Node root;

    public LeftistHeap() {
        root = null;
    }
    
    // Add more methods for heap operations
}
    

Console Output:

LeftistHeap initialized.

Skew Heap

Definition:

A skew heap is a self-adjusting binary heap, which means it does not require explicit balancing operations. It supports fast merge operations.

Mechanism:

The merging of two skew heaps involves recursively merging the right subtrees and swapping the left and right children.


class SkewHeap {
    private Node root;

    public SkewHeap() {
        root = null;
    }
    
    // Add more methods for heap operations
}
    

Console Output:

SkewHeap initialized.

Pairing Heap

Definition:

A pairing heap is a type of heap data structure with relatively simple implementation and excellent practical amortized performance.

Operations:

Pairing heaps perform well with operations like insertion, find-minimum, and decrease-key, making them suitable for various applications.


class PairingHeap {
    private Node root;

    public PairingHeap() {
        root = null;
    }
    
    // Add more methods for heap operations
}
    

Console Output:

PairingHeap initialized.

D-ary Heap

Definition:

A D-ary heap is a generalization of the binary heap where each node has D children. It is particularly useful for algorithms that require a priority queue.

Use Case:

D-ary heaps are often used in network optimization algorithms and other applications where the decrease-key operation is frequently used.


class DaryHeap {
    private int[] Heap;
    private int size;
    private int d; // Number of children per node

    public DaryHeap(int capacity, int d) {
        this.d = d;
        this.size = 0;
        Heap = new int[capacity + 1];
    }
    
    // Add more methods for heap operations
}
    

Console Output:

DaryHeap initialized.

Ternary Heap

Definition:

A ternary heap is a special case of a D-ary heap with D=3, meaning each node has three children. It provides a good balance between the binary and higher-order heaps.

Efficiency:

Ternary heaps are efficient for both the insert and delete operations, making them suitable for priority queue implementations.


class TernaryHeap {
    private int[] Heap;
    private int size;

    public TernaryHeap(int capacity) {
        this.size = 0;
        Heap = new int[capacity + 1];
    }
    
    // Add more methods for heap operations
}
    

Console Output:

TernaryHeap initialized.

Brodal Queue

Definition:

A Brodal queue is a type of heap that achieves optimal amortized time bounds for all heap operations. It is the only heap to achieve these bounds without using the Fibonacci heap's potential function.

Complexity:

Brodal queues provide constant time complexity for insertion and logarithmic time for delete-min operations.


class BrodalQueue {
    private Node root;

    public BrodalQueue() {
        root = null;
    }
    
    // Add more methods for heap operations
}
    

Console Output:

BrodalQueue initialized.

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025