2 The following algorithm computes the number of comparisons made when Prim’s algorithm is applied to a complete network on \(n\) vertices ( \(n > 2\) ).
Step 1 Input the value of \(n\)
Step 2 Let \(i = 1\)
Step 3 Let \(j = n - 2\)
Step 4 Let \(k = j\)
Step 5 Let \(i = i + 1\)
Step 6 Let \(j = j - 1\)
Step 7 Let \(k = k + ( i \times j ) + ( i - 1 )\)
Step 8 If \(j > 0\) then go to Step 5
Step 9 Print \(k\)
Step 10 Stop
- Apply the algorithm when \(n = 5\), showing the intermediate values of \(i , j\) and \(k\).
The function \(\mathrm { f } ( n ) = \frac { 1 } { 6 } n ^ { 3 } - \frac { 7 } { 6 } n + 1\) gives the same output as the algorithm.
- Showing your working, check that \(\mathrm { f } ( 5 )\) is the same value as your answer to part (i).
- What does the structure of \(\mathrm { f } ( n )\) tell you about Prim's algorithm?