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
how to draw a 5 inch square on the screen using * symbol

write a algorithsm in c to perform push and pop operations stastic implementation using array ?

include include include /* Definition of structure node */ typedef struct node { int data; struct node *next; } ; /* Definition of push function */

Each of the comparison in the binary search decrease the number of possible candidates where the key value can be searched by a factor of 2 as the array is divided into two halves

Q. Implement a stack making use of the linked list. Show the PUSH and POP operations both. A n s . Stack implemantation using linked list # include # include

Linear search is not the most efficient way to search an item within a collection of items. Though, it is extremely simple to implement. Furthermore, if the array elements are arra

What are the Objectives of visual realism applications After studying this unit, you should be able to know specific needs of realism, add realism to pictures by el

merging 4 sorted files containing 50 10 25 and 15 records will take time

A company is carrying out a survey by observing traffic at a road junction. Every time a car, bus or lorry passed by road junction it was noted down. 10 000 vehicles were counted d

Question 1 Write a program in 'C' to read N numbers and print them in descending order Question 2 Discuss the properties of ADT Question 3 Write a note on