Non-recursive algorithm, Data Structure & Algorithms


QWrite down the non-recursive algorithm to traverse a tree in preorder.

Ans:

The Non- Recursive algorithm for preorder traversal is written below: Initially in the begnining

push NULL onto stack and then set PTR=Root. Keep on repeating the following steps until PTR= NULL.

1. Preorder down the left most paths routed at the PTR.

2. Processing each node N on the path and pushing each right child if there is onto the stack.[The traversing will stop when (PTR)=NULL]

3. Backtracking: pop and assign to PTR the top element on stack. If PTR is not equal to NULL then return to step 1 otherwise it exits.

 


 

 

Posted Date: 7/10/2012 4:12:37 AM | Location : United States







Related Discussions:- Non-recursive algorithm, Assignment Help, Ask Question on Non-recursive algorithm, Get Answer, Expert's Help, Non-recursive algorithm Discussions

Write discussion on Non-recursive algorithm
Your posts are moderated
Related Questions
Q. Draw a B-tree of order 3 for the sequence of keys written below: 2, 4, 9, 8, 7, 6, 3, 1, 5, 10

Problem 1. Explain about the doubly linked list with neat diagram. Diagram Explaining doubly linked list 2. Explain what are the criteria to be used in evaluatin

Data Structure and Methods: Build an array structure to accomodate at least 10 elements. Provide routines for the following: An initializer. A routine to populate (

extra key inserted at end of array is called

Representation of Linked list in Memory:- Each node has an info part and a pointer to the next node also known as link. The number of pointers is two in case of doubly linked

The most common way to insert nodes to a general tree is to first discover the desired parent of the node you desire to insert, and then insert the node to the parent's child list.

perform the following length operation LENGTH("welcome to ICA")=

Adjacency list representation An Adjacency list representation of Graph G = {V, E} contains an array of adjacency lists mentioned by adj of V list. For each of the vertex u?V,

Q. Describe what do you understand by the term array? How does an array vary from an ordinary variable? How are the arrays represented in the specific memory?

A graph G might be defined as a finite set V of vertices & a set E of edges (pair of connected vertices). The notation utilized is as follows: Graph G = (V, E) Consider the g