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

Tree traversals, There are three kinds of tree traversals, namely, Postorde...

There are three kinds of tree traversals, namely, Postorder , Preorder and Inorder. Preorder traversal: Each of nodes is visited before its children are visited; first the roo

Algorithm to merge two sorted arrays with third array, Q. Write down an alg...

Q. Write down an algorithm to merge the two sorted arrays into the third array. Do  not perform the sort function in the third array.                           Ans: void m

Life science, Define neotaxonomy. Discuss how electron microscopy can help ...

Define neotaxonomy. Discuss how electron microscopy can help in solving a zoological problem faced by taxonomist.

Prims algorithm, how to implement prims algorithm dynamically

how to implement prims algorithm dynamically

FOLDING METHOD, 12345 SOLVE BY USING FOLDING METHOD

12345 SOLVE BY USING FOLDING METHOD

Representation of data structure in memory, Representation of data structur...

Representation of data structure in memory is known as: Abstract data type

Algorithm for the selection sort, Q. Give the algorithm for the selection s...

Q. Give the algorithm for the selection sort. Describe the behaviours of selection sort when the input given is already sorted.

Quicksort and bubble sort algorithms, Task If quicksort is so quick, w...

Task If quicksort is so quick, why bother with anything else? If bubble sort is so bad, why even mention it? For that matter, why are there so many sorting algorithms? Your

Algorithm, Write an algorithm for compound interest.

Write an algorithm for compound interest.

Deletion, sir how can i explain deletion process in a data structure

sir how can i explain deletion process in a data structure

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