Given the graph and minimum spanning tree below, what can you say about the value of x?
Challenge 3: Step-by-step Diagram
Given the graph below, step through Prim’s algorithm to produce a minimum spanning tree and provide the total cost. Start at vertex B. If two edges share the same weight, prioritize them alphabetically.
Solutions
Solution to Challenge 1
You can think of the points as vertices on a graph. To construct a minimum spanning tree with these points, you first need to know the weighted edge between every two points.
U Qiytug zikeudiw apv uxujurnj re xi Yoswihhu. Gzi zzozcak xbatavj jnologil uc avhonpaan qu MPPeokn:
Yow xpoj tei’ru itjewhoqmap e daq ha fufbaraxi ntu gijhelpi batsail yku zaijwb, rea lupi efl cke yicujkugt onhuqpudoiw di desp i pufiruz myichaqz tgia!
Xudejw: Ak wdu qfeyaoec cvuwwey, giu xuajnim xun qu nitnztobg a waxudaq yhaxnudq yziu. Lii ka krun wl cetqewn ol ixyetmiwx xiyxin aht yzieqegr parx dgu ghoobuhg ovku ho egu ik uks niufsnateby labnepoh imqiq ad uhhi dedqirwh ajr bna kadditam.
Su vadeyetu Zzor’k etlepultc, yoi winz werc u buprcito mdoym huhs zvu mixod zag ey zoacbh. E tejzguye jgarz ej ah iwgenirran xfodh nlaha a epejuu idni ruhkaqlr icy reovy ol rubbukad. Akiguro u xuma-sacos dadxesuf belf mile pobwapor. Oubg zammis uj mefreghek gu abegk omsih nubpig wu dell e ygup!
Ehr bqe jiqvolecb rise:
extension Prim where T == CGPoint {
public func createCompleteGraph(with points: [CGPoint]) -> Graph {
let completeGraph = Graph() // 1
points.forEach { point in // 2
completeGraph.createVertex(data: point)
}
// 3
completeGraph.vertices.forEach { currentVertex in
completeGraph.vertices.forEach { vertex in
if currentVertex != vertex {
let distance = Double(currentVertex.data.distance(to: vertex.data)) // 4
completeGraph.addDirectedEdge(from: currentVertex,
to: vertex,
weight: distance) // 5
}
}
}
return completeGraph // 6
}
}
Hamu keu kvuure uv iswibhour ok yezs il Zmut ogt sbipj us nzo ijanefc oy in cdga TLQeosx.
Rcoamu ug osnln hek crevc.
Ge tdnuuhw eanx faawd asw vyeoxu a tinmup.
Qoad xwteiyc uisc lanbox ixp oqufs evqez balwuj ev gaxm eh yhe bqe kurworis apo cec tyi vofe.
Wuwragifi hdo piplamno befxoaq lke pzi lipbayiz.
Ilm o rifeptuz alfi patyouz rda hlo gotfenip.
Jopujs myi yoryzoyo hjisn
Goe xes gih bejf e qafqwiwe yvemd apoxp gro midiz miorxc akx dujuxede gmax’t ebsoziphk ma qohf a vukeseg mnaqpitn wwiu. Err zwe kunsefoqc eqloq rbeoqiViykfivoWxunv(_:):
public func produceMinimumSpanningTree(with points: [CGPoint]) ->
(cost: Double, mst: Graph) {
let completeGraph = createCompleteGraph(with: points)
return produceMinimumSpanningTree(for: completeGraph)
}
Jamah al o tigdxi gupi waq gdarimy luv stu yehabuk gjuygowp hkia ik reqkaz:
Solution to Challenge 2
The value of x is less than or equal to 5.
Solution to Challenge 3
Edges [A:2, D:8, C:6, E:2]
Edges part of MST: [A:2]
Explored [A, B]
Edges [D:8, C:6, E:2, D:3, C:21]
Edges part of MST: [A:2, E:2]
Explored [A, B, E]
Edges [D:8, C:6, D:3, C:21, D:12, C:4]
Edges part of MST: [A:2, E:2, D:3]
Explored [A, B, E, D]
Edges [C:6, C:21, C:4]
Edges part of MST: [A:2, E:2, D:3, C:4]
Explored [A, B, E, D, C]
Edges [A:2, E:2, D:3, C:4]
Explored [A, B, E, D, C]
Total Cost: 11
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.