• Save
10 ds and algorithm session_14
Upcoming SlideShare
Loading in...5
×
 

10 ds and algorithm session_14

on

  • 574 views

 

Statistics

Views

Total Views
574
Views on SlideShare
477
Embed Views
97

Actions

Likes
0
Downloads
0
Comments
0

4 Embeds 97

http://niitcourseslides.blogspot.in 79
http://niitcourseslides.blogspot.com 13
http://webcache.googleusercontent.com 4
http://niitcourseslides.blogspot.ro 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Faculty should tell the students that maintaining a header node in a threaded binary tree is optional. However, in the absence of a header node, the algorithm to implement various operations in a threaded binary tree becomes complicated. This is because in that case, you are required to keep track of certain extra conditions. There is always a trade off between space and efficiency. The decision to use a header node depends upon the problem in hand. If the tree is huge that stores million of records, then the use of an extra header node is justifiable. However, if the tree stores less amount of data, then maintaining a header node can be an additional overhead.
  • Faculty should tell the students that maintaining a header node in a threaded binary tree is optional. However, in the absence of a header node, the algorithm to implement various operations in a threaded binary tree becomes complicated. This is because in that case, you are required to keep track of certain extra conditions. There is always a trade off between space and efficiency. The decision to use a header node depends upon the problem in hand. If the tree is huge that stores million of records, then the use of an extra header node is justifiable. However, if the tree stores less amount of data, then maintaining a header node can be an additional overhead.
  • In this slide you need to show the calculation to determine the sum of an arithmetic progression for bubble sort algorithm. Refer to student guide.
  • In this slide you need to show the calculation to determine the sum of an arithmetic progression for bubble sort algorithm. Refer to student guide.
  • In this slide you need to show the calculation to determine the sum of an arithmetic progression for bubble sort algorithm. Refer to student guide.
  • Before explaining the traversal of a threaded binary tree, faculty should discuss the disadvantage of traversing the binary search tree through recursion. Tell the students that a stack is implemented internally to traverse the tree recursively.
  • Before explaining the traversal of a threaded binary tree, faculty should discuss the disadvantage of traversing the binary search tree through recursion. Tell the students that a stack is implemented internally to traverse the tree recursively.

10 ds and algorithm session_14 10 ds and algorithm session_14 Presentation Transcript

  • Data Structures and AlgorithmsObjectives In this session, you will learn to: Apply trees to solve programming problems Implement a threaded binary tree Ver. 1.0 Session 14
  • Data Structures and AlgorithmsIndexing The on disk is an usually of an index. Datafollowingfiles isexampleorganized as records containing several fields, one of which is often used as a key field. The key field is used to uniquely identify each record in a Key field Offset file. 36 0 52 200 Indexing is one of the data access methods for accessing 24 400 records from the disk files. 44 600 Indexing is implemented through a table called index. 40 800 Index consists of two entries: 1000 68 59 1200 Key fields of all the records 55 1400 Offset position of each record 72 1600 35 1800 43 2000 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsIndexing (Contd.) To access the record with key field 59, search the index for You can implement a binary search tree to store these this key value to retrieve its corresponding offset value, index values. which is 1200. enables faster search for a key value. This approach Read the record from the file starting from this offset Key field Offset 52 36 position. 0 52 200 36 68 24 400 44 600 40 800 24 44 59 72 68 1000 59 1200 40 55 55 1400 72 1600 35 43 35 1800 43 2000 Index Key Fields Stored in a Binary Search Tree Ver. 1.0 Session 14
  • Data Structures and AlgorithmsImplementing a Threaded Binary Trees One of the common operations on a binary tree is traversal. In a linked representation of a binary tree, traversal is usually implemented through recursion. As a result, a stack is maintained in the memory. If the tree is huge, implementing recursion to traverse the tree would require a lot of memory space. In the absence of sufficient memory space, implementing recursion can lead to a memory leak. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsDefining Threaded Binary Trees In such a case, it would be good if you have some mechanism by which you can traverse the tree without implementing recursion. You can solve this problem by implementing a threaded binary tree. In a binary search tree, there are many nodes that have an empty left child or empty right child or both. You can utilize these fields in such a way so that the empty left child of a node points to its inorder predecessor and empty right child of the node points to its inorder successor. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsDefining Threaded Binary Trees (Contd.) Consider theitfollowing binary search tree. fields are In this case, would be good if these NULL utilized for some other useful purpose. Most of the nodes in this tree hold a NULL value in their left or right child fields. . 65 . . 40 . . 72 . 30 . 50 . 69 80 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsDefining Threaded Binary Trees (Contd.) Such a type of binary tree is node as be used to point tree. The empty left child field of aknowncan a threaded binaryto itsfield thatpredecessor. A inorder holds the address of its inorder successor or predecessor empty right thread. Similarly, the is known as child field of a node can be used to point to its inorder successor. . 65 . . 40 . . 72 . 30 50 . 69 80 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsDefining Threaded Binary Trees (Contd.) Node 30 does not have an inorder predecessor because it is the first node to be traversed in inorder sequence. Similarly, node 80 does not have an inorder successor. . 65 . . 40 . . 72 . 30 50 . 69 80 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsDefining Threaded Binary Trees (Contd.) Therefore, you of theaheader node always points to itself. The right child take dummy node called the header node. Header Node . 65 . . 40 . . 72 . 30 50 . 69 80 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsDefining Threaded Binary Trees (Contd.) The threaded binary tree is represented as the left child of the header node. Header Node . 65 . . 40 . . 72 . 30 50 . 69 80 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsDefining Threaded Binary Trees (Contd.) The left thread of node 30 and the right thread of node 80 point to the header node. Header Node . 65 . . 40 . . 72 . . 30 50 . 69 80 . 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsJust a minute In a threaded binary tree, the right thread of a node points to its inorder ___________, and the left thread points to its inorder ____________. Answer: successor, predecessor Ver. 1.0 Session 14
  • Data Structures and AlgorithmsRepresenting a Threaded Binary Tree The left and right threadin a threaded binary tree istwo structure of a node fields of a node can have a bit values: from that of a normal binary tree. different – 1: a normal normal link to the child node UnlikeIndicates a binary tree, each node of a threaded binary tree 0: Indicates a thread pointing of the inorder predecessor or – contains two extra pieces to information, namely left thread and successor inorder right thread. 4631 Information 2389 Left Address of Data Address of Right Thread Left Child Right Child Thread Ver. 1.0 Session 14
  • Data Structures and AlgorithmsRepresenting a Threaded Binary Tree (Contd.) Various operations in a threaded binary tree are as follows: Traversal Search Insert Delete Ver. 1.0 Session 14
  • Data Structures and AlgorithmsJust a minute How do you identify a root node in a threaded binary tree? Answer: In a threaded binary tree, the root node is identified as the left child of the header node. If the tree is empty, the left child of the header node becomes a thread pointing to itself. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsJust a minute How is the structure of a node of a threaded binary tree different from that of a normal binary tree? Answer: Each node in a threaded binary tree holds two extra pieces of information known as left thread and right thread. The value of these two fields indicates whether the left/right child field of a node contains a link to a child node or a thread to its inorder predecessor/successor. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree To traverse a threaded binary tree in inorder sequence, you need to determine the inorder successor of a node at each step. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. Identify the node for which you want to locate the inorder successor, and Write an algorithm toinorder the inorder successor of a node Algorithm to find the locate mark it as currentNode. in a threaded a node tree. threaded 3. If the right child of currentNode is a successor of binary in a thread: binary tree. a. Mark the right child of currentNode as successor. b. Exit. 4. Make currentNode point to its right child. 6. Repeat step 5 until left child of currentNode becomes a thread. 8. Make currentNode point to its left child. 10. Mark currentNode as successor. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. Identify the node for which you want Header Node to locate the inorder successor, and mark it as currentNode. 3. If the right child of currentNode is a thread: a. Mark the right child of currentNode as successor. . 65 . b. Exit. 4. Make currentNode point to its right child. . 40 . . 72 . 6. Repeat step 5 until left child of currentNode becomes a thread. 8. Make currentNode point to its left child. 30 . 50 . 69 80 10. Mark currentNode as successor. 60 Let us find the inorder successor of node 65 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) • Identify the node for which you want Header Node to locate the inorder successor, and mark it as currentNode. • If the right child of currentNode is a thread: a. Mark the right child of currentNode as successor. currentNode . 65 . b. Exit. 4. Make currentNode point to its right child. . 40 . . 72 . 6. Repeat step 5 until left child of currentNode becomes a thread. 8. Make currentNode point to its left child. 30 . 50 . 69 80 10. Mark currentNode as successor. 60 Let us find the inorder successor of node 65. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) • Identify the node for which you want Header Node to locate the inorder successor, and mark it as currentNode. • If the right child of currentNode is a thread: a. Mark the right child of currentNode as successor. currentNode . 65 . b. Exit. 4. Make currentNode point to its right child. . 40 . . 72 . 6. Repeat step 5 until left child of currentNode becomes a thread. 8. Make currentNode point to its left child. 30 . 50 . 69 80 10. Mark currentNode as successor. 60 Let us find the inorder successor of node 65. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. Identify the node for which you want Header Node to locate the inorder successor, and mark it as currentNode. 3. If the right child of currentNode is a thread: a. Mark the right child of currentNode as successor. currentNode . 65 . b. Exit. currentNode • Make currentNode point to its right child. . 40 . . 72 . • Repeat step 5 until left child of currentNode becomes a thread. • Make currentNode point to its left child. 30 . 50 . 69 80 • Mark currentNode as successor. 60 Let us find the inorder successor of node 65. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. Identify the node for which you want Header Node to locate the inorder successor, and mark it as currentNode. 3. If the right child of currentNode is a thread: a. Mark the right child of currentNode as successor. . 65 . b. Exit. currentNode • Make currentNode point to its right child. . 40 . . 72 . • Repeat step 5 until left child of currentNode becomes a thread. • Make currentNode point to its left child. 30 . 50 . 69 80 • Mark currentNode as successor. 60 Let us find the inorder successor of node 65. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. Identify the node for which you want Header Node to locate the inorder successor, and mark it as currentNode. 3. If the right child of currentNode is a thread: a. Mark the right child of currentNode as successor. . 65 . b. Exit. currentNode • Make currentNode point to its right child. . 40 . . 72 . • Repeat step 5 until left child of currentNode becomes a thread. • Make currentNode point to its left child. 30 . 50 . 69 80 • Mark currentNode as successor. currentNode 60 Let us find the inorder successor of node 65. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. Identify the node for which you want Header Node to locate the inorder successor, and mark it as currentNode. 3. If the right child of currentNode is a thread: a. Mark the right child of currentNode as successor. . 65 . b. Exit. • Make currentNode point to its right child. . 40 . . 72 . • Repeat step 5 until left child of currentNode becomes a thread. • Make currentNode point to its left child. 30 . 50 . 69 80 • Mark currentNode as successor. currentNode 60 Let us find the inorder successor of node 65. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) Inorder successor 1. Identify the node for which you want Header Node to locate the inorder successor, and located mark it as currentNode. 3. If the right child of currentNode is a thread: a. Mark the right child of currentNode as successor. . 65 . b. Exit. • Make currentNode point to its right child. . 40 . . 72 . • Repeat step 5 until left child of successor currentNode becomes a thread. • Make currentNode point to its left child. 30 . 50 . 69 80 • Mark currentNode as successor. currentNode 60 Let us find the inorder successor of node 65. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) Write an algorithm to traverse a threaded binary tree in inorder sequence. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread pointing to itself: Header Node a. Display “Tree is empty”. Algorithm to traverse a threaded b. Exit. binary tree in inorder sequence. 2. Mark the left child of the header node as currentNode. 4. Repeat step 4 until the left child of . 65 . currentNode becomes a thread. 6. Make currentNode point to its left child. . 40 . . 72 . 8. Display the information held by currentNode. 10. Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. 12. Find the inorder successor of currentNode, and mark the inorder successor as currentNode. 14. Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. 2. Mark the left child of the header node as currentNode. 4. Repeat step 4 until the left child of . 65 . currentNode becomes a thread. 6. Make currentNode point to its left child. . 40 . . 72 . 8. Display the information held by currentNode. 10. Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. 12. Find the inorder successor of currentNode, and mark the inorder successor as currentNode. 14. Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of currentNode . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of currentNode . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) • If the left child of the header node is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of currentNode . 65 . currentNode becomes a thread. currentNode • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. currentNode • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. currentNode • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder currentNode successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder currentNode successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder currentNode successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder currentNode successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. currentNode • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder currentNode successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. currentNode • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. currentNode • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. currentNode • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. currentNode • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. currentNode • Display the information held by the currentNode. 60 currentNode Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 60 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. • Display the information held by the currentNode. 60 currentNode Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 60 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of currentNode . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. • Display the information held by the currentNode. 60 currentNode Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 60 65 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of currentNode . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 60 65 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of currentNode . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. currentNode • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 60 65 69 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. currentNode • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 60 65 69 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. currentNode • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. currentNode • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 60 65 69 72 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. currentNode • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 60 65 69 72 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of . 65 . currentNode becomes a thread. currentNode • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder currentNode successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsTraversing a Threaded Binary Tree (Contd.) 1. If the left child of the header node 30 40 50 60 65 69 72 80 is a thread pointing to itself: Header Node a. Display “Tree is empty”. b. Exit. • Mark the left child of the header node as currentNode. • Repeat step 4 until the left child of Traversal complete . 65 . currentNode becomes a thread. • Make currentNode point to its left child. . 40 . . 72 . • Display the information held by currentNode. • Repeat steps 7 and 8 until right child of currentNode points to the 30 . 50 . 69 80 header node. • Find the inorder successor of currentNode, and mark the inorder currentNode successor as currentNode. • Display the information held by the currentNode. 60 Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree Insert an algorithm to locate the position inserting a newto be Write operation refers to the process of of a new node node at its appropriatebinary tree. inserted in a threaded position. To implement an insert operation in a threaded binary tree, you first need to locate the position for the new node to be inserted. For this, you first need to implement a search operation. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. AlgorithmHeader Node the to locate b. Exit. position of a new node in 2. Mark the left child of head as currentNode. . a threaded binary tree. 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. • Mark the left child of head as currentNode. . • • Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. currentNode . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. • Mark the left child of head as currentNode. parent . • • Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. currentNode . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. • Mark the left child of head as currentNode. parent . • • Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. currentNode . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. parent . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode parent becomes NULL: • Mark currentNode as parent. currentNode . 65 . • If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode parent becomes NULL: • Mark currentNode as parent. currentNode . 65 . • If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode parent becomes NULL: a. Mark currentNode as parent. currentNode . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. • Mark the left child of head as currentNode. . • • Mark head as parent. Repeat steps a, b, c, d, and e until currentNode parent becomes NULL: a. Mark currentNode as parent. . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode parent becomes NULL: • Mark currentNode as parent. . 65 . • If the value of the new node is less than that of currentNode and the left child of currentNode currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. parent . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: • Mark currentNode as parent. . 65 . • If the value of the new node is less than that of currentNode and the left child of currentNode currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. parent . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. parent . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right currentNode child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. • Mark the left child of head as currentNode. . • • Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. parent . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right currentNode child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. parent . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: parent i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right currentNode child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: • Mark currentNode as parent. . 65 . • If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: parent i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right currentNode child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: parent i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right currentNode child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: parent i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right currentNode child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: parent i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right currentNode child and go to step 4. e. If the value of the new node is greater than that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. 2. Mark the left child of head as currentNode. . 3. 4. Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: parent i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right currentNode child and go to step 4. e. If the value of the new node is greater than currentNode = NULL that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. If the left child of the header node is a thread Insert node 35 pointing to itself: a. Mark head as parent. Header Node b. Exit. • Mark the left child of head as currentNode. . • • Mark head as parent. Repeat steps a, b, c, d, and e until currentNode becomes NULL: a. Mark currentNode as parent. Parent node located . 65 . b. If the value of the new node is less than that of currentNode and the left child of currentNode is a normal link: i. Make currentNode point to its left child and go to step 4. . 40 . . 72 . c. If the value of the new node is less than that of currentNode and the left child of currentNode is a thread: parent i. Mark currentNode as NULL and go to step 4. d. If the value of the new node is greater than 30 . 50 . 69 80 that of currentNode and the right child of currentNode is a normal link: i. Make currentNode point to its right child and go to step 4. e. If the value of the new node is greater than currentNode = NULL that of currentNode and the right child of currentNode is a thread: 60 i. Mark currentNode as NULL and go to step 4. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) Write an algorithm toparent a node in an empty be inserted, Once you locate the insert of the new node to threaded binary tree. consider the following three cases: you need to Tree is empty (if parent is the header node) New node is to be inserted as the left child of its parent New node is to be inserted as the right child of its parent Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Allocate memory for the new node. Inserttree is initiallyaempty,in a you If the 65 Algorithm to insert node then 3. Assign value to the data field of need to insert the new nodeis the threaded binary tree, which as the new node. left child of the header node. initially empty. 5. Set the values of the left and right thread fields of the new node as zero. 7. Set the value of the left thread field of the head node as one. Header Node 9. Make the left child field of the header node as a link pointing to the new node. 11. Make the left child field of the new node as a thread pointing to the header node. 13. Make the right child field of the new node as a thread pointing to the header node. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Allocate memory for the new node. Insert 65 • Assign value to the data field of the new node. • Set the values of the left and right thread fields of the new node as zero. • Set the value of the left thread field of the head node as one. Header Node • Make the left child field of the header node as a link pointing to the new node. • Make the left child field of the new node as a thread pointing to the header node. • Make the right child field of the new node as a thread pointing to New Node the header node. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Allocate memory for the new node. • Assign value to the data field of the new node. • Set the values of the left and right thread fields of the new node as zero. • Set the value of the left thread field of the head node as one. Header Node • Make the left child field of the header node as a link pointing to the new node. • Make the left child field of the new node as a thread pointing to the header node. 65 • Make the right child field of the new node as a thread pointing to New Node the header node. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Allocate memory for the new node. • Assign value to the data field of the new node. • Set the values of the left and right thread fields of the new node as zero. • Set the value of the left thread field of the head node as one. Header Node • Make the left child field of the header node as a link pointing to the new node. • Make the left child field of the new node as a thread pointing to the header node. 65 • Make the right child field of the new node as a thread pointing to New Node the header node. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Allocate memory for the new node. • Assign value to the data field of the new node. • Set the values of the left and right thread fields of the new node as zero. • Set the value of the left thread field of the head node as one. Header Node • Make the left child field of the header node as a link pointing to the new node. • Make the left child field of the new node as a thread pointing to the header node. 65 • Make the right child field of the new node as a thread pointing to New Node the header node. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Allocate memory for the new node. • Assign value to the data field of the new node. • Set the values of the left and right thread fields of the new node as zero. • Set the value of the left thread field of the head node as one. Header Node • Make the left child field of the header node as a link pointing to the new node. • Make the left child field of the new node as a thread pointing to the header node. 65 • Make the right child field of the new node as a thread pointing to New Node the header node. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Allocate memory for the new node. • Assign value to the data field of the new node. • Set the values of the left and right thread fields of the new node as zero. • Set the value of the left thread field of the head node as one. Header Node • Make the left child field of the header node as a link pointing to the new node. • Make the left child field of the new node as a thread pointing to the header node. 65 • Make the right child field of the new node as a thread pointing to New Node the header node. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Allocate memory for the new node. • Assign value to the data field of Insertion complete the new node. • Set the values of the left and right thread fields of the new node as zero. • Set the value of the left thread field of the head node as one. Header Node • Make the left child field of the header node as a link pointing to the new node. • Make the left child field of the new node as a thread pointing to the header node. 65 • Make the right child field of the new node as a thread pointing to New Node the header node. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) Write an algorithm to insert a node in a non-empty threaded binary tree. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and mark it as parent. 2. Allocate memory and assign value to Algorithm Header Node to insert a new node the data field of the new node. 3. Set the values of the left and right in a threaded binary tree. . 4. thread fields of the new node as zero. If the value of the new node is less than that of parent: a. Make left child field of new node . 65 . b. point to the left child of parent. Make right child field of new node point to parent. c. Set the value of the left thread field of parent as one. . 40 . . 72 . d. Make left child field of parent point to the new node. e. Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and mark it as parent. Insert a node 75 2. Allocate memory and assign value to Header Node the data field of the new node. 3. Set the values of the left and right . 4. thread fields of the new node as zero. If the value of the new node is less than that of parent: a. Make left child field of new node . 65 . b. point to the left child of parent. Make right child field of new node point to parent. c. Set the value of the left thread field of parent as one. . 40 . . 72 . d. Make left child field of parent point to the new node. e. Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Locate the parent of the new node and mark it as parent. Insert a node 75 • Allocate memory and assign value to Header Node the data field of the new node. • Set the values of the left and right . • thread fields of the new node as zero. If the value of the new node is less than that of parent: a. Make left child field of new node . 65 . b. point to the left child of parent. Make right child field of new node point to parent. c. Set the value of the left thread field of parent as one. . 40 . . 72 . d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Locate the parent of the new node and mark it as parent. Insert a node 75 • Allocate memory and assign value to Header Node the data field of the new node. • Set the values of the left and right . • thread fields of the new node as zero. If the value of the new node is less than that of parent: a. Make left child field of new node . 65 . b. point to the left child of parent. Make right child field of new node point to parent. c. Set the value of the left thread field of parent as one. . 40 . . 72 . d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Locate the parent of the new node and mark it as parent. Insert a node 75 • Allocate memory and assign value to Header Node the data field of the new node. • Set the values of the left and right . • thread fields of the new node as zero. If the value of the new node is less than that of parent: a. Make left child field of new node . 65 . b. point to the left child of parent. Make right child field of new node point to parent. c. Set the value of the left thread field of parent as one. . 40 . . 72 . d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 75 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Locate the parent of the new node and mark it as parent. Insert a node 75 • Allocate memory and assign value to Header Node the data field of the new node. • Set the values of the left and right . • thread fields of the new node as zero. If the value of the new node is less than that of parent: a. Make left child field of new node . 65 . b. point to the left child of parent. Make right child field of new node point to parent. c. Set the value of the left thread field of parent as one. . 40 . . 72 . d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 75 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Locate the parent of the new node and mark it as parent. Insert a node 75 • Allocate memory and assign value to Header Node the data field of the new node. • Set the values of the left and right . • thread fields of the new node as zero. If the value of the new node is less than that of parent: a. Make left child field of new node . 65 . b. point to the left child of parent. Make right child field of new node point to parent. c. Set the value of the left thread field of parent as one. . 40 . . 72 . d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 75 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and mark it as parent. Insert a node 75 2. Allocate memory and assign value to Header Node the data field of the new node. 3. Set the values of the left and right . 4. thread fields of the new node as zero. If the value of the new node is less than that of parent: • Make left child field of new node . 65 . • point to the left child of parent. Make right child field of new node point to parent. • Set the value of the left thread field of parent as one. . 40 . . 72 . • Make left child field of parent point to the new node. parent • Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 75 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and mark it as parent. Insert a node 75 2. Allocate memory and assign value to Header Node the data field of the new node. 3. Set the values of the left and right . 4. thread fields of the new node as zero. If the value of the new node is less than that of parent: • Make left child field of new node . 65 . • point to the left child of parent. Make right child field of new node point to parent. • Set the value of the left thread field of parent as one. . 40 . . 72 . • Make left child field of parent point to the new node. parent • Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 75 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and mark it as parent. Insert a node 75 2. Allocate memory and assign value to Header Node the data field of the new node. 3. Set the values of the left and right . 4. thread fields of the new node as zero. If the value of the new node is less than that of parent: • Make left child field of new node . 65 . • point to the left child of parent. Make right child field of new node point to parent. • Set the value of the left thread field of parent as one. . 40 . . 72 . • Make left child field of parent point to the new node. parent • Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 75 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and mark it as parent. Insert a node 75 2. Allocate memory and assign value to Header Node the data field of the new node. 3. Set the values of the left and right . 4. thread fields of the new node as zero. If the value of the new node is less than that of parent: • Make left child field of new node . 65 . • point to the left child of parent. Make right child field of new node point to parent. • Set the value of the left thread field of parent as one. . 40 . . 72 . • Make left child field of parent point to the new node. parent • Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 . 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 75 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and Insertion complete mark it as parent. Insert a node 75 2. Allocate memory and assign value to Header Node the data field of the new node. 3. Set the values of the left and right . 4. thread fields of the new node as zero. If the value of the new node is less than that of parent: • Make left child field of new node . 65 . • point to the left child of parent. Make right child field of new node point to parent. • Set the value of the left thread field of parent as one. . 40 . . 72 . • Make left child field of parent point to the new node. parent • Exit. 5. If the value of the node is greater than that of parent: a. Make left child field of new node 30 . 50 . 69 . 80 point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. d. Make right child field of parent 60 75 point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and Header Node mark it as parent. Insert a node 35 2. Allocate memory and assign value to Let us now insert a node as the the data field of the new node. 3. Set the values of the left and right right child of its parent. thread fields of the new node as zero. 4. If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. e. Exit. 5. If the value of the node is greater than that of parent: 30 . 50 . 69 80 a. Make left child field of new node point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. 60 d. Make right child field of parent point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Locate the parent of the new node and Header Node mark it as parent. Insert a node 35 • Allocate memory and assign value to the data field of the new node. • Set the values of the left and right thread fields of the new node as zero. • If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: 30 . 50 . 69 80 a. Make left child field of new node point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. 60 d. Make right child field of parent point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Locate the parent of the new node and Header Node mark it as parent. Insert a node 35 • Allocate memory and assign value to the data field of the new node. • Set the values of the left and right thread fields of the new node as zero. • If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: 30 . 50 . 69 80 a. Make left child field of new node point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. 35 60 d. Make right child field of parent point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Locate the parent of the new node and Header Node mark it as parent. Insert a node 35 • Allocate memory and assign value to the data field of the new node. • Set the values of the left and right thread fields of the new node as zero. • If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: 30 . 50 . 69 80 a. Make left child field of new node point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. 35 60 d. Make right child field of parent point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) • Locate the parent of the new node and Header Node mark it as parent. Insert a node 35 • Allocate memory and assign value to the data field of the new node. • Set the values of the left and right thread fields of the new node as zero. • If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: 30 . 50 . 69 80 a. Make left child field of new node point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. 35 60 d. Make right child field of parent point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and Header Node mark it as parent. Insert a node 35 2. Allocate memory and assign value to the data field of the new node. 3. Set the values of the left and right thread fields of the new node as zero. 4. If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: 30 . 50 . 69 80 a. Make left child field of new node point to parent. b. Make right child field of new node point to the right child of parent. c. Set the value of right thread field of parent as one. 35 60 d. Make right child field of parent point to the new node. e. Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and Header Node mark it as parent. Insert a node 35 2. Allocate memory and assign value to the data field of the new node. 3. Set the values of the left and right thread fields of the new node as zero. 4. If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: 30 . 50 . 69 80 • Make left child field of new node point to parent. • Make right child field of new node point to the right child of parent. • Set the value of right thread field of parent as one. 35 60 • Make right child field of parent point to the new node. • Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and Header Node mark it as parent. Insert a node 35 2. Allocate memory and assign value to the data field of the new node. 3. Set the values of the left and right thread fields of the new node as zero. 4. If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: 30 . 50 . 69 80 • Make left child field of new node point to parent. • Make right child field of new node point to the right child of parent. • Set the value of right thread field of parent as one. 35 60 • Make right child field of parent point to the new node. • Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and Header Node mark it as parent. Insert a node 35 2. Allocate memory and assign value to the data field of the new node. 3. Set the values of the left and right thread fields of the new node as zero. 4. If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: 30 . 50 . 69 80 • Make left child field of new node point to parent. • Make right child field of new node point to the right child of parent. • Set the value of right thread field of parent as one. 35 60 • Make right child field of parent point to the new node. • Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and Header Node mark it as parent. Insert a node 35 2. Allocate memory and assign value to the data field of the new node. 3. Set the values of the left and right thread fields of the new node as zero. 4. If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: 30 . . 50 . 69 80 • Make left child field of new node point to parent. • Make right child field of new node point to the right child of parent. • Set the value of right thread field of parent as one. 35 60 • Make right child field of parent point to the new node. • Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsInserting Nodes in a Threaded Binary Tree (Contd.) 1. Locate the parent of the new node and Insertion complete Header Node mark it as parent. Insert a node 35 2. Allocate memory and assign value to the data field of the new node. 3. Set the values of the left and right thread fields of the new node as zero. 4. If the value of the new node is less than that of parent: . 65 . a. Make left child field of new node point to the left child of parent. b. Make right child field of new node point to parent. c. Set the value of the left thread . 40 . . 72 . field of parent as one. d. Make left child field of parent point to the new node. parent e. Exit. 5. If the value of the node is greater than that of parent: 30 . . 50 . 69 80 • Make left child field of new node point to parent. • Make right child field of new node point to the right child of parent. • Set the value of right thread field of parent as one. 35 60 • Make right child field of parent point to the new node. • Exit. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsSummary In this session, you learned that: Binary search trees can be used to implement indexing. A threaded binary tree is a binary tree in which a node with an empty left child stores the address of its inorder predecessor and the empty right child stores the address of its inorder successor. In a threaded binary tree, the left and right child field of a node, which holds the address of its inorder predecessor and inorder successor, respectively, is called a thread. You can traverse a threaded binary tree without implementing recursion. A threaded binary tree is represented as the left subtree of the header node. Ver. 1.0 Session 14
  • Data Structures and AlgorithmsSummary (Contd.) In contrast to a normal binary tree, each node in a threaded binary tree consists of two additional fields to keep track of whether the left and right child field of a node is a thread or a link. Ver. 1.0 Session 14