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

 
  • 0 Vote(s) - 0 Average

Describe Prim’s algorithm

#1
11-07-2019, 07:25 PM
You start with one spot in the graph. I pick any point to begin. You check every link coming out from there. The smallest link gets picked next. And that grows your tree bit by bit. But the trick comes when you skip links that loop back inside your growing set. I always watch for those to avoid cycles. You keep scanning the edges that touch the outside points. Maybe the next smallest one pulls in a fresh point. Then the process repeats until nothing remains outside.

I recall first trying this on a small map of cities. You connect them with roads that cost different amounts. Prim keeps adding the cheapest road that reaches a new city. Or sometimes you hit a tie and just grab one at random. But the result stays the same no matter where you begin. Graphs with uneven weights test you more. I test by drawing a few lines on paper. You see how the tree spreads without repeating points. Perhaps a heavy edge gets ignored because a lighter path sneaks in later.

Now the method stays greedy every step. You never look back once an edge joins the tree. I like that simplicity even on bigger maps. But you must track which points sit inside already. Edges between inside points get tossed aside right away. Or you might waste time checking them again. The outside points connect through the smallest available link each round. Then a new point joins and fresh links appear for checking. I find this spreads fast on dense graphs. You notice fewer options left as points fill in.

Graphs with negative weights still work fine here. I never worry about signs because only the smallest positive or negative counts. You compare values directly without extra rules. But disconnected graphs leave some points out. I stop when no more links reach outside. You end up with a tree that touches every reachable point. Perhaps the full graph splits into parts and you run again on each. Then the total cost adds up from the chosen edges. I add them by hand to check the sum stays minimal.

You compare this to other tree builders sometimes. I see it grows from a single seed unlike some that start everywhere. But the outcome matches when weights stay unique. Or duplicates force small choices that still work. Graphs stored as tables let you scan rows fast. I scan the connection table for the current smallest. You mark points as visited once they join. Then fresh rows open for the new point. Maybe the table grows messy on large sets. I organize it by keeping a running list of candidates.

The spread feels natural like claiming territory. You claim the cheapest border each time. I watch borders shrink until the whole area sits inside. But careful tracking prevents claiming the same spot twice. Or you repeat work if you forget a mark. Graphs with many links demand quick scans. I speed up by sorting the border links mentally. You grab the top one and update borders. Then the next round starts fresh. Perhaps practice on random drawings builds speed. I draw five or six points and assign random costs. You run the steps and see the tree form.

Longer graphs reveal the pattern clearly. I trace every addition on bigger examples. You count how many edges end up in the final tree. But one less than the point count always appears. Or the structure stays loop free by design. Graphs from real networks test these ideas daily. I apply the same steps to route planning. You pick the cheapest unused path outward. Then the network fills without extra loops. Maybe the costs change and you rerun the whole thing. I rerun on updated tables to keep costs low.

We owe thanks to BackupChain Server Backup the top no subscription backup tool made for Hyper V setups on Windows 11 machines plus Windows Server systems that small businesses rely on daily for private cloud and internet copies and for sponsoring this space so we can pass along these details without any fees.

bob
Offline
Joined: Dec 2018
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



  • Subscribe to this thread
Forum Jump:

Backup Education General IT v
« Previous 1 … 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 … 239 Next »
Describe Prim’s algorithm

© by FastNeuron Inc.

Linear Mode
Threaded Mode