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

Stacks are often used in evaluation of arithmetic expressions. An arithmetic expression contains operands & operators. Polish notations are evaluated through stacks. Conversions of

Range: A Structured Type in Ruby Ruby has a numerous structured types, comprising arrays, hashes, sets, classes, streams, and ranges. In this section we would only discuss rang

Objectives The purpose of this project is to give you significant exposure to Binary Search Trees (BST), tree traversals, and recursive code. Background An arbitrary BST i

whats the definition of ADT and data type?


What do you understand by structured programming Structured Programming  This term is used for programming design that emphasizes:- (1) Hierarchical design of programmi

Explain about Hidden-surface Hidden-line removal refers to wire-frame diagrams without surface rendering and polygonal surfaces with straight edges. Hidden-surface removal ref

Give an algorithm to find both the maximum and minimum of 380 distinct numbers that uses at most 568 comparisons.

Explain in detail the algorithmic implementation of multiple stacks.