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
Using the cohen sutherland. Algorithm. Find the visible portion of the line P(40,80) Q(120,30) inside the window is defined as ABCD A(20,20),B(60,20),C(60,40)and D(20,40)

Simplifying Assumptions of wire frame representation Neglect colour - consider Intensity: For now we shall forget about colour and restrict our discussion just to the intensi

Indexed Sequential Files An index is inserted to the sequential file to provide random access. An overflow area required to be maintained to permit insertion in sequence. I

Linked list representations contain great advantages of flexibility on the contiguous representation of data structures. However, they contain few disadvantages also. Data structur

You are given an undirected graph G = (V, E) in which the edge weights are highly restricted. In particular, each edge has a positive integer weight of either {1,2,...,W}, where W

Objectives The purpose of this project is to give you significant exposure to Binary Search Trees (BST), tree traversals, and recursive code. Background An arbitrary BST i

Problem 1. You are asked to store Names of all 100 students of class A in your Learning Centre. Which data type will you use? What is its syntax? Explaining the data typ

The Euclidean algorithm is an algorithm to decide the greatest common divisor of two positive integers. The greatest common divisor of N and M, in short GCD(M,N), is the largest in

Preconditions assertion A precondition is an assertion which should be true at the initiation of an operation. For instance, a square root operation can't accept a negative a

Ans: A procedure to reverse the singly linked list: reverse(struct node **st) { struct node *p, *q, *r; p = *st; q = NULL; while(p != NULL) { r =q;