0% found this document useful (0 votes)
46 views

Tree-Traversal:: A. To Traverse A Non-Empty Binary Tree in Preorder, Perform The

Tree-traversal refers to systematically visiting each node in a tree data structure exactly once. There are three types of traversals classified by node visit order: preorder visits the root node first then traverses left and right subtrees; inorder first traverses the left subtree, then visits the root, and finally the right subtree; postorder first traverses the left and right subtrees then visits the root node last.

Uploaded by

lily212001
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Tree-Traversal:: A. To Traverse A Non-Empty Binary Tree in Preorder, Perform The

Tree-traversal refers to systematically visiting each node in a tree data structure exactly once. There are three types of traversals classified by node visit order: preorder visits the root node first then traverses left and right subtrees; inorder first traverses the left subtree, then visits the root, and finally the right subtree; postorder first traverses the left and right subtrees then visits the root node last.

Uploaded by

lily212001
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Tree-traversal: In computer science, tree-traversal refers to the

process of visiting (examining and/or updating) each node in a tree data


structure, exactly once, in a systematic way. Such traversals are
classified by the order in which the nodes are visited.

A. To traverse a non-empty binary tree in preorder, perform the


following operations recursively at each node, starting with the
root node:

1. Visit the root.


2. Traverse the left subtree.
3. Traverse the right subtree.

B. To traverse a non-empty binary tree in inorder (symmetric),


perform the following operations recursively at each node:

1. Traverse the left subtree.


2. Visit the root.
3. Traverse the right subtree.

C. To traverse a non-empty binary tree in postorder, perform the


following operations recursively at each node:

1. Traverse the left subtree.


2. Traverse the right subtree.
3. Visit the root.
Example 1:

Example 2:

You might also like