// Numbas version: exam_results_page_options {"name": "Find the shortest path", "extensions": [], "custom_part_types": [], "resources": [["question-resources/network2_P9Gdj38.svg", "/srv/numbas/media/question-resources/network2_P9Gdj38.svg"]], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Find the shortest path", "tags": [], "metadata": {"description": "

Students are shown a graph with 6 vertices and asked to find the length of the shortest path from A to a random vertex.

\n

There is only one graph, but all of the weights are randomised.

\n

They can find the length any way they wish. In the advice, the steps of Dijkstra's algorithm used in solving this problem are displayed. It is not a complete worked solution but it should be sufficient to figure out the shortest path used to reach each vertex.

", "licence": "All rights reserved"}, "statement": "

Consider the following network:

\n

", "advice": "

You can either work out the shortest path by looking at the graph and figuring it out, or by using Dijkstra's algorithm.

\n

The length of the shortest path is calculated by adding up the weights along the shortest path.

\n

\n

The computer used Dijkstra's algorithm to find a shortest path.

\n

Here are the shortest distances from A to each vertex that it calculated in each step of the algorithm. You can use this to help you find the shortest path.

\n

A blank entry means that the algorithm has not yet added that vertex to the shortest path tree.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Step NoABCDEF
10{if(distarray[0][1]=99,\"\",distarray[0][1])}{if(distarray[0][2]=99,\"\",distarray[0][2])}{if(distarray[0][3]=99,\"\",distarray[0][3])}{if(distarray[0][4]=99,\"\",distarray[0][4])}{if(distarray[0][5]=99,\"\",distarray[0][5])}
20{if(distarray[1][1]=99,\"\",distarray[1][1])}{if(distarray[1][2]=99,\"\",distarray[1][2])}{if(distarray[1][3]=99,\"\",distarray[1][3])}{if(distarray[1][4]=99,\"\",distarray[1][4])}{if(distarray[1][5]=99,\"\",distarray[1][5])}
30{if(distarray[2][1]=99,\"\",distarray[2][1])}{if(distarray[2][2]=99,\"\",distarray[2][2])}{if(distarray[2][3]=99,\"\",distarray[2][3])}{if(distarray[2][4]=99,\"\",distarray[2][4])}{if(distarray[2][5]=99,\"\",distarray[2][5])}
40{if(distarray[3][1]=99,\"\",distarray[3][1])}{if(distarray[3][2]=99,\"\",distarray[3][2])}{if(distarray[3][3]=99,\"\",distarray[3][3])}{if(distarray[3][4]=99,\"\",distarray[3][4])}{if(distarray[3][5]=99,\"\",distarray[3][5])}
50{if(distarray[4][1]=99,\"\",distarray[4][1])}{if(distarray[4][2]=99,\"\",distarray[4][2])}{if(distarray[4][3]=99,\"\",distarray[4][3])}{if(distarray[4][4]=99,\"\",distarray[4][4])}{if(distarray[4][5]=99,\"\",distarray[4][5])}
60{if(distarray[5][1]=99,\"\",distarray[5][1])}{if(distarray[5][2]=99,\"\",distarray[5][2])}{if(distarray[5][3]=99,\"\",distarray[5][3])}{if(distarray[5][4]=99,\"\",distarray[5][4])}{if(distarray[5][5]=99,\"\",distarray[5][5])}
\n

", "rulesets": {}, "extensions": [], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"AB": {"name": "AB", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "AC": {"name": "AC", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "AE": {"name": "AE", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "BC": {"name": "BC", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "BE": {"name": "BE", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "BF": {"name": "BF", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "CD": {"name": "CD", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "CE": {"name": "CE", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "CF": {"name": "CF", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "DE": {"name": "DE", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "DF": {"name": "DF", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "EF": {"name": "EF", "group": "Ungrouped variables", "definition": "random(1..10)", "description": "", "templateType": "anything", "can_override": false}, "AD": {"name": "AD", "group": "Ungrouped variables", "definition": "99", "description": "", "templateType": "anything", "can_override": false}, "AF": {"name": "AF", "group": "Ungrouped variables", "definition": "99", "description": "", "templateType": "anything", "can_override": false}, "BD": {"name": "BD", "group": "Ungrouped variables", "definition": "99", "description": "", "templateType": "anything", "can_override": false}, "endlist": {"name": "endlist", "group": "Ungrouped variables", "definition": "[\"C\",\"D\",\"F\"]", "description": "", "templateType": "anything", "can_override": false}, "endchoice": {"name": "endchoice", "group": "Ungrouped variables", "definition": "random(0,1,2)", "description": "", "templateType": "anything", "can_override": false}, "end": {"name": "end", "group": "Ungrouped variables", "definition": "endlist[endchoice]", "description": "", "templateType": "anything", "can_override": false}, "weights": {"name": "weights", "group": "Ungrouped variables", "definition": "[\n [99,AB,AC,AD,AE,AF],\n [AB,99,BC,BD,BE,BF],\n [AC,BC,99,CD,CE,CF],\n [AD,BD,CD,99,DE,DF],\n [AE,BE,CE,DE,99,EF],\n [AF,BF,CF,DF,EF,99]\n ]", "description": "", "templateType": "anything", "can_override": false}, "distances": {"name": "distances", "group": "Ungrouped variables", "definition": "[distarray[5][2],distarray[5][3],distarray[5][5]]", "description": "", "templateType": "anything", "can_override": false}, "answer": {"name": "answer", "group": "Ungrouped variables", "definition": "distances[endchoice]", "description": "", "templateType": "anything", "can_override": false}, "distarray": {"name": "distarray", "group": "Ungrouped variables", "definition": "dijkstra(weights)", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["AB", "AC", "AE", "BC", "BE", "BF", "CD", "CE", "CF", "DE", "DF", "EF", "AD", "AF", "BD", "endlist", "endchoice", "end", "weights", "distances", "answer", "distarray"], "variable_groups": [], "functions": {"dijkstra": {"parameters": [["weights", "?"]], "type": "number", "language": "javascript", "definition": "var distarray = [[99,99,99,99,99,99],[99,99,99,99,99,99],[99,99,99,99,99,99],[99,99,99,99,99,99],[99,99,99,99,99,99],[99,99,99,99,99,99]];\n\n// S is the set in the tree\nvar S = [0];\n\n// out is the set outside the tree\nvar out = [1,2,3,4,5];\n\n// distances is the shortest distance from A to each vertex\nvar distances = [0,99,99,99,99,99];\n for (t=0;t<6;t++){\n\tdistarray[0][t] = distances[t];\n }\n// Find the vertex closest to A\nvar least = Math.min(...weights[0]);\nvar idx1 = 0;\nvar idx2 = weights[0].indexOf(least);\n\n// Move that vertex into S\n \tS.push(idx2);\n\tout.splice(out.indexOf(idx2),1);\n\n// Update the distances\ndistances[idx2]=weights[0][idx2];\nfor (t=0;t<6;t++){\n\tdistarray[1][t] = distances[t];\n }\n// Now we want to check all the edges from S to out.\n// for each element in S build a set of the weights from it to elements in out.\n\nfor (k=2;k<6;k++){\n\nvar wtarray = [];\n\nfor(j=0;jFind the shortest path from A to {end}.

", "minValue": "answer", "maxValue": "answer", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Merryn Horrocks", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/4052/"}]}]}], "contributors": [{"name": "Merryn Horrocks", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/4052/"}]}