Process of in-order traversal, Data Structure & Algorithms

Assignment Help:

In-order Traversal

 This process when executed iteratively also needs a stack and a Boolean to prevent the implementation from traversing any portion of a tree twice. The general process of in-order traversal follows the following steps:  

1.  push a NULL onto the stack.

2.  Starting with the root, proceed down the left side of the tree. As long as there is another left node following the present node, push the pointer to the current node onto the stack and move to the left node which follows it.

3.  When there are no more left nodes following the present node, process the current node.

4.  Check to see if the last left node has a right node (it obviously doesn't have a left node).

5.  If there is a right node then there is subtree to the right. This should be processed in following steps 2 to 4.

6.  If there is no right node then pop the last node from the stack (back up one node). Process this node and as this node has a left subtree that has already been processed, move to the right of the node and start looking for a left and right subtree again.  

 


Related Discussions:- Process of in-order traversal

Whether the infix expression has balanced parenthesis or not, Using stacks,...

Using stacks, write an algorithm to determine whether the infix expression has balanced parenthesis or not Algorithm parseparens This algorithm reads a source program and

Abstract data types, Abstract Data Types :- A useful tool for specifying th...

Abstract Data Types :- A useful tool for specifying the logical properties of a data type is the abstract data type or ADT. The term "abstract data type" refers to the basic mathem

Addressing modes, Compare zero-address, one-address, two-address, and three...

Compare zero-address, one-address, two-address, and three-address machines by writing programs to compute: Y = (A – B X C) / (D + E X F) for each of the four machines. The inst

Singly linked list , The two pointers per number of a doubly linked list pr...

The two pointers per number of a doubly linked list prepare programming quite easy. Singly linked lists as like the lean sisters of doubly linked lists. We need SItem to consider t

Binry trees, Build a class ?Node?. It should have a ?value? that it stores ...

Build a class ?Node?. It should have a ?value? that it stores and also links to its parent and children (if they exist). Build getters and setters for it (e.g. parent node, child n

Infix expression into the postfix expression, Q. Convert the given infix ex...

Q. Convert the given infix expression into the postfix expression (also Show the steps) A ∗ (B + D)/ E - F(G + H / k ) Ans. Steps showing Infix to Post fix

The time and space complexities of an algorihm, Relation between the time a...

Relation between the time and space complexities of an algorithm The examining of algorithm focuses on time complexity and space complexity. As compared to time analysis, the a

The quick sort algorithm exploit design technique, The quick sort algorithm...

The quick sort algorithm exploit design technique Divide and Conquer

What is quick sort, What is quick sort? Quick sort is a sorting algorit...

What is quick sort? Quick sort is a sorting algorithm that uses the idea if split and conquer. This algorithm chooses an element called as pivot element; search its position in

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