the time complexity is the same for both ways.
let grid row length be m, grid col length as n.

cuz bascially it just iterate the grid, cell by cell, one each cell, DFS or BFS at most will visit m*n cells. but for the cells it visited, we marks it so the next visit in the for loop in main function will be terminated immediately.