Steps of pre-order traversal, Data Structure & Algorithms

Pre-order Traversal

The method of doing a pre-order traversal iteratively then has the several steps(suppose that a stack is available to hold pointers to the appropriate nodes):

1. push NULL onto the stack

2. Begin 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: 5/10/2013 2:13:42 AM | Location : United States

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

Write discussion on Steps of pre-order traversal
Your posts are moderated
Related Questions
Write an algorithm for multiplication of two sparse matrices using Linked Lists.

Program: Program segment for insertion of an element into the queue add(int value) { struct queue *new; new = (struct queue*)malloc(sizeof(queue)); new->value = val

Q. Write down the recursive function to count the number of the nodes in the binary tree.    A n s . R ecursive Function to count no. of Nodes in Binary Tree is writt

In this respect depth-first search (DFS) is the exact reverse process: whenever it sends a new node, it immediately continues to extend from it. It sends back to previously explore

Develop a program that accepts the car registration( hint: LEA 43242010)

what happen''s in my computer when i input any passage

Which are the two standard ways of traversing a graph? i. The depth-first traversal   ii. The breadth-first traversal

explain the prims''s algorithm with suitable example?

#What is the pointer

Illustrates the program segment for Quick sort. It uses recursion. Program 1: Quick Sort Quicksort(A,m,n) int A[ ],m,n { int i, j, k; if m { i=m; j=n+1; k