Main Page | See live article | Alphabetical index

Backward inorder traversal

In computer science, backward inorder traversal is used in data structures, and specifically, trees and binary trees.

Programs that utilize tree structures need to process nodes in a tree (represented as circles in below diagram). Nodes contain information about an object. For now, let's assume each node contains a letter. The arrows indicate a link between nodes.

Backward InOrder Traversal is a type of tree traversal algorithm. Backward Inorder is similar to InOrder, except that the right subtree is processed first.

Steps to Backward Inorder Traversal

Given a non-empty tree,

  1. Process the nodes in the right subtree with a recursive call
  2. Process the root
  3. Process the nodes in the left subtree with a recursive call

Given a binary tree PY:

The order would go F,C,A,E,G,B,D

int backinorder_print(const binary_tree_nodes* ptr)
// ptr is a pointer to a node in a binary tree OR null
// meaning empty tree.
   if (ptr != NULL)
       backinorder_print( ptr->right() );
       std::cout << ptr->data() << std::endl;
       backorder_print( ptr->left() );
   return 0;

Pre-order traversal, post-order traversal, inorder traversal