![]() |
To understand this let’s take a binary tree ![]() Binary tree If we conduct BFS in this tree:
![]() Level-0
![]() Level-1
![]() Level-2
![]() Level-3 But in the case of DFS in this tree, you’ll never have more than 4 nodes in memory ![]() Depth-first search The difference in peak memory consumption between DFS and BFS:
So, we can conclude that the maximum space used by BFS or DFS is based on the structure of the tree. There can be cases when DFS takes less space than BFS and the opposite can also happen. |
Reffered: https://www.geeksforgeeks.org
Data Structures |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |