Algorithm for pre-order traversal, Data Structure & Algorithms

Hear is given a set of input representing the nodes of a binary tree, write a non recursive algorithm that must be able to give the output in three traversal orders. Write down an algorithm for checking validity of the input, i.e., the program must know if the input given is duplicated, disjoint and has a loop.                                                                                                             

The Pre-order Traversal

The process of doing a pre-order traversal iteratively then has the following steps (assuming that a stack is available to hold pointers to the proper nodes):

1. push NULL onto the stack

2. start at the root and begin execution

3. write the information in the node

4. if the pointer to the right is not NULL push

the pointer onto the stack

5. if the pointer to the left is not NULL move the pointer to the node on the left

6. if the pointer to the left is NULL pop the stack

7. repeat steps 3 to 7 until no nodes remain

Posted Date: 7/9/2012 10:08:36 PM | Location : United States







Related Discussions:- Algorithm for pre-order traversal, Assignment Help, Ask Question on Algorithm for pre-order traversal, Get Answer, Expert's Help, Algorithm for pre-order traversal Discussions

Write discussion on Algorithm for pre-order traversal
Your posts are moderated
Related Questions
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


a. Explain the sum of subset problem. Apply backtracking to solve the following instance of sum of subset problem: w= (3, 4, 5, 6} and d = 13. Briefly define the method using a sta

Run time complexity of an algorithm is depend on

In order to get the contents of a Binary search tree in ascending order, one has to traverse it in In-order

Write an algorithm using pseudocode which takes temperatures input over a 100 day period (once per day) and output the number of days when the temperature was below 20C and the num

A tree is a non-empty set one component of which is designated the root of the tree while the remaining components are partitioned into non-empty groups each of which is a subtree

padovan string

how multiple stacks can be implemented using one dimensional array

Binary Search Tree let three types of traversals by its nodes. They are: Pre Order Traversal In Order Traversal Post Order Traversal In Pre Order Traversal, we ca