Seeking suggestions: When to use BFS and DFS while both are applicable
Anonymous User
180

Hi,

I am quite confused on the usage of BFS and DFS.
For some problems (e.g. https://leetcode.com/problems/number-of-islands/), DFS and BFS are both applicable. But still one of them provide better runtime over other in Leetcode.
For this specific question, BFS runs at 10-11 ms while DFS runs at 1-3 ms.

Though there is no specific difference in runtime complexities for both the cases.
Can you please provide some suggestions how we can identify the best algorithm for one problem or more specifically is there any specific difference between those two alogithms (BFS and DFS) due to which we are getting lesser runtime in one than other?

Thanks!

Comments (0)