Greedy and Dynamic Algorithms Flashcards

1
Q

Explain the concept of the greedy approach

A

At each step, the algorithm chooses the best available option without considering the overall future consequences.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are some examples of greedy alogoithms?

A

Greedy Search Algorithm, Prim’s Algorithm,
Kruskal’s Algorithm, Dijkstra’s Algorithm, Huffman Trees.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the Big O of Dijkstra’s algorithm?

A

O(ElogV)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the time complexity of Prim’s algo?

A

O(E log V)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the time complexity of Kruskal’s algo?

A

O(E log E)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which is faster, Prim or Kruskals.

A

Prim’s algorithm runs faster in dense graphs. Kruskal’s algorithm runs faster in sparse graphs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

T/F Prim’s can work using non connected graphs.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the worst case performance of Dijkstra’s using a matrix representation?

A

O(v^2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain Prim’s Algorithm

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain Kruskal’s Algorithm

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain the Floyd Warshall’s Algorithm

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain Dijkstra’s Algorithm

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly