Graph Algorithms Flashcards
1
Q
Dijkstra’s algorithm (3)
A
- ) Used to find the shortest path from one node (“source”) to every other node.
- ) Part of greedy technique.
- ) Works only on graphs with non negative edges.
2
Q
Dijkstra’s how (6)
A
- ) Assign 0 to initial node and infinity to all others.
- ) Set initial node as current, all others as unvisited.
- ) Calculate all tentative distances from adjacent nodes. If value is lower than current assign it.
- ) Set node as visited.
- ) if destination node is set as visited or no more nodes are available, algorithm has finished.
- ) else select node with lowest tentative distance and repeat from 3.
3
Q
Spanning tree (1)
A
1.) Tree which contains all vertices in the graph.
4
Q
Minimum spanning tree (1)
A
1.) Spanning tree in a weighted graph with the lowest possible weight.
5
Q
Prim’s algorithm (2)
A
- ) Used to find the minimum spanning tree in a graph.
2. ) Part of greedy technique.
6
Q
Prim’s how (3)
A
- ) Select a vertex to be the first in the tree.
- ) Consider all vertices adjacent to the tree, and add the lowest one.
- ) Repeat 2 until each vertex is included.
7
Q
Kruskal’s algorithm (2)
A
- ) Used to find the minimum spanning tree in a graph.
2. ) If graph is made of sub-graphs, find minimum spanning forest.
8
Q
Kruskal how (6)
A
- ) Remove all loops.
- ) Remove parallel edges (keep ones with lowest weight).
- ) Create edge table sorted in ascending order.
- ) Select edge with minimum weight.
- ) Select edge with minimum weight which doesn’t form a cycle.
- ) Repeat 5 until each vertex is included.