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

Discrete, For each of these arguments determine whether the argument is cor...

For each of these arguments determine whether the argument is correct or incorrect and explain why. a) Everyone enrolled in the university has lived in a dormitory. Mia has never l

If she mails 1, Lucy's Lunch is sending out flyers and pays a bulk rate of ...

Lucy's Lunch is sending out flyers and pays a bulk rate of 14.9 cents per piece of mail. If she mails 1,500 flyers, what will she pay? Multiply the price per piece through the

Circles, how to find equations of circles when given equations of centres o...

how to find equations of circles when given equations of centres on which it lies?

Integers, The set of whole numbers also does not satisfy all our requ...

The set of whole numbers also does not satisfy all our requirements as on observation, we find that it does not include negative numbers like -2, -7 and so on. To

Determine the inverse transform, Determine the inverse transform of each of...

Determine the inverse transform of each of the subsequent. (a)    F(s) = (6/s) - (1/(s - 8)) + (4 /(s -3)) (b)   H(s) = (19/(s+2)) - (1/(3s - 5))  + (7/s 2 ) (c)    F(s) =

Prove that ac2 =ab2 + bc2+2bcxbd, If ABC is an obtuse angled triangle, obtu...

If ABC is an obtuse angled triangle, obtuse angled at B and if AD⊥CB Prove that AC 2 =AB 2 + BC 2 +2BCxBD Ans:    AC 2 = AD 2 + CD 2 = AD 2 + (BC + BD) 2 = A

Determine differential equation from direction field, Thus, just why do we ...

Thus, just why do we care regarding direction fields? Two nice pieces of information are there which can be readily determined from the direction field for a differential equation.

MATLAB, Program of "surface of revolution" in MATLAB

Program of "surface of revolution" in MATLAB

How long will it take to dispense 330 gallons, A large pipe dispenses 750 g...

A large pipe dispenses 750 gallons of water in 50 seconds. At this rate, how long will it take to dispense 330 gallons? Find out the number of gallons per second by dividing 75

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