Monday, March 25, 2013

Preorder, Postorder, and Inorder


Construct tree of A, B, C, D, ,E, F, G, H, I, J, K, L, M, N, O and traverse whole tree by all Preorder, Postorder, and Inorder.



  

1. Preorder

A – B – D – H – I – E – J – K – C – F – L – M – G – N – O

2. Postorder

H – I – D – J – K – E – B – L – M – F – N – O – G – C – A

3. Inorder

H – D – I – B – J – E – K – A – L – F – M – C – N – G – O


Construct tree of 45, 69, 99, 4, 5, 13, 17, 19, 26, 55, 89 and traverse whole tree by all Preorder, Postorder, and Inorder.




  

1. Preorder

45 – 69 – 4 – 19 – 26 – 5 – 55 – 89 – 99 – 13 – 17

2. Postorder

19 – 26 – 4 – 55 – 89 – 5 – 69 – 13 – 17 – 99 – 45

3. Inorder

19 – 4 – 26 – 69 – 55 – 5 – 89 – 45 – 13 – 99 – 17


Traverse whole tree by all Preorder, Postorder, and Inorder.




1. Preorder

99 – 88 – 66 – 22 – 11 – 55 – 9 – 8 – 77 – 44 – 7 – 33 – 6 – 5

2. Inorder

22 – 66 – 11 – 88 – 9 – 55 – 8 – 99 – 44 – 7 – 77 – 6 – 33 – 5

3. Postorder

22 – 11 – 66 – 9 – 8 – 55 – 88 – 7 – 44 – 6 – 5 – 33 – 77 – 99