Non Recursive Algorithm to Traverse a Binary Tree, Data Structure & Algorithms

Assignment Help:

Q. Write down a non recursive algorithm to traverse a binary tree in order.                   

Ans:

Non - recursive algorithm to traverse a binary tree in inorder is as follows:-

Initially in the beginning   push NULL  onto STACK  and then set  PTR  = ROOT. Then    repeat the steps written below until   NULL is popped from STACK.

i.      Continue down the left -most path rooted at PTR, pushing each node N onto STACK and stopping when a node     N    with no left    child     is   pushed    onto

STACK.

ii.    [Backtracking.] Pop and  process the nodes on

STACK. If the NULL is popped then Exit. If a node N

Having a right child R(N) is processed, set PTR = R(N) (by assigning PTR = RIGHT[PTR] and return to the Step(a)).

 

 


Related Discussions:- Non Recursive Algorithm to Traverse a Binary Tree

Algorithm, Write an algorithm for compound interest.

Write an algorithm for compound interest.

If else, design algorithm and flow chart that computes the absolute differe...

design algorithm and flow chart that computes the absolute difference of two values x and y

Doubly linked list, How does operations like insertion, deletion occur?

How does operations like insertion, deletion occur?

Traversing a graph, two standards ways of traversing a graph in data struc...

two standards ways of traversing a graph in data structure

Matrix stored in memory, Method to measure address of any element of a matr...

Method to measure address of any element of a matrix stored in memory. Let us consider 2 dimensional array a of size m*n further consider that the lower bound for the row index

Depth-First Traversal, With the help of a program and a numerical example e...

With the help of a program and a numerical example explain the Depth First Traversal of a tree.

Data flow diagrams, How to construct a data flow diagram for a college assi...

How to construct a data flow diagram for a college assignment and marking systemA

Write procedure to the insert a node into the linked list, Q. Write a proce...

Q. Write a procedure to the insert a node into the linked list at a particular position and draw the same by taking an example?

Insert an element after an element pointed by some pointer, Consider a link...

Consider a linked list of n elements. What is the time taken to insert an element after an element pointed by some pointer? O (1)

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd