0% found this document useful (0 votes)
116 views2 pages

Binary Tree Traversal

There are three types of binary tree traversal: preorder, inorder, and postorder. Each type involves visiting each node exactly once by following a set order of operations - visiting the root node first or last, and recursively traversing the left and right subtrees in a different order for each type. The document provides examples of applying each traversal type to a sample binary tree and outputs the resulting node visit order.

Uploaded by

Sarthak Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views2 pages

Binary Tree Traversal

There are three types of binary tree traversal: preorder, inorder, and postorder. Each type involves visiting each node exactly once by following a set order of operations - visiting the root node first or last, and recursively traversing the left and right subtrees in a different order for each type. The document provides examples of applying each traversal type to a sample binary tree and outputs the resulting node visit order.

Uploaded by

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

Binary tree traversal:

Visiting each node in the tree exactly only once


Types:
Preorder, Inorder, and Postorder
Example:

Preorder traversal:
To traverse a binary tree in Preorder, following operations are carried-out
(i)

Visit the root

(ii)

Traverse the left subtree recursively

(iii)

Traverse the right subtree recursively

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 subtree recursively

(ii)

Visit the root

(iii)

Traverse the right subtree recursively

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 the left subtree recursively

(ii)

Traverse the right subtree recursively

(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

You might also like