Greedy and Dynamic Algorithms Flashcards
Explain the concept of the greedy approach
At each step, the algorithm chooses the best available option without considering the overall future consequences.
What are some examples of greedy alogoithms?
Greedy Search Algorithm, Prim’s Algorithm,
Kruskal’s Algorithm, Dijkstra’s Algorithm, Huffman Trees.
What is the Big O of Dijkstra’s algorithm?
O(ElogV)
What is the time complexity of Prim’s algo?
O(E log V)
What is the time complexity of Kruskal’s algo?
O(E log E)
Which is faster, Prim or Kruskals.
Prim’s algorithm runs faster in dense graphs. Kruskal’s algorithm runs faster in sparse graphs.
T/F Prim’s can work using non connected graphs.
False
What is the worst case performance of Dijkstra’s using a matrix representation?
O(v^2)
Explain Prim’s Algorithm
finding the MST for a graph by randomly selecting any node then the node with the shortest distance from the current node or set of nodes visited so far until all nodes have been connected
Explain Kruskal’s Algorithm
finding the MST for a graph by selecting the smallest edge then the next smallest edge and so on until all nodes have been connected
Explain the Floyd Warshall’s Algorithm
finding the shortest path between each node and all other nodes in a given graph, by selecting each node and seeing if a shorter path can be found from each source to each destination by going through the currently selected node
Explain Dijkstra’s Algorithm
finding the shortest path between a specific starting node and a specific destination node. It picks the unvisited node with the smallest distance, calculates the path through it from the start node, and updates the neighbours distances if smaller.