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
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;

Determination of Time Complexity The RAM Model The random access model (RAM) of computation was devised through John von Neumann to study algorithms. In computer science,

Ask queConsider the following functional dependencies: Applicant_ID -> Applicant_Name Applicant_ID -> Applicant_Address Position_ID -> Positoin_Title Position_ID -> Date_Position_O

Q. Construct a binary tree whose nodes in inorder and preorder are written as follows: Inorder : 10, 15, 17, 18, 20, 25, 30, 35, 38, 40, 50 Preorder: 20, 15, 10

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

Ans. An algorithm for the quick sort is as follows: void quicksort ( int a[ ], int lower, int upper ) { int i ; if ( upper > lower ) { i = split ( a, lower, up

what is frequency count with examble? examble?

how to implement multiple stack using single dimension array in c


Write down the algorithm of quick sort. An algorithm for quick sort: void quicksort ( int a[ ], int lower, int upper ) {  int i ;  if ( upper > lower ) {   i = split ( a,