Iterative Algorithm

Design an iterative algorithm to traverse a binary tree represented in two dimensional matrix

Showing Answers 1 - 0 of 0 Answers

A binary tree can be traversed using only one dimensional array.

InOrder_TreeTraversal()
{
prev = null;
current = root;
next = null;

while( current != null )
{
if(prev == current.parent)
{
prev = current;
next = current.left;
}

if(next == null || prev == current.left)
{
print current.value;
prev = current;
next = cuurent.right;
}

if(next == null || prev == current.right)
{
prev = current;
next = cuurent.parent;
}

current = next;
}
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions