Inorder traversal, Data Structure & Algorithms

Assignment Help:

Inorder traversal: The left sub tree is visited, then the node and then right sub-tree.

Algorithm for inorder traversal is following:

  1. traverse left sub-tree
  2. visit node
  3. traverse right sub-tree

2209_Inorder traversal.png

Figure: An expression tree: An inorder traversal

Inorder traversal can be best explained by an expression tree, where the operators are at parent node & operands are at leaf nodes.

Let us assume the above expression tree .The postorder , preorder, and inorder traversal are following:

preorder Traversal :  + * / 4 2 7 - 3 1

 postorder traversal :  4 2 / 7 * 3 1 - +

inorder traversal    :  - ((((4 / 2) * 7) + (3 - 1))

 

There is another tree traversal (certainly, not very common) is called level order, where all the nodes of the similar level are first travelled starting from the root .

271_Inorder traversal1.png

Figure: Tree Traversal: Level Order


Related Discussions:- Inorder traversal

Creation of a circular linked list, Program: Creation of a Circular linked ...

Program: Creation of a Circular linked list ALGORITHM (Insertion of an element into a Circular Linked List) Step 1        Begin Step 2      if the list is empty or new

Determine the greatest common divisor, Determine the greatest common diviso...

Determine the greatest common divisor (GCD) of two integers, m & n. The algorithm for GCD might be defined as follows: While m is greater than zero: If n is greater than m, s

Program for all pairs shortest paths algorithm, Program segment for All pai...

Program segment for All pairs shortest paths algorithm AllPairsShortestPaths(int N, Matrix C, Matrix P, Matrix D) { int i, j, k if i = j then C[i][j] = 0  for ( i =

Define data model, Define data model?  A data model is a collection of ...

Define data model?  A data model is a collection of conceptual tools for explaning data, data relationships, data semantics and consistency constraints.

Explain about greedy technique, Explain about greedy technique The  gre...

Explain about greedy technique The  greedy  method  suggests  constructing  a   solution  to  an  optimization  problem   by  a sequence of steps, every expanding a partially c

Reverse order of elements on a slack, Q. Describe the representations of gr...

Q. Describe the representations of graph. Represent the graph which is given to us using any two methods Ans: The different ways by which we can represent graphs are:

Algorithm to insert a node in between any two nodes, Q. Write down an algor...

Q. Write down an algorithm to insert a node in between any two nodes in a linked list         Ans. Insertion of a the node after the given element of the listis as follows

Array and two-dimensional array, Q. Describe the term array.  How do we rep...

Q. Describe the term array.  How do we represent two-dimensional arrays in memory?  Explain how we calculate the address of an element in a two dimensional array.

Avl tree, Example: (Single rotation into AVL tree, while a new node is inse...

Example: (Single rotation into AVL tree, while a new node is inserted into the AVL tree (LL Rotation)) Figure: LL Rotation The rectangles marked A, B & C are trees

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