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
Define Big Omega notation Big Omega notation (?) : The lower bound for the function 'f' is given by the big omega notation (?). Considering 'g' to be a function from the non-n

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

How will you represent a max-heap sequentially? Max heap, also known as the descending heap, of size n is an almost complete binary tree of n nodes such that the content of eve


Q. Write down an algorithm to test whether a Binary Tree is a Binary Search Tree.              A n s . The algorithm to check whether a Binary tree is as Binary Search

Approximating smooth surfaces with Polygon nets Networks of polygons are used to represent smooth surfaces. They are, of course, only an approximation to the true surface, but

Optimal solution to the problem given below. Obtain the initial solution by VAM Ware houses Stores Availibility I II III IV A 5 1 3 3 34 B 3 3 5 4 15 C 6 4 4 3 12 D 4 –1 4 2 19 Re

A Binary Search Tree is binary tree which is either empty or a node having a key value, left child & right child. By analyzing the above definition, we notice that BST comes int

Define the term counting - Pseudocode Counting in 1s is quite simple; use of statement count = count + 1 would enable counting to be done (for example in controlling a repeat