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

Frequency count, what is frequency count with examble? examble?

what is frequency count with examble? examble?

Explain the different types of traversal on binary tree, Question 1 What i...

Question 1 What is a data structure? Discuss briefly on types of data structures Question 2 Explain the insertion and deletion operation of linked list in detail Qu

Preorder traversal of a binary tree, Preorder traversal of a binary tree ...

Preorder traversal of a binary tree struct NODE { struct NODE *left; int value;     /* can take any data type */ struct NODE *right; };   preorder(struct N

Define tractable and intractable problems, Define tractable and intractable...

Define tractable and intractable problems Problems that can be solved in polynomial time are known as tractable problems, problems that cannot be solved in polynomial time are

Multiqueue, data structure for multiqueue

data structure for multiqueue

Complexity of an algorithm, compare two functions n and 2n for various valu...

compare two functions n and 2n for various values of n. determine when second becomes larger than first

Explain the prim''s minimum spanning tree algorithm, Question 1. Explai...

Question 1. Explain the different types of traversal on binary tree 2. Explain the Prim's minimum spanning tree algorithm 3. Differentiate fixed and variable storage allo

Explain the linked list implementation of stack, Question 1 Explain the fo...

Question 1 Explain the following? Arrays Stack Trees Question 2 Explain the Linked list implementation of stack Question 3 What is a binary tree? Expla

Define linked list ?, Linked lists are among the most common and easiest da...

Linked lists are among the most common and easiest data structures. They may be used to implement various other common abstract data types, including queues, stacks, symbolic expre

Explain time complexity, Time Complexity, Big O notation The amount of ...

Time Complexity, Big O notation The amount of time needed by an algorithm to run to its completion is referred as time complexity. The asymptotic running time of an algorithm i

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