7.03f Worst case complexity: T(n) as function of problem size

7 questions

Sort by: Default | Easiest first | Hardest first
OCR MEI D1 2009 January Q2
8 marks Moderate -0.8
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
  1. 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.
  2. Showing your working, check that \(\mathrm { f } ( 5 )\) is the same value as your answer to part (i).
  3. What does the structure of \(\mathrm { f } ( n )\) tell you about Prim's algorithm?
OCR MEI D1 2012 June Q2
8 marks Moderate -0.3
2 This question concerns the following algorithm which operates on a given function, f. The algorithm finds a point between A and B at which the function has a minimum, with a maximum error of 0.05 .
Step 1Input A
Step 2Input B , where \(\mathrm { B } > \mathrm { A }\)
Step 3Let \(\mathrm { R } = \mathrm { A } + \left( \frac { \sqrt { 5 } - 1 } { 2 } \right) \times ( \mathrm { B } - \mathrm { A } )\)
Step 4Let \(\mathrm { L } = \mathrm { A } + \mathrm { B } - \mathrm { R }\)
Step 5Find \(f ( \mathrm {~L} )\) and \(f ( \mathrm { R } )\)
Step 6If \(\mathrm { f } ( \mathrm { L } ) \leqslant \mathrm { f } ( \mathrm { R } )\) then let \(\mathrm { B } = \mathrm { R }\) and go to Step 8
Step 7If \(\mathrm { f } ( \mathrm { L } ) > \mathrm { f } ( \mathrm { R } )\) then let \(\mathrm { A } = \mathrm { L }\) and go to Step 8
Step 8If \(\mathrm { B } - \mathrm { A } < 0.1\) then go to step 10
Step 9Go to step 3
Step 10Print \(\frac { ( \mathrm { A } + \mathrm { B } ) } { 2 }\) and stop
  1. Working correct to three decimal places, perform two iterations of the algorithm for \(\mathrm { f } ( x ) = 2 x ^ { 2 } - 15 x + 30\), when \(\mathrm { A } = 3\) and \(\mathrm { B } = 4\). Start at Step 1 and stop when you reach Step 8 for the second time.
  2. The \(\left( \frac { \sqrt { 5 } - 1 } { 2 } \right)\) factor in Step 3 ensures that either the new ' \(L\) ' is equal to the old ' \(R\) ', or vice versa. Why is this important?
  3. This algorithm is used when the function is not known explicitly, but where its value can be found for any given input. Give a practical example of where it might be used.
OCR Further Discrete AS 2020 November Q1
10 marks Standard +0.3
1 Algorithm X is given below: STEP 1: \(\quad\) Let \(A = 0\) STEP 2: Input the value of \(B \quad [ B\) must be a positive integer]
STEP 3: \(\quad C = \operatorname { INT } ( B \div 3 )\) STEP 4: \(D = B + 3 C\) STEP 5: \(\quad\) Replace \(A\) with \(( D - A )\) STEP 6: Decrease \(B\) by 1
STEP 7: If \(B > 0\) go to STEP 3
STEP 8: Display the value of \(\operatorname { ABS } ( A )\) and STOP
  1. Trace through algorithm X when the input is \(B = 5\). Only record changes to the values of the variables, \(A , B , C\) and \(D\), using a new column of the table in the Printed Answer Booklet each time one of these variables changes.
  2. Explain carefully how you know that algorithm X is finite for all positive integer values of \(B\).
  3. Explain what it means to say that an algorithm is deterministic. The run-time of algorithm X is \(k \times\) (number of times that STEP 6 is used), for some positive constant \(k\).
  4. Explain, with reference to your answer to part (b), why the order of algorithm X is \(\mathrm { O } ( n )\), where \(n\) is the input value of \(B\). For each input \(B\), algorithm Y achieves the same output as algorithm X , but the run-time of algorithm Y is \(m \times\) (the number of digits in \(B\) ), where \(m\) is a positive constant.
  5. Show that algorithm Y is more efficient than algorithm X .
Edexcel FD1 AS 2018 June Q1
9 marks Moderate -0.5
1. \begin{figure}[h]
\includegraphics[alt={},max width=\textwidth]{3e853c6d-e90e-4a09-b990-1c2c146b54e1-2_1105_1459_463_402} \captionsetup{labelformat=empty} \caption{Figure 1}
\end{figure} Figure 1 represents a network of roads.
The number on each arc represents the time taken, in minutes, to drive along the corresponding road.
    1. Use Dijkstra's algorithm to find the shortest time needed to travel from A to H .
    2. State the quickest route. For a network with \(n\) vertices, Dijkstra's algorithm has order \(n ^ { 2 }\)
  1. If it takes 1.5 seconds to run the algorithm when \(n = 250\), calculate approximately how long it will take, in seconds, to run the algorithm when \(n = 9500\). You should make your method and working clear.
  2. Explain why your answer to part (b) is only an approximation.
Edexcel FD1 2021 June Q6
10 marks Standard +0.3
6. \begin{figure}[h]
\includegraphics[alt={},max width=\textwidth]{43bc1e60-d8b2-4ea5-9652-4603a26c2f78-07_728_1465_248_301} \captionsetup{labelformat=empty} \caption{Figure 4}
\end{figure} In Figure 4 the weights on the arcs represent distances.
    1. Use Dijkstra's algorithm to find the shortest path from A to H .
    2. State the length of the shortest path from A to H . One application of Dijkstra's algorithm has order \(n ^ { 2 }\), where \(n\) is the number of nodes in the network. A computer produces a table of shortest distances between any two different nodes by repeatedly applying Dijkstra's algorithm from each node of the network. It takes the computer 0.082 seconds to produce a table of shortest distances for a network of 10 nodes.
  1. Calculate approximately how long it will take, in seconds, for the computer to produce a table of shortest distances for a network with 200 nodes. You must give a reason for your answer.
  2. Explain why your answer to part (b) can only be an approximation.
Edexcel FD1 2023 June Q3
8 marks Standard +0.3
3. \begin{figure}[h]
\includegraphics[alt={},max width=\textwidth]{6ccce35f-4e62-4b6b-acf6-f9b3e18d4b52-05_862_1460_219_299} \captionsetup{labelformat=empty} \caption{Figure 4}
\end{figure} Figure 4 represents a network with nodes, A, B, C, D, E, F, G, H and J.
The number on each edge gives the length of the corresponding edge.
    1. Use Dijkstra's algorithm to find the shortest path from A to J.
    2. State the length of the shortest path from A to J . One application of Dijkstra's algorithm has order \(n ^ { 2 }\), where \(n\) is the number of nodes in the network. It takes a computer 0.0312 seconds to find the shortest path from a given start node to a given end node in a network of 9 nodes.
  1. Calculate approximately how long it would take, in minutes, for the computer to find the shortest path from a given start node to a given end node for a network of 9000 nodes.
Edexcel FD1 Specimen Q1
4 marks Easy -1.2
  1. A list of \(n\) numbers needs to be sorted into descending order starting at the left-hand end of the list.
    1. Describe how to carry out the first pass of a bubble sort on the numbers in the list.
    Bubble sort is a quadratic order algorithm.
    A computer takes approximately 0.021 seconds to apply a bubble sort to a list of 2000 numbers.
  2. Estimate the time it would take the computer to apply a bubble sort to a list of 50000 numbers. Make your method clear.