Level order, breadth first search or zig-zag traversal of a binary tree

Traverse the binary tree in breadth first search also known as level order traversal manner.


// Should print  8, 3, 10, 1, 6, 14, 4, 7, 13

Pseudo Algorithm

PSEUDO ALGORITHM (Breadth first search approach)

  1. Create an empty queue q
  2. Enqueue q the root node
  3. Loop while queue is not EMPTY
    1. temp_node = dequeue q
    2. print temp_node’s data
    3. Enqueue temp_node’s children (first left then right children) to q




You may also like...

Leave a Reply

Your email address will not be published.