In-order traversal, Data Structure & Algorithms

Write steps for algorithm for In-order Traversal

This process when implemented iteratively also needs a stack and a Boolean to prevent the execution from traversing any portion or area of a tree twice. The common process of in-order traversal follows the following steps:

1.   push a NULL onto the given stack.

2.   starting with the root, proceed down the left side of the   tree. As long as  there is one more left node  following     the current  node,

push the pointer to the current node onto the stack and move to the left node which follows it.

3.   when there are no further left nodes following the current node, process the current node.

4.   check to see if the last left node has a right node(it   certainly doesn't  have  a  left node).

5.   if  there is a  right node then there will be subtree to the right. This should be further processed in following steps 2   to 4.

6.   if there is no right node in it then pop the last node from the stack (back up one node). Process this node and as this node has a left subtree that     has  already   been     processed, move    to   the right of the node and start looking for a left and right subtree again.

 

 

 

Posted Date: 7/9/2012 10:10:15 PM | Location : United States







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

Write discussion on In-order traversal
Your posts are moderated
Related Questions
Double Linked List In a doubly linked list, also known as 2 way lists, each node is separated into 3 parts. The first part is called last pointer field. It has the address of t

for i=1 to n if a[i}>7 for j=2 to n a[j]=a{j}+j for n=2 to n a[k]=a[j]+i else if a[1]>4 && a[1] for 2 to a[1] a[j]= a{j]+5 else for 2to n a[j]=a[j]+i ..

Define a sparse metrics. A matrix in which number of zero entries are much higher than the number of non zero entries is known as sparse matrix. The natural method of showing m

Write a detailed description of a function that takes in an integer as an argument, then prints out the squares of all positive integers whose squares are less than the input. (The

A small shop sells 280 different items. Every item is identified by a 3 - digit code. All items which start with a zero (0) are cards, all items which start with a one (1) are swee

difference between recursion and iteration

H o w can you r ot a t e a B i n a r y Tr e e? E x pl a i n r i g h t a n d l eft r ot a tion s by taking an e x a mpl e.   If after

Q. Explain that how do we implement two stacks in one array A[1..n] in such a way that neither the stack overflows unless the total number of elements in both stacks together is n.

Determine about the logic gates Many electronic circuits operate using binary logic gates. Logic gates essentially process signals that represent true or false or equivalent i.

what is far and near procedures in system programming?