8.1 Graph Traversal –Dijkstra’s Algorithm Flashcards

1
Q

Shortest Path Problem Variations and Algorithms

A

❑Problem Variations:
❑Single-source shortest path problem: shortest paths from source node to all other nodes in the graph
❑Single-destination shortest path problem: shortest paths from all nodes in the directed graph to a single destination node.
❑All-pair shortest path problem: shortest paths between every pair of nodes in the graph
❑Various algorithms for solving the problem: Dijkstra’s algorithm, Bellman-Ford algorithm, A* search algorithm, Floyd-Warshallalgorithm etc..

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

Dijkstra’s Algorithm

A

❑Used to solve the shortest path problem
❑Both directed and undirected graphs
❑All edges must have non-negative weights
❑Graphs must be connected
❑Many variants but the most common is to find the shortest paths from a source node to all other nodes in the graph.
❑Given an end destination, we can keep track of visited nodes and thus find the path

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

Dijkstra’s Time Analysis

A

❑The complexity of the algorithm depends on the implementation and the data structure:
❑The classic implementation is O(n2), nbeing the number of nodes of the graph
❑Using other implementations like heaps: O(E + nlog n), Eis the number of edges and nis the number of nodes of the graph

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

What is a heap?

A

*In a max heap, for any given node C, if P is a parent node of C, then the key (the value) of P is greater than or equal to the key of C.

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

Dijkstra’s Algorithm Applications

A

*Geographical Mapping Services
▪Google Maps/Waze use algorithms similar to Dijktra’sto find the shortest path between two points
*Network Routing Protocols: find the shortest path for data packets to travel across a network
*Game Development/Robot navigation: find the shortest path for game characters to navigate around obstacles.
*Social Network Analysis: measure social influence

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

Dijkstra’s Algorithm Disadvantages

A

*No sense of direction
*It does not work with negative weights
*Once a node is marked as visited, it cannot be reconsidered even if there is another path with less cost or distance
*Time Complexity/Memory Usage for Dense Graphs: The algorithm can be quite slow on dense graphs (graphs with many edges).
*Single Source Limitation: Dijkstra’s algorithm finds the shortest path from a single source to all other vertices. If you need the shortest paths between all pairs of vertices, you must run Dijkstra’s algorithm once for each vertex, which can be inefficient.
*Not Dynamic: Dijkstra’s algorithm doesn’t adapt well to dynamic graphs where edge weights change frequently. In such cases, the algorithm would have to be rerun from scratch to find the new shortest paths

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

Floyd–WarshallAlgorithm

A

❑This algorithm computes how far each node is from every other node in the input graph
❑All-pairs shortest path
❑Computes 1-step paths, 2-step paths, etc…
❑Is it shorter to go to a node via a node rather than directly to it
?❑It does not return the paths [but it can do…]
❑Negative edges allowed (but not negative cycles)

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

Dynamic Programming

A

❑Floyd-Warshallrelies on Dynamic Programming
❑It is a problem-solving approach
❑Systematically pre-compute and store the answers to sub-problems to build up the solution to a complex problem
❑Reuses those recorded results instead of recomputing them

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

Dynamic Programming

A

A dynamic programming algorithm solves every subproblem just once and then saves its answer in a table, avoiding the work of recomputing the answer every time the subproblem is encountered.

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

Floyd–Warshall-Steps

A

❑The optimal way to represent the graph is with 2D adjacency matrix
❑If there is no edge between two nodes we set the edge weight to infinity
❑Indicating two nodes are not directly connected to each othe

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

Floyd–WarshallTime Analysis

A

❑What is the time complexity of this algorithm?
❑O(n3), where nis the number of nodes
❑Because of the three nested for loops
❑Ideal for smaller graphs ❑No larger than few hundred nodes

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