Prims algorithm siv rau dab tsi?
Prims algorithm siv rau dab tsi?

Video: Prims algorithm siv rau dab tsi?

Video: Prims algorithm siv rau dab tsi?
Video: khwv nyiaj tsis nce tes yog vim li cas 2024, Kaum ib hlis
Anonim

Hauv computer science, Prim cov (tseem hu ua Jarník's) algorithm yog tus siab hlob algorithm uas nrhiav qhov tsawg kawg nkaus spanning ntoo rau ib tug hnyav undirected graph. Qhov no txhais tau tias nws pom ib qho kev sib txuas ntawm cov npoo uas tsim ib tsob ntoo uas suav nrog txhua qhov vertex, qhov twg tag nrho qhov hnyav ntawm tag nrho cov npoo hauv tsob ntoo raug txo qis.

Tsis tas li ntawd, Kruskal's algorithm siv rau dab tsi?

Kruskal's algorithm siv txoj kev greedy mus nrhiav ib tug yam tsawg kawg nkaus spanning ntoo. Kruskal lub algorithm treatsevery node raws li ib tsob ntoo ywj pheej thiab txuas ib qho nrog lwm tus tsuas yog tias nws muaj tus nqi qis tshaj piv rau tag nrho lwm cov kev xaiv muaj.

Thib ob, Dijkstra's algorithm ua dab tsi? Dijkstra's algorithm tuaj yeem siv los txiav txim siab txoj kev luv tshaj plaws los ntawm ib qho ntawm cov duab rau txhua qhov ntawm lwm qhov hauv tib daim duab cov ntaub ntawv, yog tias cov nodes tuaj yeem ncav cuag los ntawm qhov pib ntawm qhov pib. Dijkstra's algorithm siv tau los nrhiav txoj kev luv tshaj plaws.

Qhov thib ob, qhov twg yog qhov zoo dua Prims thiab Kruskal algorithm?

Kruskal's Algorithm : ua zoo dua intypical xwm txheej (sparse graphs) vim nws siv cov ntaub ntawv yooj yim dua. Prim's Algorithm : Yog ho ceev inthe txwv thaum koj twb tau txais ib tug tiag tiag tuab teeb nrog ntau ntau edgesthan vertices.

Lub sij hawm nyuaj ntawm Prims algorithm yog dab tsi?

Yog li nws siv ib qho array ntawm tus lej los txhais asub-graph ntawm ib daim duab. Cov lub sij hawm complexity yog O(VlogV + ElogV) = O(ElogV), ua nws tib yam li Kruskal's algorithm . Txawm li cas los xij, Prim lub algorithm tuaj yeem txhim kho Fibonacci Heaps (cf Cormen) rau O (E + logV).

Pom zoo: