Non-recursive algorithm, Data Structure & Algorithms


QWrite down the non-recursive algorithm to traverse a tree in preorder.

Ans:

The Non- Recursive algorithm for preorder traversal is written below: Initially in the begnining

push NULL onto stack and then set PTR=Root. Keep on repeating the following steps until PTR= NULL.

1. Preorder down the left most paths routed at the PTR.

2. Processing each node N on the path and pushing each right child if there is onto the stack.[The traversing will stop when (PTR)=NULL]

3. Backtracking: pop and assign to PTR the top element on stack. If PTR is not equal to NULL then return to step 1 otherwise it exits.

 


 

 

Posted Date: 7/10/2012 4:12:37 AM | Location : United States







Related Discussions:- Non-recursive algorithm, Assignment Help, Ask Question on Non-recursive algorithm, Get Answer, Expert's Help, Non-recursive algorithm Discussions

Write discussion on Non-recursive algorithm
Your posts are moderated
Related Questions
Draw trace table and determine output from the following flowchart using following data: Number = 45, -2, 20.5

A town contains a total of 5000 houses. Every house owner has to pay tax based on value of the house. Houses over $200 000 pay 2% of their value in tax, houses over $100 000 pay 1.

Before programming a problem solution those employees a stack, we have to decide how to represent a stack by using the data structures which exist in our programming language. Stac

QUESTION Explain the following data structures: (a) List (b) Stack (c) Queues Note : your explanation should consist of the definition, operations and examples.

Conceptually, the stack abstract data type mimics the information kept into a pile on a desk. Informally, first we consider a material on a desk, where we might keep separate stack

Program will demonstrate deletion of an element from the linear array /* declaration of delete_list function */ voiddelete_list(list *, int); /* definition of delete_list

In-order Traversal  This process when executed iteratively also needs a stack and a Boolean to prevent the implementation from traversing any portion of a tree twice. The gener

algorithm to search a node in linked list

What is a linear array? An array is a way to reference a series of memory locations using the similar name. Every memory location is shown by an array element. An  array elemen

The quick sort algorithm exploit design technique Divide and Conquer