Y1 - Decision - C3 - Algorithms on Graphs Flashcards
1
Q
3.1-3.2 What do Kruskal and Prim’s algorithms do?
A
They find the minimum spanning tree (MST) of a network
2
Q
3.1 Describe Kruskal’s algorithm
A
- Sort the arcs in ascending order of weight
- Select the arc of least weight to start the tree
- Consider the next arc of least weight:
i) If it would form a cycle, reject it
ii) If it would not form a cycle, add it to the tree (if arcs are of equal weight consider each in turn) - Repeat (3) until all vertices are connected
3
Q
3.2 Describe Prim’s algorithm
A
- Select any vertex to start the tree from (often given to you in the question)
- Choose an arc of least weight connecting to the starting vertex that joins a vertex not currently in the tree (if there are a choice of equal arcs then choose randomly)
- Repeat (2) until all vertices are connected
4
Q
3.3 Describe how you can apply Prim’s algorithm to a distance matrix
A
- Choose any vertex to start the tree
- Cross out the row containing that vertex
- Number the column in the matrix for the chosen vertex
- Ring the lowest remaining entry in the column (if equal, choose randomly)
- The ringed entry becomes the next arc added to the tree
- Repeat 2, 3, 4, & 5 until all rows are deleted
5
Q
3.3 What order is Prim’s algorithm?
A
n^3
6
Q
3.4 What is Dijkstra’s algorithm used for?
A
Dijkstra’s (‘Dike-stra’) algorithm is used to find the shortest path through a network
7
Q
3.4 Describe Dijkstra’s algorithm
A
- Above every vertex there is a vertex label, order of labelling, final value, and working values
- Label the starting vertex with a 1 and a final value of 0
- Record a working value at every vertex that is connected to the vertex chosen
- If this value is smaller than the current working value, cross the old value out
- Look at the working values at all vertices without final labels, select the smallest working value and make it the final label
- Repeat until the destination receives a final label
8
Q
3.4 How do you find the shortest path between 2 points on a network?
A
Work backwards, whichever arc equals the next vertex when you subtract the arc value is the correct path