While Searching A Node in Tree Data Structure, we can take Two Approaches or options:
- Breath First Search (BFS)
- Depth First Search (DFS)
now, let's talk about these
Breath First Search (BFS)
If are going to the Root then to the all Parent Nodes (Classes) first. That means you are covering the Parent Nodes at first and then those Parent Nodes's Child Nodes, then it's called the BFS (Breath First Search). That's why you are covering the Width or Breath first :)
Look at the Image below. See the order 1, 2, 3, 4, 5, 6, 7 .... :)
And if are going to the Root then to the Deep or going all the way down first. That means you are covering the left side deeply and going to the right side deeply.
So, that's called the DFS (Deep First Search).
Look at the Image below. See the order 1, 2, 3, 4, 5, 6, 7... B)
0 Comments