Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

Im an idiot

Revision en1, by nobody_6e72, 2026-08-21 16:40:34

I never realised that during BFS in the queue approach in the following variations -

  1. When I mark visited only when popping from the queue
  2. When I mark visited when I add neighbours to the queue

Both of these methods have a strong different in time complexities. Holy molly.

The first one's time complexity goes to $$$Fibonacci(n)$$$ and the second one is our plan old linear one. I realised this today, am I an idiot or what for never questioning this.

Thanks to random solving of LC200 for this!!

Tags misconception, graphs, bfs

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en8 English nobody_6e72 2026-08-22 10:17:37 0 (published)
en7 English nobody_6e72 2026-08-22 10:17:16 18
en6 English nobody_6e72 2026-08-22 10:16:29 2 Tiny change: 'done.\n\n_Also as s' -> 'done.\n\n_\_Also as s'
en5 English nobody_6e72 2026-08-22 10:16:10 10
en4 English nobody_6e72 2026-08-22 10:15:42 415
en3 English nobody_6e72 2026-08-22 10:13:06 35
en2 English nobody_6e72 2026-08-22 10:12:16 1387
en1 English nobody_6e72 2026-08-21 16:40:34 522 Initial revision (saved to drafts)