SlideShare a Scribd company logo
1 of 19
Download to read offline
Threaded Binary Tree
Definition
A binary search tree in which each node
  uses an otherwise-empty left child link to
  refer to the node's in-order predecessor
  and an empty right child link to refer to its
  in-order successor.
Threaded Binary Trees
• Two many null pointers in current
  representation
  of binary trees
     n: number of nodes
     number of non-null links: n-1
     total links: 2n
     null links: 2n-(n-1)=n+1
• Replace these null pointers with some useful
  “threads”.
Threaded Binary Trees (Continued)

If ptr->left_child is null,
   replace it with a pointer to the node that would be
   visited before ptr in an inorder traversal

If ptr->right_child is null,
   replace it with a pointer to the node that would be
   visited after ptr in an inorder traversal
A Threaded Binary Tree
                root            A
                                                      dangling
                      B                           C


dangling    D             E               F             G

                          inorder traversal:
      H           I       H, D, I, B, E, A, F, C, G
Data Structures for Threaded BT
left_thread   left_child   data   right_child right_thread

  TRUE                                          FALSE



    TRUE: thread                      FALSE: child
typedef struct threaded_tree
  *threaded_pointer;
typedef struct threaded_tree {
    short int left_thread;
    threaded_pointer left_child;
    char data;
    threaded_pointer right_child;
    short int right_thread; };
• Dangling can be solved as follows
  – Introduce a header node.
  – The left and right pointer of the header node
    are treated as normal links and are initialized
    to point to header node itself
Memory Representation of A Threaded BT




                            root                             --
                                                 f                    f


                                                 f           A        f


                f           B        f                                        f       C       f


    f       D           f        t           E           t        t       F       t       t       G


t       H           t        t           I           t
• Right-threaded tree:
• A variant of a threaded tree in which only
  the right thread, i.e. link to the successor,
  of each node is maintained.
Advantages of Threaded Tree
• It reduces the time complexity of algorithm.
• Operation like traversal, insertion, deletion can
  be done without using recursive algorithm.
• It becomes very easy to find out inorder
  successor of any node ‘n’ in a threaded binary
  tree. If the right thread of n is true or 1 then the
  node pointed by its right pointer is the desired
  information successor. If the right thread of ‘n’ is
  false or 0 then the inorder successor must be
  on the right subtree of ‘n’.
Application of Tree
• Expression Tree
• Game Tree
Infix, prefix, and postfix notation
• representation of math expressions as a binary tree
   – operators have their left and right operands as
     subtrees
   – literal values are stored as leaves

• notations
   – prefix: Polish notation
   – infix:   standard notation
   – postfix: reverse Polish notation
Expression example
Expression tree example
Game Tree
• Tree generated for games such as tic-tac-
  toe
• Consider all the possible position for the
  given position. And find the best solution
  to win.
Heap Sort
• It is based on tree structure.
• Heap sort is in two phase
  – The entries are arranged in the list satisfying
    the requirement of a heap
  – We repeatedly remove the top of the heap
    and promote another entry to take its place.
Construction of heap
• First construct a complete binary tree
• There are two types of heap- min heap or
  ascending heap or max heap or
  descending heap
• Consider the elements present at a level
  one less than the maximum level. They
  are converted to heap in the same way as
  replacing the node of a heap.
• In next step the elements that are present
  at a level two less than the maximum level
  of the tree are considered
• Likewise in each step one level is
  decremented and all the subtrees at that
  level are converted to heaps
• Eg 13, 4, 11, 15, 59, 27, 19, 3, 92, 5
Phase two
• Remove the root of tree and place it to last
  and re-create the heap in descending
  order and repeat the process.
• Solution on board.

More Related Content

What's hot

linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy TutorialAfzal Badshah
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeManishPrajapati78
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applicationsJsaddam Hussain
 
B+tree Data structures presentation
B+tree Data structures presentationB+tree Data structures presentation
B+tree Data structures presentationMuhammad Bilal Khan
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure Ankit Kumar Singh
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked listFahd Allebdi
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data StructureMeghaj Mallick
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data StructureAnuj Modi
 

What's hot (20)

linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
 
Binary tree
Binary tree Binary tree
Binary tree
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
stack & queue
stack & queuestack & queue
stack & queue
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
B+tree Data structures presentation
B+tree Data structures presentationB+tree Data structures presentation
B+tree Data structures presentation
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Red black tree
Red black treeRed black tree
Red black tree
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 

Viewers also liked (11)

Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
 
THREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREETHREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREE
 
Full threded binary tree
Full threded binary treeFull threded binary tree
Full threded binary tree
 
Rfid
RfidRfid
Rfid
 
Heap tree
Heap treeHeap tree
Heap tree
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 

Similar to Threaded binarytree&heapsort (20)

Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
Tree
TreeTree
Tree
 
DSA-Unit-2.pptx
DSA-Unit-2.pptxDSA-Unit-2.pptx
DSA-Unit-2.pptx
 
Binary tree
Binary treeBinary tree
Binary tree
 
6_1 (1).ppt
6_1 (1).ppt6_1 (1).ppt
6_1 (1).ppt
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
 
Trees
TreesTrees
Trees
 
Lec216
Lec216Lec216
Lec216
 
Lec21
Lec21Lec21
Lec21
 
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
 
Chapter 5_Trees.pdf
Chapter 5_Trees.pdfChapter 5_Trees.pdf
Chapter 5_Trees.pdf
 
Unit8 C
Unit8 CUnit8 C
Unit8 C
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 
Lect 22 Zaheer Abbas
Lect 22 Zaheer AbbasLect 22 Zaheer Abbas
Lect 22 Zaheer Abbas
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
Binary tree
Binary treeBinary tree
Binary tree
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Trees.pptx
Trees.pptxTrees.pptx
Trees.pptx
 

More from Ssankett Negi (9)

Multi way&btree
Multi way&btreeMulti way&btree
Multi way&btree
 
Heapsort
HeapsortHeapsort
Heapsort
 
Binary trees
Binary treesBinary trees
Binary trees
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
Stack prgs
Stack prgsStack prgs
Stack prgs
 
Recursion
RecursionRecursion
Recursion
 
Qprgs
QprgsQprgs
Qprgs
 
Circular queues
Circular queuesCircular queues
Circular queues
 
U2.linked list
U2.linked listU2.linked list
U2.linked list
 

Recently uploaded

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

Threaded binarytree&heapsort

  • 2. Definition A binary search tree in which each node uses an otherwise-empty left child link to refer to the node's in-order predecessor and an empty right child link to refer to its in-order successor.
  • 3. Threaded Binary Trees • Two many null pointers in current representation of binary trees n: number of nodes number of non-null links: n-1 total links: 2n null links: 2n-(n-1)=n+1 • Replace these null pointers with some useful “threads”.
  • 4. Threaded Binary Trees (Continued) If ptr->left_child is null, replace it with a pointer to the node that would be visited before ptr in an inorder traversal If ptr->right_child is null, replace it with a pointer to the node that would be visited after ptr in an inorder traversal
  • 5. A Threaded Binary Tree root A dangling B C dangling D E F G inorder traversal: H I H, D, I, B, E, A, F, C, G
  • 6. Data Structures for Threaded BT left_thread left_child data right_child right_thread TRUE FALSE TRUE: thread FALSE: child typedef struct threaded_tree *threaded_pointer; typedef struct threaded_tree { short int left_thread; threaded_pointer left_child; char data; threaded_pointer right_child; short int right_thread; };
  • 7. • Dangling can be solved as follows – Introduce a header node. – The left and right pointer of the header node are treated as normal links and are initialized to point to header node itself
  • 8. Memory Representation of A Threaded BT root -- f f f A f f B f f C f f D f t E t t F t t G t H t t I t
  • 9. • Right-threaded tree: • A variant of a threaded tree in which only the right thread, i.e. link to the successor, of each node is maintained.
  • 10. Advantages of Threaded Tree • It reduces the time complexity of algorithm. • Operation like traversal, insertion, deletion can be done without using recursive algorithm. • It becomes very easy to find out inorder successor of any node ‘n’ in a threaded binary tree. If the right thread of n is true or 1 then the node pointed by its right pointer is the desired information successor. If the right thread of ‘n’ is false or 0 then the inorder successor must be on the right subtree of ‘n’.
  • 11. Application of Tree • Expression Tree • Game Tree
  • 12. Infix, prefix, and postfix notation • representation of math expressions as a binary tree – operators have their left and right operands as subtrees – literal values are stored as leaves • notations – prefix: Polish notation – infix: standard notation – postfix: reverse Polish notation
  • 15. Game Tree • Tree generated for games such as tic-tac- toe • Consider all the possible position for the given position. And find the best solution to win.
  • 16. Heap Sort • It is based on tree structure. • Heap sort is in two phase – The entries are arranged in the list satisfying the requirement of a heap – We repeatedly remove the top of the heap and promote another entry to take its place.
  • 17. Construction of heap • First construct a complete binary tree • There are two types of heap- min heap or ascending heap or max heap or descending heap
  • 18. • Consider the elements present at a level one less than the maximum level. They are converted to heap in the same way as replacing the node of a heap. • In next step the elements that are present at a level two less than the maximum level of the tree are considered • Likewise in each step one level is decremented and all the subtrees at that level are converted to heaps • Eg 13, 4, 11, 15, 59, 27, 19, 3, 92, 5
  • 19. Phase two • Remove the root of tree and place it to last and re-create the heap in descending order and repeat the process. • Solution on board.