Download presentation
Presentation is loading. Please wait.
1
Partially Ordered Data ,Heap,Binary Heap
Sreeresmi T S AP CSE Dept.
2
Introduction Priority Queue:
Priority queue is a data structure where element together with their priority is inserted into the queue. Operations: Insertion : Element with priority is inserted. Deletion: Element with topmost priority is found and gets deleted
3
Partially Ordered Tree.
A better implementation of Priority Queue is Partially Ordered Tree. Partially ordered tree is the one in which contents of a child of a node are always smaller than the contents of this node A binary tree with elements and their priorities at nodes satisfying the following property: priority at any node>= the priority at either of its children
5
Heap A heap is a partially ordered complete binary tree.
To say that a heap is partially ordered is to say that there is some relationship between the value of a node and the values of its children. In a min-heap , the value of a node is less than or equal to the values of its children. In a max-heap , the value of a node is greater than or equal to the values of its children. Consequently, the smallest (largest) value in a min-heap(max-heap) is at the heap's root
6
Heap Min Heap Max Heap
7
Array Implementation A complete binary tree can be uniquely represented by storing its level order traversal in an array. The root is the second item in the array. We skip the index zero cell of the array for the convenience of implementation. Consider k-th element of the array, the n its left child is located at 2*k index its right child is located at 2*k+1. index its parent is located at k/2 index
8
Building the heap tree 1 2 3
9
Building the heap tree 4 5
10
Binary Heaps Heaps could be binary or d-ary.
Binary heaps are special forms of binary trees while d-ary heaps are a special class of general trees. Binary heaps were first introduced by Williams in 1964. DEF. A binary heap is a complete binary tree with elements from a partially ordered set, such that the element at every node is less than (or equal to) the element at its left child and the element at its right child.
11
Binary Heaps
12
Binary Heaps A binary heap is a binary tree (NOT a BST) that is: Complete : the tree is completely filled except possibly the bottom level, which is filled from left to right Satisfies the heap order property every node is less than or equal to its children or every node is greater than or equal to its children • The root node is always the smallest node or the largest, depending on the heap order
14
Operations on Binary Heap
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.