0% found this document useful (0 votes)
3 views2 pages

Rec C

The document discusses two methods for solving a problem related to graphs with edge weights, specifically focusing on Dijkstra's algorithm. Method I involves a reduction to create a new graph G' with only edge weights, allowing the use of Dijkstra's algorithm to find shortest paths, while Method II modifies Dijkstra's algorithm to account for node weights. Additionally, it includes a problem requiring the identification of a DFS tree and various types of edges in a given graph starting from a specified node.

Uploaded by

zhihengzhou0419
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Rec C

The document discusses two methods for solving a problem related to graphs with edge weights, specifically focusing on Dijkstra's algorithm. Method I involves a reduction to create a new graph G' with only edge weights, allowing the use of Dijkstra's algorithm to find shortest paths, while Method II modifies Dijkstra's algorithm to account for node weights. Additionally, it includes a problem requiring the identification of a DFS tree and various types of edges in a given graph starting from a specified node.

Uploaded by

zhihengzhou0419
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Spring 2025 CSCI 2300 -- Introduction to Algorithms

Recitation C: Graphs with Edge Weights

Problem Statement: DPV 4.19

Solution: There are two approaches: one is a reduction; the other is a direct modification of Dijkstra’s
algorithm.
Method I: The idea is to use a reduction: on input (G, l, c, s), we construct a graph G’ = (V ‘, E ’ ) where
G’ only has edge weights (no node weights), so that the shortest path from s to t in G is essentially the same
as that in G ′, with some minor modifications. We can then compute shortest paths in G′ using Dijkstra’s
algorithm.
The reduction works by taking every vertex v of G and splitting it into two vertices vi and v o. All edges
coming into v now come into v i, while all edges going out of v now go out of v o. Finally, we add an edge
from vi to vo of weight c(v).

c(v)

Reduction in 4.19.

Consider now any path in G and notice that it can be converted to an edge-weighted path of the
same weight in G′ by replacing the visit to vertex v with the traversal of edge (vo, vi). Conversely,
consider a path in G ′: every other edge visited is of the form (vi, v o) and corresponds to a vertex v of G.
Replacing these edges with the corresponding vertices we obtain a path in G of the same weight as the path
in G ′. The time required to perform this reduction is O(|V | + |E|). G′ has |V | + |E| edges and 2|V |
vertices, so running Dijkstra takes time O(|V |2 ) and the total running time is O(|V |2).

Method II: We make the following modifications to Dijkstra’s algorithm to take into account node
weights:
• In the initialization phase, dist(s) = w(s).
• In the update phase, we use dist(u) + l(u, v) + w(v) instead of dist(u) + l(u, v).
Analysis of correctness and running time are exactly the same as in Dijkstra’s algorithm.
Problem 2: For the graph below, find the DFS tree starting from A (following the alphabet order
when you have multiple choices). Identify the back edges, forward edges, and cross edges.
Note that the nodes not reachable from A should not be in the DFS tree.

A B C D E

F G H I J

K L M

You might also like