![]() |
A leftist heap is a priority Queue implemented with a binary heap. Every node has a sValue which is at the nearest Distance to the other nodes. Now we will write a java program for performing certain operations on a leftist Heap (Inorder Traversal) like insert, delete, clear, and check for empty. A leftist tree is a binary tree with properties:
Example: The below leftist tree is presented with its distance calculated for each node with the procedure mentioned above. The rightmost node has a rank of 0 as the right subtree of this node is null and its parent has a distance of 1 by dist( i ) = 1 + dist( right( i )). The same is followed for each node and their s-value( or rank) is calculated. From the above second property, we can draw two conclusions :
Example: LEFTIST HEAP Functions to do 2. delete min 3. check empty 4. clear 2 Inorder Traversal: 53 52 54 If you wish to continue type Y or y y Functions to do 2. delete min 3. check empty 4. clear 3 Empty status = false Inorder Traversal: 53 52 54 If you wish to continue type Y or y y Functions to do 2. delete min 3. check empty 4. clear 4 Inorder Traversal: If you wish to continue type Y or y Approach:
Implementation: Java
Output:
|
Reffered: https://www.geeksforgeeks.org
Java Programs |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |