Tree traversal, Data Structure & Algorithms

Q. What do you understand by the tree traversal? Write down the procedure for traversing a binary tree in preorder and execute it on the following tree. 

419_tree traversal.png

 

Ans:

The algorithm walks through tree data structure and performs some calculation at each node in the tree. This procedure of walking through the tree is called a tree traversal.

There are basically two different methods in which to visit systematically all the nodes of a tree-the depth-first traversal and the breadth-first traversal. Certain depth- first traversal methods happen frequently enough that they are given names of their own: preorder traversal, inorder traversal and postorder traversal.

The algorithm for traversing a tree in preorder is written as follows:-

i.     Process the root R.

ii.    Traverse left sub tree of R in preorder.
iii.   Traverse right sub tree of R in preorder. The preorder for the given tree is as follows:-

A   L1  R1

A  B    L1l  L1R  R1

A  B    D      L1R  R1

A  B    D      E       R1

A  B    D      E       C    R1L  R1R

A  B      D         E            C      F       R1R

A  B          D         E          C            F       G

Posted Date: 7/11/2012 1:38:53 AM | Location : United States







Related Discussions:- Tree traversal, Assignment Help, Ask Question on Tree traversal, Get Answer, Expert's Help, Tree traversal Discussions

Write discussion on Tree traversal
Your posts are moderated
Related Questions
I need a person who has a good background in using R. Studio? In adition, a person who is good in using algorithms.

how we can convert a graph into tree

how to convert 12 hour format into 24 hour format using c program

1. In computer science, a classic problem is how to dynamically store information so as to let for quick look up. This searching problem arises frequently in dictionaries, symbol t

Which are the two standard ways of traversing a graph? i. The depth-first traversal   ii. The breadth-first traversal

Abstract Data Types :- A useful tool for specifying the logical properties of a data type is the abstract data type or ADT. The term "abstract data type" refers to the basic mathem

Hubs - In reality a multiport repeater - Connects stations in a physical star topology - As well may create multiple levels of hierarchy to remove length limitation of 10

Materials consumed are priced in a systematic and realistic manner. It is argued that current acquisition costs are incurred for the purpose of meeting current production and sales

hello, i need help in data mining assignment using sas em and crisp-dm

Complexity of an Algorithm An algorithm is a sequence of steps to solve a problem; there may be more than one algorithm to solve a problem. The choice of a particular algorith