SlideShare a Scribd company logo
1 of 107
Data Structures and Algorithms
Objectives


                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 Algorithms
Indexing


               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 Algorithms
Indexing (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 Algorithms
Implementing 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 Algorithms
Defining 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 Algorithms
Defining 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 Algorithms
Defining 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 Algorithms
Defining 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 Algorithms
Defining 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 Algorithms
Defining 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 Algorithms
Defining 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 Algorithms
Just 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 Algorithms
Representing 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 Algorithms
Representing 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 Algorithms
Just 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 Algorithms
Just 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Traversing 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 Algorithms
Inserting 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 Algorithms
Inserting 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 Algorithms
Inserting 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 Algorithms
Inserting 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 Algorithms
Inserting 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
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14
10 ds and algorithm session_14

More Related Content

Viewers also liked

InApp Inc. Corporate Profile
InApp Inc. Corporate ProfileInApp Inc. Corporate Profile
InApp Inc. Corporate Profileinapp
 
Hec ras-dasar-simple-geometry-river-sep11
Hec ras-dasar-simple-geometry-river-sep11Hec ras-dasar-simple-geometry-river-sep11
Hec ras-dasar-simple-geometry-river-sep11WSKT
 
I suggest efinancials
I suggest efinancialsI suggest efinancials
I suggest efinancialsTietoNL
 
Портфоліо Кушніренко К.А.
Портфоліо Кушніренко К.А.Портфоліо Кушніренко К.А.
Портфоліо Кушніренко К.А.dashootkagakh
 
Trivandrum master plan draft comments 060213
Trivandrum master plan draft comments 060213Trivandrum master plan draft comments 060213
Trivandrum master plan draft comments 060213Ajay Prasad
 
Modul microsoft word 2013
Modul microsoft word 2013Modul microsoft word 2013
Modul microsoft word 2013Anto Jurang
 
Digital Dimensions by Emrecan Gulay
Digital Dimensions by Emrecan GulayDigital Dimensions by Emrecan Gulay
Digital Dimensions by Emrecan GulayEmrecan Gulay
 
Metropolis India Managing Urban Growth
Metropolis India Managing Urban GrowthMetropolis India Managing Urban Growth
Metropolis India Managing Urban GrowthAnupam Yog
 
Sni 2847 2013 persyaratan beton stuktural untuk bangunan gedung
Sni 2847 2013 persyaratan beton stuktural untuk bangunan gedungSni 2847 2013 persyaratan beton stuktural untuk bangunan gedung
Sni 2847 2013 persyaratan beton stuktural untuk bangunan gedungWSKT
 
14. sma kelas xi rpp pemanasan global (karlina 1308233) (1)
14. sma kelas xi rpp pemanasan global (karlina 1308233) (1)14. sma kelas xi rpp pemanasan global (karlina 1308233) (1)
14. sma kelas xi rpp pemanasan global (karlina 1308233) (1)eli priyatna laidan
 
Jurnal jembatan rangka baja
Jurnal jembatan rangka bajaJurnal jembatan rangka baja
Jurnal jembatan rangka bajaE Sanjani
 
UMPTN Fisika 2002 regional II Kode 321
UMPTN Fisika 2002 regional II Kode 321UMPTN Fisika 2002 regional II Kode 321
UMPTN Fisika 2002 regional II Kode 321SMA Negeri 9 KERINCI
 
Valtech - Réalité virtuelle : analyses, perspectives, démonstrations
Valtech - Réalité virtuelle : analyses, perspectives, démonstrationsValtech - Réalité virtuelle : analyses, perspectives, démonstrations
Valtech - Réalité virtuelle : analyses, perspectives, démonstrationsValtech
 

Viewers also liked (19)

InApp Inc. Corporate Profile
InApp Inc. Corporate ProfileInApp Inc. Corporate Profile
InApp Inc. Corporate Profile
 
Hec ras-dasar-simple-geometry-river-sep11
Hec ras-dasar-simple-geometry-river-sep11Hec ras-dasar-simple-geometry-river-sep11
Hec ras-dasar-simple-geometry-river-sep11
 
I suggest efinancials
I suggest efinancialsI suggest efinancials
I suggest efinancials
 
Cas_client_Sporting
Cas_client_SportingCas_client_Sporting
Cas_client_Sporting
 
Портфоліо Кушніренко К.А.
Портфоліо Кушніренко К.А.Портфоліо Кушніренко К.А.
Портфоліо Кушніренко К.А.
 
Trivandrum master plan draft comments 060213
Trivandrum master plan draft comments 060213Trivandrum master plan draft comments 060213
Trivandrum master plan draft comments 060213
 
Modul microsoft word 2013
Modul microsoft word 2013Modul microsoft word 2013
Modul microsoft word 2013
 
Digital Dimensions by Emrecan Gulay
Digital Dimensions by Emrecan GulayDigital Dimensions by Emrecan Gulay
Digital Dimensions by Emrecan Gulay
 
Metropolis India Managing Urban Growth
Metropolis India Managing Urban GrowthMetropolis India Managing Urban Growth
Metropolis India Managing Urban Growth
 
Bab 1. atmosfer bintang
Bab 1. atmosfer bintangBab 1. atmosfer bintang
Bab 1. atmosfer bintang
 
Sni 2847 2013 persyaratan beton stuktural untuk bangunan gedung
Sni 2847 2013 persyaratan beton stuktural untuk bangunan gedungSni 2847 2013 persyaratan beton stuktural untuk bangunan gedung
Sni 2847 2013 persyaratan beton stuktural untuk bangunan gedung
 
14. sma kelas xi rpp pemanasan global (karlina 1308233) (1)
14. sma kelas xi rpp pemanasan global (karlina 1308233) (1)14. sma kelas xi rpp pemanasan global (karlina 1308233) (1)
14. sma kelas xi rpp pemanasan global (karlina 1308233) (1)
 
Jurnal jembatan rangka baja
Jurnal jembatan rangka bajaJurnal jembatan rangka baja
Jurnal jembatan rangka baja
 
UMPTN Fisika 2002 regional II Kode 321
UMPTN Fisika 2002 regional II Kode 321UMPTN Fisika 2002 regional II Kode 321
UMPTN Fisika 2002 regional II Kode 321
 
listrik dc lanjutan
listrik dc lanjutanlistrik dc lanjutan
listrik dc lanjutan
 
gelombang bunyi
gelombang bunyigelombang bunyi
gelombang bunyi
 
Immunization
ImmunizationImmunization
Immunization
 
teori kuantum
teori kuantumteori kuantum
teori kuantum
 
Valtech - Réalité virtuelle : analyses, perspectives, démonstrations
Valtech - Réalité virtuelle : analyses, perspectives, démonstrationsValtech - Réalité virtuelle : analyses, perspectives, démonstrations
Valtech - Réalité virtuelle : analyses, perspectives, démonstrations
 

Similar to 10 ds and algorithm session_14

Gpu computing workshop
Gpu computing workshopGpu computing workshop
Gpu computing workshopdatastack
 
Sharding Architectures
Sharding ArchitecturesSharding Architectures
Sharding Architecturesguest0e6d5e
 
Database Sharding the Right Way: Easy, Reliable, and Open source - HighLoad++...
Database Sharding the Right Way: Easy, Reliable, and Open source - HighLoad++...Database Sharding the Right Way: Easy, Reliable, and Open source - HighLoad++...
Database Sharding the Right Way: Easy, Reliable, and Open source - HighLoad++...CUBRID
 
Analysis of Bayes, Neural Network and Tree Classifier of Classification Techn...
Analysis of Bayes, Neural Network and Tree Classifier of Classification Techn...Analysis of Bayes, Neural Network and Tree Classifier of Classification Techn...
Analysis of Bayes, Neural Network and Tree Classifier of Classification Techn...cscpconf
 
Presentation overview of neural & kernel based clustering
Presentation overview of neural & kernel based clustering Presentation overview of neural & kernel based clustering
Presentation overview of neural & kernel based clustering Shubham Vijay Vargiy
 
PT-4054, "OpenCL™ Accelerated Compute Libraries" by John Melonakos
PT-4054, "OpenCL™ Accelerated Compute Libraries" by John MelonakosPT-4054, "OpenCL™ Accelerated Compute Libraries" by John Melonakos
PT-4054, "OpenCL™ Accelerated Compute Libraries" by John MelonakosAMD Developer Central
 
oracle 9i cheat sheet
oracle 9i cheat sheetoracle 9i cheat sheet
oracle 9i cheat sheetPiyush Mittal
 

Similar to 10 ds and algorithm session_14 (9)

Css trees
Css treesCss trees
Css trees
 
Gpu computing workshop
Gpu computing workshopGpu computing workshop
Gpu computing workshop
 
Sharding Architectures
Sharding ArchitecturesSharding Architectures
Sharding Architectures
 
Database Sharding the Right Way: Easy, Reliable, and Open source - HighLoad++...
Database Sharding the Right Way: Easy, Reliable, and Open source - HighLoad++...Database Sharding the Right Way: Easy, Reliable, and Open source - HighLoad++...
Database Sharding the Right Way: Easy, Reliable, and Open source - HighLoad++...
 
Analysis of Bayes, Neural Network and Tree Classifier of Classification Techn...
Analysis of Bayes, Neural Network and Tree Classifier of Classification Techn...Analysis of Bayes, Neural Network and Tree Classifier of Classification Techn...
Analysis of Bayes, Neural Network and Tree Classifier of Classification Techn...
 
Presentation overview of neural & kernel based clustering
Presentation overview of neural & kernel based clustering Presentation overview of neural & kernel based clustering
Presentation overview of neural & kernel based clustering
 
PT-4054, "OpenCL™ Accelerated Compute Libraries" by John Melonakos
PT-4054, "OpenCL™ Accelerated Compute Libraries" by John MelonakosPT-4054, "OpenCL™ Accelerated Compute Libraries" by John Melonakos
PT-4054, "OpenCL™ Accelerated Compute Libraries" by John Melonakos
 
oracle 9i cheat sheet
oracle 9i cheat sheetoracle 9i cheat sheet
oracle 9i cheat sheet
 
orical
oricalorical
orical
 

More from Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Recently uploaded

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Recently uploaded (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

10 ds and algorithm session_14

  • 1. Data Structures and Algorithms Objectives In this session, you will learn to: Apply trees to solve programming problems Implement a threaded binary tree Ver. 1.0 Session 14
  • 2. Data Structures and Algorithms Indexing 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
  • 3. Data Structures and Algorithms Indexing (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
  • 4. Data Structures and Algorithms Implementing 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
  • 5. Data Structures and Algorithms Defining 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
  • 6. Data Structures and Algorithms Defining 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
  • 7. Data Structures and Algorithms Defining 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
  • 8. Data Structures and Algorithms Defining 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
  • 9. Data Structures and Algorithms Defining 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
  • 10. Data Structures and Algorithms Defining 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
  • 11. Data Structures and Algorithms Defining 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
  • 12. Data Structures and Algorithms Just 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
  • 13. Data Structures and Algorithms Representing 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
  • 14. Data Structures and Algorithms Representing a Threaded Binary Tree (Contd.) Various operations in a threaded binary tree are as follows: Traversal Search Insert Delete Ver. 1.0 Session 14
  • 15. Data Structures and Algorithms Just 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
  • 16. Data Structures and Algorithms Just 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
  • 17. Data Structures and Algorithms Traversing 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
  • 18. Data Structures and Algorithms Traversing 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
  • 19. Data Structures and Algorithms Traversing 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
  • 20. Data Structures and Algorithms Traversing 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
  • 21. Data Structures and Algorithms Traversing 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
  • 22. Data Structures and Algorithms Traversing 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
  • 23. Data Structures and Algorithms Traversing 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
  • 24. Data Structures and Algorithms Traversing 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
  • 25. Data Structures and Algorithms Traversing 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
  • 26. Data Structures and Algorithms Traversing 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
  • 27. Data Structures and Algorithms Traversing a Threaded Binary Tree (Contd.) Write an algorithm to traverse a threaded binary tree in inorder sequence. Ver. 1.0 Session 14
  • 28. Data Structures and Algorithms Traversing 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
  • 29. Data Structures and Algorithms Traversing 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
  • 30. Data Structures and Algorithms Traversing 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
  • 31. Data Structures and Algorithms Traversing 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
  • 32. Data Structures and Algorithms Traversing 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
  • 33. Data Structures and Algorithms Traversing 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
  • 34. Data Structures and Algorithms Traversing 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
  • 35. Data Structures and Algorithms Traversing 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
  • 36. Data Structures and Algorithms Traversing 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
  • 37. Data Structures and Algorithms Traversing 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
  • 38. Data Structures and Algorithms Traversing 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
  • 39. Data Structures and Algorithms Traversing 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
  • 40. Data Structures and Algorithms Traversing 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
  • 41. Data Structures and Algorithms Traversing 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
  • 42. Data Structures and Algorithms Traversing 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
  • 43. Data Structures and Algorithms Traversing 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
  • 44. Data Structures and Algorithms Traversing 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
  • 45. Data Structures and Algorithms Traversing 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
  • 46. Data Structures and Algorithms Traversing 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
  • 47. Data Structures and Algorithms Traversing 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
  • 48. Data Structures and Algorithms Traversing 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
  • 49. Data Structures and Algorithms Traversing 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
  • 50. Data Structures and Algorithms Traversing 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
  • 51. Data Structures and Algorithms Traversing 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
  • 52. Data Structures and Algorithms Inserting 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
  • 53. Data Structures and Algorithms Inserting 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
  • 54. Data Structures and Algorithms Inserting 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
  • 55. Data Structures and Algorithms Inserting 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
  • 56. Data Structures and Algorithms Inserting 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

Editor's Notes

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.