SlideShare a Scribd company logo
Data structure presentation
Leftist heap(min)
CSE 225
Leftist Heap
By
Shuvro Roy
EECS DEPARTMENT
NORTH SOUTH UNIVERSITY
A leftist tree or leftist heap is a priority queue implemented with a
variant of a binary heap.
The parent node is always less than or equals to the child node.
Hence , the minimum element is at the top.
 Every node in a Leftist Heap has a rank which is the
distance to the nearest leaf.
The Rank
The Leftist Heap Property: If the rank, (i.e.- the
distance between the nearest null leaf node and the
node) of the right sub tree is greater than the
rank of the left sub tree, the right sub tree is made
the left sub tree i.e.-they are swapped.
In contrast to a binary heap, a leftist tree attempts to be very
unbalanced.
Due to the Leftist Heap Property the Leftist heaps are
maintained so the right descendant of each node has lower
rank. Hence, the left sub tree is heavier than the right sub
tree.
Insertion
The rank of the right child <= the rank of the left child.
So we always go right.
If the element to be inserted is greater than the existing element in a
node, then we insert that element at the right node of the existing
node.
If the element to be inserted is less than the existing element in a
node, then we make the existing node the right node of that
element.
Insertion
After each insertion the ranks of all the parent nodes are updated
back to the root.
While updating the rank of a parent, we first compare the rank of the
left child and the rank of right child.
If the rank of the left child is less than that of the right, then we swap
the left child and the right child and update the rank of the parent.
Leftist heap
O(log n)
Merge
While merging two trees, we first have to compare the two roots of
the two trees.
The node with the smaller element becomes the new root.
The root of the other tree replaces the right node of the root.
Then the replaced node is compared with the sub nodes for further
placement.
The ranks for each of the nodes are updated and the sub trees are
swapped if needed.
4
25
12
15
819
2027
43
6
78
14
Consider two leftist heaps …Consider two leftist heaps …
Task: merge them into a single leftist heapTask: merge them into a single leftist heap
Merging leftist heaps
4
25
12
15
819
2027
43
6
78
14
First, instantiate a StackFirst, instantiate a Stack
Merging leftist heaps
4
25
12
15
819
2027
43
6
78
14
First, instantiate a StackFirst, instantiate a Stack
44
Merging leftist heaps
x yy
4
25
12
15
819
2027
43
6
78
14
Remember smaller valueRemember smaller value
66
44
xx
yy
Merging leftist heaps
4
25
12
15
819
2027
43
6
78
14
Repeat the process with the right child ofRepeat the process with the right child of
the smaller valuethe smaller value
66
44
x yy
Merging leftist heaps
4
25
12
15
819
2027
43
6
78
14
Remember smaller valueRemember smaller value
77
66
44
xx yy
Merging leftist heaps
4
25
12
15
819
2027
43
6
78
14
Repeat the process with the right child ofRepeat the process with the right child of
the smaller valuethe smaller value
77
66
44
xx
yy
nullnull
Merging leftist heaps
4
25
12
15
819
2027
43
6
78
14
Because one of the arguments is null,Because one of the arguments is null,
return the other argumentreturn the other argument
77
66
44
xx
88
Merging leftist heaps
4
25
12
15
19
2027
43
6
8
14
Make 8 the right child of 7Make 8 the right child of 7
77
66
44
x
88
8
7Refers to nodeRefers to node
88
Merging leftist heaps
4
25
12
15
19
2027
43
6
8
14
Make 7 leftist (by swapping children)Make 7 leftist (by swapping children)
77
66
44
88
8
7Refers to nodeRefers to node
88
Merging leftist heaps
4
25
12
15
19
2027
43
6
8
14
Return node 7Return node 7
66
44
77
8
7Refers to nodeRefers to node
88
Merging leftist heaps
4
25
12
15
19
2027
43
6
8
14
Make 7 the right child of 6 (whichMake 7 the right child of 6 (which
it already is)it already is)
66
44
77
8
7Refers to nodeRefers to node
88
Merging leftist heaps
4
25
12
15
19
2027
43
6
8
14
Make 6 leftist (it already is)Make 6 leftist (it already is)
66
44
77
8
7Refers to nodeRefers to node
88
Merging leftist heaps
4
25
12
15
19
2027
43
6
8
14
Return node 6Return node 6
44
6
8
7Refers to nodeRefers to node
88
Merging leftist heaps
4
25
12
15
19
2027
43
6
8
14
Make 6 the right child of 4Make 6 the right child of 4
44
66
8
7
Merging leftist heaps
4
25
12
15
19
2027
43
6
8
14
Make 4 leftist (it already is)Make 4 leftist (it already is)
44
66
8
7
Merging leftist heaps
4
25
12
15
19
2027
43
6
8
14
Return node 4Return node 4
44
8
7
O(log n)O(log n)
Final leftist heap
Deletion
To delete the minimum item we disconnect the root form its left and
right sub tree.
The left and right sub trees now has its own roots.
The roots of the two trees are compared and merged into one tree.
Deletion
Deletion
Right sub treeLeft sub tree
Deletion
Deletion
O(log n)
Time Complexity
Get min O(1)
Insert O(log n)
Delete O(log n)
Merge O(log n)
THANK YOU 

More Related Content

PPTX
Computer architecture input output organization
PPTX
Business intelligence
PPT
Product life cycle
PPTX
Control charts for attributes
PPT
Modes Of Transfer in Input/Output Organization
PDF
Python programming using problem solving approach by thareja, reema (z lib.org)
PDF
Unit 4-input-output organization
PDF
Data structure ppt
Computer architecture input output organization
Business intelligence
Product life cycle
Control charts for attributes
Modes Of Transfer in Input/Output Organization
Python programming using problem solving approach by thareja, reema (z lib.org)
Unit 4-input-output organization
Data structure ppt

What's hot (20)

PDF
Red black tree
PPTX
Loops in flow
PPT
Spanning trees
PPTX
Red black trees
PPTX
PPTX
Data structure - Graph
PPT
Data Structures- Part5 recursion
PPTX
Tree - Data Structure
PDF
Binary tree
PPTX
Threaded Binary Tree
PPT
Deadlock detection and recovery by saad symbian
PPTX
Unification and Lifting
PPTX
Relational algebra ppt
PPSX
Functional dependency
PPT
BINARY TREE REPRESENTATION.ppt
PPTX
AVL Tree in Data Structure
PPTX
B and B+ tree
PPTX
Knapsack Problem
Red black tree
Loops in flow
Spanning trees
Red black trees
Data structure - Graph
Data Structures- Part5 recursion
Tree - Data Structure
Binary tree
Threaded Binary Tree
Deadlock detection and recovery by saad symbian
Unification and Lifting
Relational algebra ppt
Functional dependency
BINARY TREE REPRESENTATION.ppt
AVL Tree in Data Structure
B and B+ tree
Knapsack Problem
Ad

Viewers also liked (8)

PPTX
Binomial heap presentation
PDF
Fibonacci Heap
PPTX
Binomial heap (a concept of Data Structure)
PPTX
Binomial Heaps and Fibonacci Heaps
PPT
chapter - 6.ppt
PPT
Heap sort
PPT
Lec 17 heap data structure
PPTX
Binomial Heap
Binomial heap presentation
Fibonacci Heap
Binomial heap (a concept of Data Structure)
Binomial Heaps and Fibonacci Heaps
chapter - 6.ppt
Heap sort
Lec 17 heap data structure
Binomial Heap
Ad

Similar to Leftist heap (20)

PPTX
16-avl- balanced-123456789078-trees.pptx
PPT
16-avl-trees for computer science and.ppt
PDF
Sienna6bst 120411102353-phpapp02
PPTX
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
PPTX
Trees in data structure
PDF
Leftlist Heap-1.pdf
PDF
AVL tree ( Balanced Binary Search Tree)-Data Structure
PPTX
Balanced Tree(AVL Tree,Red Black Tree)
PPTX
GEC_Soumik[1].pptx.interview of a person from JU.
PPTX
AVL Tree.pptx
PPT
16-avl-trees.ppt data structures prestentation
PPTX
Balanced Tree (AVL Tree & Red-Black Tree)
PPT
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
PPTX
Splay trees by NIKHIL ARORA (www.internetnotes.in)
PPTX
datastructurestreeand type of trees.pptx
PPT
PPTX
Data structures trees and graphs - AVL tree.pptx
PPT
Ch13 Binary Search Tree
PPT
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
PPTX
16-avl- balanced-123456789078-trees.pptx
16-avl-trees for computer science and.ppt
Sienna6bst 120411102353-phpapp02
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
Trees in data structure
Leftlist Heap-1.pdf
AVL tree ( Balanced Binary Search Tree)-Data Structure
Balanced Tree(AVL Tree,Red Black Tree)
GEC_Soumik[1].pptx.interview of a person from JU.
AVL Tree.pptx
16-avl-trees.ppt data structures prestentation
Balanced Tree (AVL Tree & Red-Black Tree)
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
Splay trees by NIKHIL ARORA (www.internetnotes.in)
datastructurestreeand type of trees.pptx
Data structures trees and graphs - AVL tree.pptx
Ch13 Binary Search Tree
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11

Recently uploaded (20)

PPTX
Current and future trends in Computer Vision.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPT
Total quality management ppt for engineering students
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
PPT on Performance Review to get promotions
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
UNIT - 3 Total quality Management .pptx
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Soil Improvement Techniques Note - Rabbi
PPTX
introduction to high performance computing
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Current and future trends in Computer Vision.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Information Storage and Retrieval Techniques Unit III
R24 SURVEYING LAB MANUAL for civil enggi
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Total quality management ppt for engineering students
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PPT on Performance Review to get promotions
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
UNIT - 3 Total quality Management .pptx
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Automation-in-Manufacturing-Chapter-Introduction.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Soil Improvement Techniques Note - Rabbi
introduction to high performance computing
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...

Leftist heap