Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CS 7280 Lesson 2 Notes

Lesson 2 Part 3

DAG

● If a directed network has a topological order, it must be a directed acyclic graph


(DAG).
● This can be easily demonstrated by considering that if the network had a cycle,
there would be an edge from a higher-ranked node to a lower-ranked node,
which would violate the topological order property.
● A DAG must contain at least one source node, which is a node with zero
incoming edges.
● This can be observed by starting from any node in the DAG and moving
backward, following edges in the opposite direction. Eventually, we will reach a
source node since there are no cycles and the graph has a finite number of
nodes.
● If a graph is a DAG, it must have a topological ordering.
● To demonstrate this, start from a source node s (as we established that every
DAG has at least one source node).
● Remove the source node s and decrement the in-degree of all nodes that s
points to. The graph remains a DAG after the removal of s.
● Choose a new source node s' and repeat the previous step until all nodes are
removed.
● It's important to note that the topological order of a DAG may not be unique.

Dijkstra’s Shortest Part Algorithm

● For a weighted network where the weight of each edge represents its "length" or
"cost," Dijkstra's algorithm can be used to compute the shortest path from a
source node s to any other node.
● It's important to note that Dijkstra's algorithm is applicable only when the weights
are positive.
● The key idea in the algorithm is to select, in each iteration, the node m with the
minimum known distance from s. This distance cannot be further reduced in
subsequent iterations.
● The algorithm then updates the minimum known distance to every unexplored
neighbor of m if it is larger than the distance from s to m plus the cost of the edge
from m to the neighbor.
● If the network is weighted and includes negative weights, Dijkstra's algorithm is
not suitable. Instead, the Bellman-Ford algorithm can be used, which is a classic
example of dynamic programming.
● The running time of the Bellman-Ford algorithm is O(m*n), where m is the
number of edges and n is the number of nodes.
● In contrast, the running time of Dijkstra's algorithm is O((m + n) log n) if a
Fibonacci heap is used to identify the node with the minimum distance from s in
each iteration of the loop.

You might also like