Non Recursive Algorithm to Traverse a Binary Tree, Data Structure & Algorithms

Q. Write down a non recursive algorithm to traverse a binary tree in order.                   

Ans:

Non - recursive algorithm to traverse a binary tree in inorder is as follows:-

Initially in the beginning   push NULL  onto STACK  and then set  PTR  = ROOT. Then    repeat the steps written below until   NULL is popped from STACK.

i.      Continue down the left -most path rooted at PTR, pushing each node N onto STACK and stopping when a node     N    with no left    child     is   pushed    onto

STACK.

ii.    [Backtracking.] Pop and  process the nodes on

STACK. If the NULL is popped then Exit. If a node N

Having a right child R(N) is processed, set PTR = R(N) (by assigning PTR = RIGHT[PTR] and return to the Step(a)).

 

 

Posted Date: 7/10/2012 5:56:43 AM | Location : United States







Related Discussions:- Non Recursive Algorithm to Traverse a Binary Tree, Assignment Help, Ask Question on Non Recursive Algorithm to Traverse a Binary Tree, Get Answer, Expert's Help, Non Recursive Algorithm to Traverse a Binary Tree Discussions

Write discussion on Non Recursive Algorithm to Traverse a Binary Tree
Your posts are moderated
Related Questions
As we talked in class, a program with two integer variables is universal. Now, we consider a special form of four variableprograms. Let G = (V; E) be a directed graph, where V is a

Since memory is becoming more & cheaper, the prominence of runtime complexity is enhancing. However, it is very much significant to analyses the amount of memory utilized by a prog

what do you understand by structured programming?explain with eg. top down and bottem up programming technique

circular queue using c

Q. Write down any four applications or implementation of the stack.                                     Ans. (i)       The Conversion of infix to postfix form (ii)

The information in the table below is available for a large fund-raising project. a. Determine the critical path and the expected completion time of the project. b. Plot the total

Q. Write down an algorithm to insert a node in the beginning of the linked list.                         Ans: /* structure containing a link part and link part

This section prescribes additional exercise with the recursive and iterative handling of a binary search tree. Adding to the Binary Search Tree Recursively Add implementation

Ask question #Minima binary search tree is used to locate the number 43 which of the following probe sequences are possible and which are not? explainum 100 words accepted#

The space-complexity of the algorithm is a constant. It just needs space of three integers m, n and t. Thus, the space complexity is O(1). The time complexity based on the loop