FM - Decision 1 - 3) Algorithms on graphs Flashcards
1
Q
Definition of a minimum spanning tree
A
Spanning tree where the total length of its edges is as small as possible
2
Q
Method to find a minimum spanning tree using Kruskal’s algorithm
A
- Sort all edges into ascending order of weight
- Select any edge of least weight. If it would form a cycle, reject it. (If there are multiple valid edges of equal weight, choose whichever)
- Repeat until all vertices are connected
3
Q
Method to find a minimum spanning tree using Prim’s algorithm
A
- Choose any vertex to start the tree
- Select the arc of least weight that joins a vertex already in the tree to one not yet in the tree. (If there are multiple valid edges of equal weight, choose whichever)
- Repeat until all vertices are connected
4
Q
Method to find a minimum spanning tree using the distance matrix form of Prim’s algorithm
A
- Choose any vertex to start the tree
- Delete the row in the matrix of the chosen vertex
- Number the column in the matrix of the chosen vertex
- Circle lowest undeleted entry in the numbered columns. (If there are multiple valid entries, choose whichever)
- The circled entry is the next edge to be added to the tree
- Repeat until all rows have been deleted
5
Q
Method to find the shortest path between two vertices in a network using Dijkstra’s algorithm
A
- Each vertex has an array of boxes → TL: vertex (letter) | TM: order of labelling (number order) | TR: final label (lowest working value) | B: working values
- Label starting vertex with its letter, 1 order of labelling, and 0 final label
- Record a working value (final label + weight of edge) at every non-completed vertex that it directly connects to
- Whenever a working value is added, put brackets around the higher number
- Choose the next vertex that has the lowest working value and label it fully. (If multiple vertices have the same smallest working value, choose whichever)
- Repeat until destination vertex recieves its final label
- To find the shortest path, trace back from destination to starting vertex → the correct edges are the ones where the weight of the arc = final label of later arc - final label of earlier arc. Then flip the order to go from starting to destination vertex