How do you traverse a binary tree, Mathematics

Assignment Help:

How do you traverse a Binary Tree?  Describe Preorder, Inorder and Postorder traversals with example.    

Ans: Traversal of tree means tree searching for a aim. The aim may be for searching or sorting of the items consisted of in a tree. A tree may consist of an item at its node as a label.

Traversing a tree is a recursive process. 

1764_How do you traverse a Binary Tree.png

To apply this, a tree is considered to comprise three components: root, left subtree and right subtree. These three components can be in order in six different ways: (left, root, right), (root, left, right), (left, right, root), (right, left, root), (right, root, left) and (root, right, left). The first three are used while the last three combinations are of no make use of as it alters the positions of a node in a positional tree.

Inorder Traversal: In this type of traversal, a tree is traversed in the sequence: Left subtree, Root, Right subtree.   

In the above expression, start at the root node marked, +. As first we have to traverse its left subtree, thus move to the root of left subtree that is node marked, *. Once again it has a left subtree with root node marked +, visit it. This subtree has a node labeled 3 that has no left subtree, thus out put 3. Then root of this subtree that is '+' and then right subtree which is once again a node labeled with 4, so output it. So we have expression acquired till here is 3 + 4.

Proceeding this way we acquire (3+4)*(5-2) + (-5). Parentheses signify both precedence and portion of the sub tree to which this sub-expression corresponds.     

Preorder Traversal: In this type of traversal a tree is traversed in the sequence: Root, Left subtree, Right subtree. Apply the algorithm recursively till all nodes have been visited, we acquire + * + 3 4 - 5 2 -5. 

Postorder Traversal: In this type of traversal a tree is traversed in the sequence: Left subtree, Right subtree, Root. We acquire 3 4 + 5 2 - * 5 - +.


Related Discussions:- How do you traverse a binary tree

What were her sales for the month of may of medical supplies, Kim is a medi...

Kim is a medical supplies salesperson. Each month she receives a 5% commission on all her sales of medical supplies up to $20,000 and 8.5% on her total sales over $20,000. Her tota

Method for simultaneous equations of two or more variables, Method In ...

Method In this method we eliminate either x or y, get the value of other variable and then substitute that value in either of the original equations to

What was his weight within pounds and ounces, Justin weighed 8 lb 12 oz whi...

Justin weighed 8 lb 12 oz while he was born. At his two-week check-up, he had gained 8 ounces. What was his weight within pounds and ounces? There are 16 ounces within a pound.

Fuzzy decisionmaking using minimization of regret, why we use decision maki...

why we use decision making using minimization of regret method in uncertainty?

Sketch the exponental graph of f( x )=2x and g( x )= 1/2 , Example Sketc...

Example Sketch the graph of following f( x ) = 2x  and  g( x ) = ( 1 /2) x Solution Let's firstly make a table of values for these two functions. Following is

staticis, a statisics professor plans classes so carefully that the length...

a statisics professor plans classes so carefully that the lengths of her classes are uniformly distributed between 46.0 and 56.0 minutes. find the probability that a given class pe

Profit and loss, A man sold an item for Rs 6,750 at a loss 25%. What will b...

A man sold an item for Rs 6,750 at a loss 25%. What will be the selling price of same item if he sells it at a profit of 15%?

How much does every person required to pay rob, Rob purchased picnic food f...

Rob purchased picnic food for $33.20 to share along with three of his friends. They plan to split the cost evenly among the four friends. How much does every person required to pay

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd