0% found this document useful (0 votes)
25 views10 pages

Heap Sort

The document discusses heaps, which are complete binary trees that satisfy the heap property. There are two main types of heaps: max-heaps, where each node's key is greater than its children's keys, and min-heaps, where each node's key is less than its children's keys. The heap property dictates the key ordering in the tree. Heap operations include heapify to build the heap structure, and insertion and deletion which maintain the heap ordering through heapifying.

Uploaded by

Tisha Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views10 pages

Heap Sort

The document discusses heaps, which are complete binary trees that satisfy the heap property. There are two main types of heaps: max-heaps, where each node's key is greater than its children's keys, and min-heaps, where each node's key is less than its children's keys. The heap property dictates the key ordering in the tree. Heap operations include heapify to build the heap structure, and insertion and deletion which maintain the heap ordering through heapifying.

Uploaded by

Tisha Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Heap

A complete binary tree is a special binary tree in which every level, except possibly the last, is
filled. All the nodes are as far left as possible
Heap data structure is a complete binary tree that satisfies the heap property. It is also called
as a binary heap. Generally, Heaps can be of two types:

Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys
present at all of it’s children. The same property must be recursively true for all sub-trees in
that Binary Tree.
Min-Heap: In a Min-Heap the key present at the root node must be minimum among the keys
present at all of it’s children. The same property must be recursively true for all sub-trees in
that Binary Tree.

Heap Property is the property of a node in which (for max heap) key of each node is always
greater than its child node/s and the key of the root node is the largest among all other
nodes;(for min heap) key of each node is always smaller than the child node/s and the key of
the root node is the smallest among all other nodes.
Heap
• For Input → 35 33 42 10 14 19 27 44 26 31
• Min-Heap − Where the value of the root node is less than or equal to either of its children.

• Max-Heap − Where the value of the root node is greater than or equal to either of its
children.

• Max Heap Example Min Heap Example

52
7,10,15,45,50, 55,70
• Node : kth position array
• Left child: 2*k (if it starts from 0 : 2*k+1)
• Right child: 2*k+1 (: 2*k+2)

55 50 45 15 10 7
• Heap Operations
• Some of the important operations performed
on a heap are described below along with their
algorithms.

• Heapify
• Heapify is the process of creating a heap data
structure from a binary tree. It is used to create
a Min-Heap or a Max-Heap.
• Insert the new element at the end of the tree.

• Heapify the tree.


• Select the element to be deleted.
Swap it with the last element.
• Remove the last element.

You might also like