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
C compiler does not verify the bounds of arrays. It is your job to do the essential work for checking boundaries wherever required. One of the most common arrays is a string tha

A common person's faith is that a computer can do anything. It is far from truth. In realism computer can carry out only definite predefined instructions. The formal illustration o

Description A heap is an efficient tree-based data structure that can be used as a priority queue. Recall that the abstract data type of a priority queue has the following opera

nested for loop for (i = 0; i for (j = 0; j sequence of statements } } Here, we observe that, the outer loop executes n times. Every time the outer loop execute

1. A string s is said to be periodic with a period α, if s is α k for some k > 2. (Note that α k is the string formed by concatenating k times.) A DNA sequence s is called a tand

Q.1 Write procedures/ Algorithm to insert and delete an element in to array. Q.2. Write an algorithm for binary search. What are the conditions under which sequential search of

write pseudocode to implement a queue with two stacks

* Initialise d & pi* for each vertex v within V( g ) g.d[v] := infinity  g.pi[v] := nil g.d[s] := 0; * Set S to empty * S := { 0 }  Q := V(g) * While (V-S)

So far, we now have been concerned only with the representation of single stack. What happens while a data representation is required for several stacks? Let us consider an array X

infix to revrse polish