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 sparse matrix stored in the memory of a computer?

The number of different directed trees with 3 nodes are ?? The number of disimilar directed trees with three nodes are 3

Explain about Franklin Algorithm We mentioned how the number of possible comparisons of polygons grows as the square of the number of polygons in the scene. Many of the hidden-

write a algorithsm in c to perform push and pop operations stastic implementation using array ?

Primitive Data Structure These are the basic structure and are directly operated upon by the machine instructions. These in general have dissimilar representations on different

write an algorithm to sort given numbers in ascending order using bubble sort

Explain about greedy technique The  greedy  method  suggests  constructing  a   solution  to  an  optimization  problem   by  a sequence of steps, every expanding a partially c

A linked list can be of the following types:-  Linear linked list or one way list Doubly linked list or two way list. Circular linked list Header linked list

Typical programming languages such as Pascal, C or Java give primitive data kinds such as integers, boolean, reals values and strings. They give these to be organised into arrays,

Can a Queue be shown by circular linked list with only single pointer pointing to the tail of the queue? Yes a Queue can be shown by a circular linked list with only single p