Tree Traversal

 

Tree Traversal

Handwritten Notes- Click Here

A tree is a non-linear data structure in which elements are arranged in a hierarchical structure.

Tree Traversal is the process of visiting each node of a tree exactly once in a particular order.

The main types of tree traversal are:

  1. Preorder Traversal (Root → Left → Right)
  2. Inorder Traversal (Left → Root → Right)
  3. Postorder Traversal (Left → Right → Root)
Preorder Traversal :

In Preorder Traversal, the root node is visited first, followed by the left subtree and then the right subtree.

Example

        A
       / \
      B   C
     / \
    D   E

The Preorder Traversal is: A → B → D → E → C


Inorder Traversal:

In Inorder Traversal, the left subtree is visited first, followed by the root node and then the right subtree.

Example

        A
       / \
      B   C
     / \
    D   E

The Inorder Traversal is: D → B → E → A → C


Postorder Traversal:

In Postorder Traversal, the left subtree is visited first, followed by the right subtree, and the root node is visited last.

Example

        A
       / \
      B   C
     / \
    D   E

The Postorder Traversal is: D → E → B → C → A







Comments

Popular posts from this blog

Entity-Relationship(ER) Model

Queue ADT

Normalization in DBMS,(1NF,2NF,3NF,BCNF,4NF,5NF)