Вы находитесь на странице: 1из 3

Data Structures Notes: Binary tree traversal: Preorder, Inorder, and Postorder http://datastructuresnotes.blogspot.com/2009/02/binary-tree-traversal-pr...

More

Next Blog

Create Blog

Sign In

Thursday, February 19, 2009

Binary tree traversal: Preorder, Inorder, and Postorder


In order to illustrate few of the binary tree traversals, let us consider the below binary tree:

Preorder traversal: To traverse a binary tree in Preorder, following operations are carried-out (i) Visit the root, (ii) Traverse the left subtree, and (iii) Traverse the right subtree. Therefore, the Preorder traversal of the above tree will outputs: 7, 1, 0, 3, 2, 5, 4, 6, 9, 8, 10 Inorder traversal: To traverse a binary tree in Inorder, following operations are carried-out (i) Traverse the left most subtree starting at the left external node, (ii) Visit the root, and (iii) Traverse the right subtree starting at the left external node. Therefore, the Inorder traversal of the above tree will outputs: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Postorder traversal: To traverse a binary tree in Postorder, following operations are carried-out (i) Traverse all the left external nodes starting with the left most subtree which is then followed by bubble-up all the internal nodes, (ii) Traverse the right subtree starting at the left external node which is then followed by bubble-up all the internal nodes, and (iii) Visit the root. Therefore, the Postorder traversal of the above tree will outputs: 0, 2, 4, 6, 5, 3, 1, 8, 10, 9, 7
Posted by Nash at 12:11 PM Labels: Binary tree, Inorder traversal, Postorder traversal, Preorder traversal, Traversal

No comments:

1 of 3

5/27/2013 5:41 PM

Data Structures Notes: Binary tree traversal: Preorder, Inorder, and Postorder http://datastructuresnotes.blogspot.com/2009/02/binary-tree-traversal-pr...

Post a Comment

Comment as:

Newer Post Subscribe to: Post Comments (Atom)

Home

Older Post

Unique Visitors
33655

Blog Archive
2009 (44) March (26) February (18) Binary tree traversal: Preorder, Inorder, and Post... String Searching Algorithm KMP Algorithm Exercise-Radix Sorting Exercise-Manipulating an element in an array (Repl... Exercise-Reverse Polish Notation (RPN) Sorting Algorithm - HeapSort & Heapify Algorithm that returns the middle element of a dou... Time complexity - Omega of data structures Time complexity - Omega of algorithms Checklist before selecting the right data structur... Algorithm to print-all-pairs in the tables (X, Y) Algorithm to Sum-up n number of items in the table... Time complexity of algorithms - In particular Big ... Operation time complexity for a LINKED LIST Operation time complexity for an ARRAY Selection Sorting An Array Bubble Sorting An Array Computing The Median of An Array

2 of 3

5/27/2013 5:41 PM

Data Structures Notes: Binary tree traversal: Preorder, Inorder, and Postorder http://datastructuresnotes.blogspot.com/2009/02/binary-tree-traversal-pr...

About Me
Nash View my complete profile

3 of 3

5/27/2013 5:41 PM

Вам также может понравиться