Solving shortest path problem with Dijkstra’s algorithm for n negative-weight edges and no negative-weight cycle

Although many texts state Dijkstra’s algorithm does not work for negative-weight edges, the modification of Dijkstra’s algorithm can. Here is the algorithm to solve a single negative-weight edge without negative-weight edges.

Let $ d_s(v)$ be the shortest distance from source vertex s to vertex v.
Suppose the negative edge $ e$ is $ (u, v)$
First, remove the negative edge $ e$ , and run Dijkstra from the source vertex s.
Then, check if $ d_s(u) + w(u, v) \leq d_s(v)$ . If not, we are done. If yes, then run Dijkstra from $ v$ , with the negative edge still removed.
Then, $ \forall t \in V $ , $ d(t) = min(d_s(t), d_s(u) + w(u, v) + d_v(t))$

Given the above algorithm, I want to modify the above algorithm again to solve n negative-weight edges and no negative weight cycle. Any hint?

CLRS 22.3-1, How Come Solutions Online State There Can’t Be Edges From WHITE to GRAY nodes “at any point… during search”?

The exercise (from the book Introduction To Algorithms) states

Make a 3-by-3 chart with row and column labels WHITE, GRAY,and BLACK. In each cell (i, j) indicate whether, at any point during a depth-first search of a di- rected graph, there can be an edge from a vertex of color i to a vertex of color j . For each possible edge, indicate what edge types it can be. Make a second such chart for depth-first search of an undirected graph.

The colors WHITE, GRAY, BLACK correspond to Undiscovered, discovered but not finished, and finished. The following solution is what multiple sites & universities have posted(such as: walkccc, Rutgers University):

 |       | WHITE         | GRAY                | BLACK                | |-------|---------------|---------------------|----------------------| | WHITE | All kinds     | Cross, Back         | Cross                | | GRAY  | Tree, Forward | Tree, Forward, Back | Tree, Forward, Cross | | BLACK | -             | Back                | All kinds            | 

I will draw a minimal counter example as it helps understand my conflict:


  • Start at node 0: 0 is GRAY
  • At this point, 3 is still white and has an edge to 0
  • Resume and keep going, eventually the edge from 3 to 0 will be discovered as a tree edge

This contradicts the solutions saying you can only have Cross/Back edges going form WHITE->GRAY. This example can be easily modified to contradict many of the elements in the table. I think the solutions are doing one of the following:

  • Assuming that the graph is a tree and that we start at its root. (Wrong as DFS doesn’t need a tree graph and any node can be started from).
  • More likely (Just thought of this), interpreting the question of "can there be an edge" as "can there be an edge that we have discovered". In which case, the solutions work, as although the edge from 3->0 was a WHITE->GRAY edge at one point, we hadn’t discovered it yet.

In the dataflow programming paradigm programs are modeled as directed graphs. Are the edges of the graph variables? And are the vertexes functions?

As I understand it in dataflow programming, programs are structured as directed graphs, an example of which is below enter image description here

Is it true to say that the arrows (or edges) represent the variables within a program and the vertexes (blue circles) represent programmatic functions? Or is this too much of a simplification?

I am interested in understanding how dataflow languages actually apply graph theory.

First-time and second-time seen edges in DFS on undirected graphs

Assume an undirected graph and a DFS traversal on it. I am interested in the DFS tree which encodes the discoverer/discovered (parent/child) relationships of the traversal. Just to make sure we are on the same page, define a discovered vertex x as one that has been visited but descendants of it are still being processed, i.e., we have not yet returned back to x. Define, a processed vertex x as one that we have returned to after we have recursed into all of its descendants and we mark it as such upon return.

Let us define the following edge types on that tree

  • Tree edges: direct parent/child edges: the parent is the one to first discover the child.
  • Back edges: edge from a descendant to an ancestor at least 2 levels up on the tree: the descendant sees an already discovered vertex.

Those are the only two types of edges one can have on undirected graph DFS. Now, I have been reading The Algorithm Design Manual (page 173) which discusses the following:

  • Given an undirected graph DFS and an edge (x,y) as seen from x how can we tell whether we have seen this edge before from the side of y?

I can understand the cases when y is undiscovered or discovered but not yet processed.

However, the book says that if y is processed then we can say that it’s the 2nd time (i.e., we have seen the edge (x,y) from y before); this is because we should have seen all edges coming out of y before marking it as processed. The part I don’t understand is when such a case can occur. How can we see y again after we have marked it processed? Can you give me an example of such a graph?

Prove: If $T’$ is not a MST one of its edges may be replaced by a lighter edge in order to get a lighter spanning tree

Prove: If $ T’=(V,F’)$ is not a MST of $ G=(V,E)$ , then there are edges $ e’ \in F$ and $ e \in $ $ E$ \ $ F$ such that $ w(e)<w(e’)$ and $ T’$ \ $ \{e’\} \cup \{e\}$ is a spanning tree.

My idea:

Let $ T=(V,F)$ be a MST of $ G$

for all $ e \in T$ , try to insert it into $ T’$ and see if there is an edge in the cycle created that is heavier than $ e$ . If we found such $ e$ we are done.

If not, define $ G’=(V,F \cup F’)$

This graph obviously has a MST.

We didn’t find a suitable $ e$ in the previous part so all edges in $ F$ may be colored in red.

That means there is a MST $ T”=(V,F”)$ such that $ F” \ F’$ but that is impossible because $ T’$ is not a MST of $ G’$ , because $ T$ is lighter.

Does that seem correct?

Find every path that passes through certain edges

I’m faced with the following problem:


  • Directed and unweighted graph, where each edge E has two attributes


  • Find every path through the 3 (or more) given edges


  • Is it NP-hard?
  • Is there already an algorithm for this?
  • I was thinking about placing a node in every edge and than run Dijkstra algorithm to find the shortest path from A to B and then from B to C. Although, this complicates my graph. Any other ideas? Thanks

Shortest path using less than or equal to m edges in a directed, weighted graph with negative cycles

I’m solving a problem:

Given a directed, weighted graph $ G$ that has $ V$ vertices and $ E$ edges and a positive integer $ m$ , describe an algorithm that finds the length of the shortest path using less than or equal to $ m$ edges. Note that the graph may contain negative cycles.

First, I tried Bellman-Ford algorithm, but I cannot deal with negative cycles. Next, I tried one using recursive DFS, but it takes too much time! I think dynamic programming may solve this problem, but I don’t know how to start with DP. Is there any fancy way to solve this problem in short time?

How do I purchase edges?

I’m creating a new character for Hunter: The Reckoning. My virtues are Zeal (3 dots). How do I buy my edges?

The short guide on page 84 of the Reckoning book says “edges (according to your Virtue allocation)”. I understand this to mean that I have three dots to spend on Zeal edges.

I’m confused about how to spend those dots on edges. Each edge has several ability with a dot cost. Do I pay the full cost of each one? Or are they accumulative?

For example, the Judgment edges (pg.159-162) include:

  • Discern (1 dot)
  • Burden (2 dots)

If I want both of those, did I just spend 2 dots or 3?

Count bridging edges in a family of two component forests

I am given a (simple, undirected, connected) graph $ G = (V, E)$ and a fixed spanning tree $ T$ in this graph. Removing an edge $ e\in E(T)$ from $ T$ splits it into a spanning forest $ F^e$ with two components $ F_1^e$ and $ F_2^e$ . I am interested in the number $ c(e)$ of edges in $ G$ that connect $ F^e$ i.e. with one vertex in $ F_1^e$ and the other in $ F_2^e$ .

I would like to compute the number $ c(e)$ for all $ e$ in $ T$ simultaneously. This can be done naively in $ O(|V||E|)$ . Is there a faster way to achieve this?

The graphs I am working with are small-world graphs. In particular the average distance between nodes in $ G$ can be assumed to be small.