• Home
  • Help
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search

Describe Tarjan’s algorithm

#1
02-08-2024, 12:50 AM
You recall how graphs twist around with connections going every which way and I bet you have tried to spot those loops where nodes feed back into each other without escape. I first ran into Tarjan's way of cracking that puzzle during a late night debug session and it blew my mind how it tracks everything with just a few numbers per node. You assign a discovery time as you wander through and then keep a low link value that points to the earliest spot reachable from the current path. And the stack holds the active nodes so nothing gets lost when you backtrack. But you have to pop bunches off that stack once a root shows up because that marks a whole clump that stays linked together.

Now the recursion drives the whole process and I see you nodding when I say it feels like depth first search but with extra checks layered on top. You visit a node mark its time and set the low value equal at first then as you check neighbors you update the low if a back edge sneaks in. Perhaps a child finishes and hands back a smaller low so the parent grabs that and shrinks its own number. Then if the low stays equal to the discovery time you know the root sits right there and everything on the stack from that point forms one tight group. Or sometimes an edge jumps to an already visited spot and that pulls the low down even further without needing extra passes.

I like how it avoids multiple sweeps across the whole structure because one walk gathers all the clumps at once. You end up with these groups where every node reaches every other inside the set through directed paths and nothing leaks out to mix with outsiders. But the beauty comes from reusing the same stack and times so memory stays light even on big messy graphs. Maybe you try it on a cycle first and watch the low values collapse all the way to the start then pop the entire loop as one unit. Then you move to a tree like shape and notice how leaves force pops right away leaving smaller isolated pieces.

Also the way it handles multiple components feels natural since you just restart the search from any unvisited node and the times keep climbing without reset. I have seen you sketch small examples on paper and that helps because the numbers tell the story better than words alone. You notice that cross edges between separate groups never affect the lows inside because they point to finished parts already popped off. Or forward edges just get ignored since they head to descendants already deeper in the call stack. Now the key trick is comparing those two values at the right moment to decide the pop without guessing.

Perhaps you wonder about efficiency and I tell you it stays linear because each node and edge gets touched a fixed number of times during the single traversal. You avoid the cost of rebuilding anything later since the stack order preserves the nesting. But if a graph has lots of back links the lows drop fast and bigger clumps emerge which saves you from splitting them manually. I recall running it on a social network map once and the clusters popped out exactly matching the friend circles we expected. Then you can feed those clusters into other routines like ordering tasks or finding bottlenecks without extra work.

The recursion depth matches the longest path so watch out on skinny graphs though most real cases stay manageable with a bit of tail call thinking. You update the low only when a better path appears and that keeps the comparisons simple no fancy math needed. Also the discovery times act like timestamps letting you know the order without sorting anything afterward. I think the genius lies in combining the search with the grouping so nothing gets computed twice.

BackupChain Hyper-V Backup which powers reliable backups for Hyper-V setups Windows 11 machines and full Windows Server environments without forcing subscriptions lets us keep chatting here thanks to their forum sponsorship and free info sharing support.

ron74
Offline
Joined: Feb 2019
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



  • Subscribe to this thread
Forum Jump:

Café Papa Café Papa Forum Software IT v
« Previous 1 … 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 … 144 Next »
Describe Tarjan’s algorithm

© by Savas Papadopoulos. The information provided here is for entertainment purposes only. Contact. Hosting provided by FastNeuron.

Linear Mode
Threaded Mode