0

Are there any general or simple algorithms that convert a weighted graph into a non-weighted graph (where each edge has the same weight)?

I know an algorithm called Djikstra's algorithm that works very similar to BFS on a weighted graph when finding the shortest distance between any two vertices in a graph.

But I would like to change the question a little that takes in any weighted graph where each edge is in the set of weights {1,2,3,4,...,n} where each number in the set is a weight of an edge. That way, if every edge is the same weight, I can apply BFS or DFS to it directly.

I want to find a way to modify the graph so that each edge in the modified graph has the same weight (meaning preferably each edge in the modified graph has weight 1). I know that I may have to delete or add edges and add intermediate vertices or delete any vertices to/from the original graph to satisfy this.

Is there a general idea on how to accomplish this? I've never seen a post on StackOverflow that goes over this.

Dew Man7
  • 33
  • 5
  • Every edge of weight 4 (for example) can be replaced by 4 edges of weight 1. – c0der Mar 25 '21 at 17:37
  • Yeah I get the idea. But is there an algorithm to do this? I am thinking of using a hash table with linked list (adjacency lists) to model a graph and add/delete edges and intermediate vertices. – Dew Man7 Mar 28 '21 at 18:00

1 Answers1

0

Note: There is nothing about a weighted graph that prevents you from using BFS/DFS.

With that being said you certainly can convert a weighted graph to an unweighted graph by just adding a bunch of intermediate notes. However, I would not recommend that you do this because there are already algorithms like dijkstra's, bellman ford, floyd warshall ... that can compute shortest paths on weighted graphs. Additionally, I would assume that it would be very difficult to represent a weighted graph with negative edges using an unweighted graph.

  • I know that I can use Djikstra's algorithm but is there a general algorithm for reducing the graph to make all weights the same (like all edges equal to 1)? – Dew Man7 Mar 24 '21 at 21:43