tree-traversals

Tree Traversals

Process of visiting each node in a tree exactly once

Untitled

Breadth First

Pre-order Traversal

  1. Print node

  2. Traverse left

  3. Traverse right

Untitled

Use “Data , Left , Right” to mark the nodes to see which path to go

In order Traversal

  1. Traverse left

  2. Print node

  3. Traverse right

    output is in order 1 to 19

    output is in order 1 to 19

Untitled

Use “ Left , Data , Right” to mark the nodes to see which path to go

Post-order Traversal

  1. Traverse left

  2. Traverse right

  3. Print node

    Untitled
    Untitled

Use “ Left , Right , Data ” to mark the nodes to see which path to go


Depth First

Level order traversal

Untitled

Traverse level by level

Untitled

Uses a FIFO Queue


Last updated