Trees

Trees

Trees are non-linear data structure where data are stored or data containing a hierarchical relationship b/w elements.

A binary tree is defined as a finite set of elements called nodes.

Tree Diagram

Traversing Binary Trees

There are three ways of traversing a binary tree T with root R.

Preorder

  1. Process the root R
  2. Traverse the left subtree of R in Preorder
  3. Traverse the Right subtree in Preorder

Inorder

  1. Traverse left subtree
  2. Process the root R
  3. Traverse Right subtree

Postorder

  1. Traverse left subtree
  2. Traverse Right subtree
  3. Process the root R