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

Array implementation of a dequeue, If a Dequeue is implemented via arrays, ...

If a Dequeue is implemented via arrays, then this will suffer with the similar problems which a linear queue had suffered. Program 8 gives the array implementation of Dequeue.

Question, A binary search tree is used to locate the number 43. Which of th...

A binary search tree is used to locate the number 43. Which of the following probe sequences are possible and which are not? Explain. (a) 61 52 14 17 40 43 (b) 2 3 50 40 60 43 (c)

Data structure, Ask question #Minimum 1Mark each of the following statement...

Ask question #Minimum 1Mark each of the following statements as valid or invalid. If a statement is invalid, explain why. a. current ¼ list; b. temp->link->link ¼ NULL; c. trail->l

Properties of a red-black tree, Any binary search tree must contain followi...

Any binary search tree must contain following properties to be called as a red-black tree. 1. Each node of a tree should be either red or black. 2. The root node is always bl

Define graph, A graph is a mathematical structure giving of a set of vertex...

A graph is a mathematical structure giving of a set of vertexes (v1, v2, v3) and a group of edges (e1, e2, e3). An edge is a set of vertexes. The two vertexes are named the edge en

Binary search tree, A binary search tree (BST), which may sometimes also be...

A binary search tree (BST), which may sometimes also be named a sorted or ordered binary tree, is an edge based binary tree data structure which has the following functionalities:

HUFFMAN CODING, Ask question 1. Indicate whether each of the following prop...

Ask question 1. Indicate whether each of the following properties is true for every Huffman code. a. The codewords of the two least frequent symbols have the same length. b. The

Preorder traversal of a binary tree, Preorder traversal of a binary tree ...

Preorder traversal of a binary tree struct NODE { struct NODE *left; int value;     /* can take any data type */ struct NODE *right; };   preorder(struct N

Program, circular queue using c

circular queue using c

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