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

Each data record contains a fixed place in a relative file. Each record ought to have associated with it in integer key value which will help identify this slot. Therefore, this ke

Determine about the unreachable code assertion An unreachable code assertion is an assertion that is placed at a point in a program that shouldn't be executed under any circum

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

A representation of an array structure is a mapping of the (abstract) array with elements of type T onto the store which is an array with elements of type BYTE. The array could be

Q. What do you understand by the term Hashing?  How do the collisions occur during hashing?  Explain the different techniques or methods for resolving the collision.

need an expert to help me with the assignment

Program gives the program segment by using arrays for the insertion of an element to a queue into the multiqueue. Program: Program segment for the insertion of any element to t

A stack is a last in, first out (LIFO) abstract data type and sequential data structure. A stack may have any abstract data type as a component, but is characterized by two fundame

A shop sells books, maps and magazines. Every item is identified by a unique 4 - digit code. All books have a code starting with a 1, all maps have a code which starts with a 2 and