I avoided graph problems for 4 months. here's what happened when i finally faced them.

not proud of this but i literally used to filter out graph problems on this site. every time i saw "number of islands" or "course schedule" in a list i'd just... skip it. told myself i'd come back to it. spoiler: i never came back to it.

the avoidance made zero sense in hindsight because the fear was way scarier than the actual topic. i think graphs felt different from arrays or strings because there's no obvious "shape" to them. like, when you're doing a sliding window problem you can almost see the window moving in your head. graphs felt like this foggy mess of nodes going in every direction.

what finally broke the cycle was doing bfs and dfs back to back on the same problem- pacific atlantic water flow. i coded bfs first, got it accepted, then rewrote it with dfs just to see what changed. doing both versions on one problem was way more useful than doing one version on two separate problems. suddenly i could see that bfs and dfs aren't different algorithms, they're just different orderings of the same idea. that reframe changed everything.

after that i spent one week doing nothing but graph problems, roughly 2 a day. didn't care about time complexity at first, just wanted the pattern to feel natural. by day 4 i was recognizing "oh this is just a connected components problem in disguise" within the first read.

the thing nobody tells you about graphs is that 80% of graph problems on here are basically the same 3 ideas- bfs/dfs traversal, topological sort, and union-find. once those three feel automatic, most mediums become almost boring. almost.

if you're currently in the avoidance phase like i was, just do number of islands today. right now. it takes 20 minutes and it's the most useful 20 minutes you'll spend this week.

Comments (1)