D1 – Minimum Connectors D1 – Minimum Connectors A minimum spanning tree shows the shortest set of edges connecting a number of vertices. For n vertices there are n – 1 edges in a minimum spanning tree. Prim’s algorithm adds the nearest vertex to the current tree. - must have start vertex - find nearest vertex to existing tree - add vertex to tree - don’t make a cycle - continue until all vertices part of tree Prim’s algorithm can be applied to a matrix. Kruskal’s algorithm adds edges to a tree in order of size. - start with shortest edge - find next shortest edge - add vertex to tree - don’t’ make cycles - continue until all vertices part of tree. D1 – Shortest Path Problem A minimum spanning tree shows the shortest set of edges connecting a number of vertices. For n vertices there are n – 1 edges in a minimum spanning tree. Prim’s algorithm adds the nearest vertex to the current tree. - must have start vertex - find nearest vertex to existing tree - add vertex to tree - don’t make a cycle - continue until all vertices part of tree Prim’s algorithm can be applied to a matrix. Kruskal’s algorithm adds edges to a tree in order of size. - start with shortest edge - find next shortest edge - add vertex to tree - don’t’ make cycles - continue until all vertices part of tree. D1 – Shortest Path Problem Real-life problems may not obey the triangle inequality. Real-life problems may not obey the triangle inequality. Dijkstra’s algorithm enables the shortest path between two points to be found. - label start vertex as 0, box this number - at each vertex connected to start vertex list distance - box smallest number - from this vertex, list all distances connected to this vertex - if distance is less than a value at this vertex, cross out and write new value - box the smallest number shown at any vertex - continue until destination is boxed. Dijkstra’s algorithm enables the shortest path between two points to be found. - label start vertex as 0, box this number - at each vertex connected to start vertex list distance - box smallest number - from this vertex, list all distances connected to this vertex - if distance is less than a value at this vertex, cross out and write new value - box the smallest number shown at any vertex - continue until destination is boxed. Dijkstra’s algorithm is equally valid when used backwards through a network (i.e. this is necessary when there are multiple starting points.) Dijkstra’s algorithm fails if there are negative edges in the network. Tracing a route through a network can be easily found if careful labelling of Dijkstra’s algorithm is used. Dijkstra’s algorithm is equally valid when used backwards through a network (i.e. this is necessary when there are multiple starting points.) Dijkstra’s algorithm fails if there are negative edges in the network. Tracing a route through a network can be easily found if careful labelling of Dijkstra’s algorithm is used.