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

Show that the height h of the tower, The angle of elevation of the to...

The angle of elevation of the top of a tower from a point on the same level as the foot of the tower is α. On advancing 'p' meters towards the foot of the tower, the angle of eleva

Example of multiplying decimals, Example of Multiplying Decimals: Exa...

Example of Multiplying Decimals: Example:  0.45 x 10 = 4.5.  Same, while multiplying a decimal through 100, 1000, and 10,000, move the decimal point to the right the similar

Linear programming , Use the simplex method to solve the following LP Probl...

Use the simplex method to solve the following LP Problem. Max Z = 107x1+x2+2x3 Subject to 14x1+x2-6x3+3x4=7 16x1+x2-6x3 3x1-x2-x3 x1,x2,x3,x4 >=0

Derivatives of trig functions, Derivatives of Trig Functions In this s...

Derivatives of Trig Functions In this section we will see derivatives of functions other than polynomials or roots of polynomials. We'll begin this process off through taking

Example of division , Example of division: Divide 738 by 83. Soluti...

Example of division: Divide 738 by 83. Solution: Example: Divide 6409 by 28. Solution: Division could be verified through multiplying

Graph ( x + 1)2 /9 -( y - 2)2/4 =1 of hyperbola, Graph  ( x + 1) 2 /9 -( ...

Graph  ( x + 1) 2 /9 -( y - 2) 2 /4 =1 Solution It is a hyperbola. There are in fact two standard forms for a hyperbola.  Following are the basics for each form. H

Solving decimal equations, The distance around a square photograph is 12.8 ...

The distance around a square photograph is 12.8 centimeters. What is the langth of each side of the fotograph?

Compute the essential matrix and epipolar lines , 1. In Figure there are th...

1. In Figure there are three cameras where the distance between the cameras is B, and all three cameras have the same focal length f. The disparity dL = x0 - xL, while the disparit

Multiplication rule: dependent events, Multiplication Rule: Dependent Event...

Multiplication Rule: Dependent Events The joint probability of two events A and B which are dependent is equal to the probability of A multiplied by the probability of B given

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