Non-recursive algorithm to traverse a tree in preorder, Data Structure & Algorithms

Assignment Help:

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

The Non- Recursive algorithm for preorder traversal is as follows:

Initially  push NULL onto stack and then set PTR=Root. Repeat the steps until PTR= NULL.

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

2. Processing every node N on the path and pushing every right child if any onto the stack.[The traversing stops when (PTR)=NULL]

3. Backtracking: pop and assign to PTR the top element on stack. If PTR not equal to NULL then return to step 1 or else exit.  

 


Related Discussions:- Non-recursive algorithm to traverse a tree in preorder

Selection sort, how to reduce the number of passes in selection sort

how to reduce the number of passes in selection sort

Order of the matrix, /* The program accepts matrix like input & prints the ...

/* The program accepts matrix like input & prints the 3-tuple representation of it*/ #include void main() { int a[5][5],rows,columns,i,j; printf("enter the order of

What do you mean by hash clash, What do you mean by hash clash? Hashing...

What do you mean by hash clash? Hashing is not perfect. Occasionally, a collision occurs when two different keys hash into the same hash value and are assigned to the same arra

Numerical - algorithm, Q. What is the smallest value of n such that an algo...

Q. What is the smallest value of n such that an algorithm whose running time is 100n2 runs faster than an algorithm whose running time is 2n on the same machine.    A n

Define big omega notation, Define Big Omega notation Big Omega notatio...

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

Darw a flowchart that inputs country someone is visiting, Regis lives in Br...

Regis lives in Brazil and frequently travels to USA, Japan and Europe. He wants to be able to convert Brazilian Reais into US dollars, European euros and Japanese yen. Conversion f

Explain insertion sort, Q. Explain the insertion sort with a proper algorit...

Q. Explain the insertion sort with a proper algorithm. What is the complication of insertion sort in the worst case?

Calculate the k-th power and recursive algorithem, 1. The following is a r...

1. The following is a recursive algorithm to calculate the k -th power of 2. Input k a natural number Output kth power of 2 Algorithem: If k =0then return 1 Else return 2* po

B-TREE and AVL tree diffrance, Explain process of B-TREE and what differen...

Explain process of B-TREE and what difference between AVL Tree Using Algorithms

Stack, how we will make projects on stack in c?

how we will make projects on stack in c?

5/10/2013 2:49:34 AM

Thanks for suggesting me this answer, appreciate your knowledge.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd