Jarník-Prim algorithm
Jarník-Prim algorithm

The Jarník-Prim algorithm (Jarník's algorithm, Prim's algorithm, DJP algorithm) is used to find a minimum/maximum spanning tree of the graph (spanning tree, in which is the sum of its edges weights minimal/maximal). The algorithm was developed in 1930 by Czech mathematician Vojtěch Jarník, in 1957 it was rediscovered by American mathematician Robert Prim. And again in 1959 the algorithm was rediscovered by Dutch computer scientist Edsger Dijkstra.

Description

The algorithm traverses the graph starting at a random node and maintains a list of already discovered nodes with their distance from the already connected (processed) subgraph. In every step the procedure connects a node, which is in the least distance, discovers its neighbours or recalculates their distance, if they had been already discovered and a more favorable edge was found. When all the nodes are connected to the subgraph, the algorithm terminates.

Complexity analysis

The complexity of the Jarník-Prim algorithm is dependent on the implementation of the list. The list itself may be modified at most \\vert E \\vert times, because every discovery of a new edge may add a new node to the list or change a weight of some already discovered node.

If we implement the list using a binary heap, which acts as a priority queue, than its each modification takes O(\\log_{2}(\\vert V \\vert)) steps. Hence the complexity of the Jarník-Prim algorithm is O(\\vert E \\vert  \\log_{2}(\\vert V \\vert)).

Code

/**
 * Jarnik-Prim algorithm
 * Finds the minimal spanning tree of the given graph
 * @graph graph
 * @weight edge weights  
 * @return array of predecessors  
 */ 
node[] jarnikPrimAlgorithm(graph, weight)
    Queue q
    q.addAllVetices(graph.vertices) //add all vertices to the queue
    
    distances = new int[q.size()] //array of distances
    distances[0] = 0 //root
    for i in 1 -> distances.length - 1 do                                 
        distances[i] = +inf //all remaining vertices are in infinite distance
     
    predecessors = new node[q.size()] //array of predecessors
    predecessors[0] = null //the root does not have any predecessor
    
    while !queue.empty() do //while the queue is not empty
        u = queue.extractMin() //return a node in a minimal distance
        for node in descendants(u) do //for all descendants of u
            if queue.contains(node) AND weight(u, node) < d[node] //if we have found some improving path to the descendant
                then predecessors[node] = u //than u is his predecessor
                     d[node] = weight(u, node) //and set a new distance    
    
    return predecessors //return the array of predecessors

Sources

  • KOLÁŘ, Josef. Teoretická informatika. 2. edition. Prague : Česká informatická společnost, 2004. 205 p. ISBN 80-900853-8-5.

SEO od společnosti Digital Pylon


Online casino s algoritmem

České casino online online slot-vegas.cz

Hrajte nejlepší hry jako je GoodGame Empire.





Zajímavé články: Jak najít práci snů? Zvolte kariéru v IT!, Češi mají rádi hrací automaty online, Jak funguje algoritmické obchodování Casino, Online výuka Algoritmus a online marketing mají svá pravidla, Automaty, Matematický vliv, Ratings, Jak fungují algoritmy hazardních her online: více znalostí, více peněz, SYPWAI - nástroj pro vědecký vývoj, Vynikají na globálním trhu: Nejlepší vývojáři softwaru pro online výherní automaty, Jak si vybrat nejlepší české online casino, Proč byste měli hrát online casino VPN revoluce, Kde najdeme algoritmy v každodenním životě?, Čeká vás pracovní pohovor mimo město? Podívejte se, jak dokonale zvládnout včasný příchod, 5 úžasných technologií ze světa hazardních her, Mirror and access to Mostbet, Svou kancelář můžete mít stále po ruce, Jaké výhody má digitalizovaná firma oproti off-line konkurenci?, Jaký systém vybrat pro snadné řízení výroby?, Nahradí umělá inteligence ajťáky?, Důvody, proč používat SnapTik ke stahování videí TikTok, Dokonalý den na pláži: Co si vzít s sebou, aby byl výlet zábavný a bezpečný?, Jak přežít dlouhý let?, Go pay GoodGame Empire, Blockchain, Rozhovor


Doporučujeme

Internet pro vaši firmu na míru

https://www.algoritmy.net