Im an idiot

Правка en1, от 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!!

Теги misconception, graphs, bfs

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en8 Английский nobody_6e72 2026-08-22 10:17:37 0 (published)
en7 Английский nobody_6e72 2026-08-22 10:17:16 18
en6 Английский nobody_6e72 2026-08-22 10:16:29 2 Tiny change: 'done.\n\n_Also as s' -> 'done.\n\n_\_Also as s'
en5 Английский nobody_6e72 2026-08-22 10:16:10 10
en4 Английский nobody_6e72 2026-08-22 10:15:42 415
en3 Английский nobody_6e72 2026-08-22 10:13:06 35
en2 Английский nobody_6e72 2026-08-22 10:12:16 1387
en1 Английский nobody_6e72 2026-08-21 16:40:34 522 Initial revision (saved to drafts)