Difference in running time of recursive dfs and itrative dfs

Правка en1, от mansisinha16, 2020-07-24 21:44:45

Hi, I have just started with learning graphs and was doing a question which involved basic dfs. While doing it, I was getting TLE when I was using iterative dfs and when I only changed the dfs from iterative to recursive, the solution got accepted. Since the time complexity of both the methods are same, the only reason I could think of is the time taken to push and pop in the stack, but I didn't think the difference would be this huge. These are the links: Problem: https://codeforces.net/contest/771/problem/A iterative solution: https://codeforces.net/contest/771/submission/87812642 recursive solution: https://codeforces.net/contest/771/submission/87812583

I am baffled by the difference in the runtime of the 2 solutions. If anyone knows a reason for this, please help me :)

Теги #dfs and similar, #dfs

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский mansisinha16 2020-07-24 21:47:36 10
en2 Английский mansisinha16 2020-07-24 21:45:09 1
en1 Английский mansisinha16 2020-07-24 21:44:45 852 Initial revision (published)