D1, C3 - Algorithm's on Graphs Flashcards

1
Q

What is a minimum spanning tree

A

A spanning tree of minimum weight

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the steps of Kruskal’s algorithm

A

1) List the edges in ascending weight
2) Start with the edge with least weight to start the graph
3) Look at the edge with the next lowest weight. Do NOT use if edge forms a cycle. Add it to tree if doesn’t form a cycle
4) Repeat until all vertices are connected

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What should you do in Kruskal’s algorithm if there are more than once choice

A

Look at each choice in turn

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Prim’s algorithm

A

1) Start at any vertex
2) Choose the edge with the lowest weight to join a vertex not yet in the tree
3) Repeat until all vertices are in the tree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the differences between Kruskal’s and Prim’s algorithm

A

Kruskal’s jumps around and starts at the lowest weighted edge
Prim’s grows and starts at any vertex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you apply Prim’s algorithm to a distance matrix

A

1) Choose any starting vertex
2) Delete this row
3) Number this column (1, 2, …)
4) Circle the lowest undeleted number (in any numbered column)
5) Repeat steps 2-4 with the circle number and repeat until all rows have been deleted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If you have n values in row A (e.g. 6) and need to find the lowest number, how many comparisons are required to find the smallest / largest value

A

n - 1
e.g. 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How many comparisons are needed for an n * n distance matrix

A

(n-1) values –> (n-1)-1 comparisons
2(n-2) values –> 2(n-2)-1
3(n-3) values –> 3(n-3)-1

(n-1)(n-(n-1) values –> (n-1)(n-(n-1))-1
Answer: (n^3 - 7n + 6) / 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

For an n * n matrix you need to do (n^3 - 7n + 6) / 6 comparisons, what is the order of this implementation in terms of the number of vertices, n

A

Order is n^3 (greater power)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does Dijkstra’s algorithm do

A

Allows us to find shortest path through a network

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What goes in each of the boxes for Dijkstra’s algorithm (left, middle, right, bottom)

A

Left- vertex label
Middle- order of labelling
Right- final label (value)
Bottom (working values)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What working value should you use for Dijkstra’s algorithm

A

The smallest one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you perform Dijkstra’s algorithm

A

1) Label the start vertex (order of labelling 1, final label 0)
2) Look at the vertices directly connected to the last vertex, add the weight of these vertices and write down this working value(s)
3) Select the vertex with the smallest working value and make this the final label, and add the order of labelling (2,3,4,…)
4) Repeat steps 2-4
5) Repeat until the end vertex has a final label

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does Floyd’s algorithm do

A

Finds the shortest distance between any two vertices in a network

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you perform Floyd’s algorithm

A

1) Complete a distance table and a route table for the network
2) Make a copy of the first row and column (A) of the distance table (and the dashes -) and highlight this row/column
3) Look at the unshaded part of the table and compare the row / column total with the original distance table
3a) If the ‘copy table’ total < original table, change distance table value and change route table letter
3b) If the ‘copy table’ total >= original table, copy over distance / route from original table
4) Copy the ‘copy table’ and highlight the next row / column (B) (this is one iteration)
5) Repeat from steps 3-4 until all rows / columns are complete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What value goes in the original distance table for Floyd’s algorithm if there is no direct route between the vertices

A

Infinity

17
Q

What letters go in the original route table for Floyd’s algorithm

A

The letter of the top header (column header) fills the whole column vertically

18
Q

What can the final route table of Floyd’s algorithm tell you

A

Which vertices you need to visit for the shortest route

19
Q

What can the final distance table of Floyd’s algorithm tell you

A

The length of the shortest route