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

Evaluate the volume of a ball, Evaluate the volume of a ball whose radius i...

Evaluate the volume of a ball whose radius is 4 inches? Round to the nearest inch. (π = 3.14) a. 201 in 3 b. 268 in 3 c. 804 in 3 d. 33 in 3 b. The volume of a

Analalitic geometry, 1. Write down the canonical equations of the line pass...

1. Write down the canonical equations of the line passing through the point A(2,3, 4) and being parallel to the vector q ={5,0,-1}.

Find out ratio, the sides of a right angle triangle are a,a+d,a+2d with a a...

the sides of a right angle triangle are a,a+d,a+2d with a and d both positive.the ratio of a to d  a)1:2 b)1:3 c)3:1 d)5:2 answer is (c) i.e. 3:1 Solution: Applying

Precalculus, describe the end behavior of the following function using Limi...

describe the end behavior of the following function using Limit notation f(x)= 2x-1/x-1

Experience language pictures symbols-e - l - p - s , E - L - P - S : Has t...

E - L - P - S : Has the title of this section stumped you? Children, similarly, don't understand new symbols that are thrust upon them without giving them an adequate grounding. Y

Write algorithm for the multiplication of a 3-digit number, E1) Why do we s...

E1) Why do we shift the place by one, of the result in the second row of the calculation, when we multiply, say, 35 by 237 E2) Write down the algorithm for the multiplication of

Word problems, The sum of two numbers is 19, their difference is 5. find th...

The sum of two numbers is 19, their difference is 5. find the numbers

Find out all the critical points and derivation, Find out all the critical ...

Find out all the critical points for the function. Solution Following is the derivative for this function. Now, this looks unpleasant, though along with a little fa

Find out the area of the circle, 1. The number of accidents attended to by ...

1. The number of accidents attended to by 6 emergency ambulance stations during a 5 month period was: Station May June July Aug Sep      A        21     20     22    37    37

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