0% found this document useful (0 votes)
64 views1 page

Data Structures Notes

The document discusses three methods for traversing a binary tree: preorder traversal which visits the root node first then traverses the left and right subtrees; inorder traversal which traverses the left subtree first, then visits the root node, then traverses the right subtree; and postorder traversal which traverses the left and right subtrees first, then visits the root node last. Examples of each traversal type are given on a sample binary tree.

Uploaded by

Wew Nigga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views1 page

Data Structures Notes

The document discusses three methods for traversing a binary tree: preorder traversal which visits the root node first then traverses the left and right subtrees; inorder traversal which traverses the left subtree first, then visits the root node, then traverses the right subtree; and postorder traversal which traverses the left and right subtrees first, then visits the root node last. Examples of each traversal type are given on a sample binary tree.

Uploaded by

Wew Nigga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

DATA STRUCTURES NOTES

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

http://datastructuresnotes.blogspot.com/2009/02/binary-tree-traversal-preorder-inorder.html

You might also like