Page 539 - Computer science 868 Class 12
P. 539

Let us demonstrate with some examples.
                                                                                                        3
                 Example 1: Write (a) Pre order (b) Post order (c) In order traversal for
                 the given Binary tree.
                                                                                               10                5
                 Pre Order   :   3, 10, 11, 15,20,12,13,5,6,8

                 Post Order  :   15, 20, 11, 13, 12, 10, 6, 8, 5, 3
                 In Order   :   15, 11, 20, 10, 13, 12, 3, 6, 5, 8                       11          12      6        8




                                                                                    15      20    13
                                  A


                         H                 B
                                                     Example 2: Write (a) Pre order (b) Post order (c) In order traversal for the
                                                     given Binary tree.

                   G           I                C    Pre Order  :  A, H, G, I, F, E, B, C, D
                                                     Post Order :  G, F, E, I, H, D, C, B, A
                                                     In Order   :  G, H, F, I, E, A, B, D, C
                          F       E        D





                 Example 3: Write (a) Pre order (b) Post order (c) In order traversal
                 for the given Binary tree.                                                             50


                 Pre Order   :   50, 17, 12, 9, 14, 23, 19, 72, 54, 67, 76                     17                72
                 Post Order   :   9, 14, 12, 19, 23, 17, 67, 54, 76, 72, 50

                 In Order    :   9, 12, 14, 17, 23, 19, 50, 54, 67, 72, 76               12          23      54      76




                                                                                    9       14           19      67



                 Example 4: Answer the following from the given diagram of a Binary Tree.                       [ISC 2011]
                     (i) Write the Post order tree traversal                                            A
                     (ii) Name the Leaves of the tree
                    (iii) Height of the tree                                                       B           C
                    (iv) Root of the tree

                 Ans. (i) Post Order Traversal: B, D, G, H, F, E, C, A                                      D     E
                      (ii) Leaves are B, D, G, H
                     (iii) Height of tree : 5                                                                   F
                     (iv) Root of the tree : A
                                                                                                            G     H




                                                                                                                       537
                                                                                                       Data Structures  537
   534   535   536   537   538   539   540   541   542   543   544