2. BREATH FIRST TRAVERSAL:
Breadth-first search (BFS) is an algorithm for
traversing or searching tree or graph data structures.
TREE TRAVERSAL: It is the process of visiting each node
in the tree exactly once in same order.
reading or processing data in the node.
Based on visiting the node, the tree traversal is broadly
classified into 2 types:
* BREADTH FIRST TRAVERSAL
* DEPTH FIRST TRAVERSAL
In breadth first traversal the node is started from the tree
node and moves down to each level.
3. EXAMPLE-1:
F
D J
B E G K
A C I
H
L-0
L-1
L-2
L-3
L-4
LEVEL ORDER: F,D,J,B,E,G,K,A,C,I,H
6. STEPS:
1. Start by putting any one of the graph's vertices at the
back of a queue.
2. Take the front item of the queue and add it to the
visited list.
3. Create a list of that vertex's adjacent nodes. Add the
ones which aren't in the visited list to the back of the
queue.
4. Keep repeating steps 2 and 3 until the queue is empty.