Data Structures Questions Medium
The main difference between a weighted graph and an unweighted graph lies in the presence or absence of weights assigned to the edges of the graph.
In an unweighted graph, each edge is considered to have the same weight or cost. It means that there is no distinction between the edges in terms of their importance or significance. The primary focus in an unweighted graph is on the connectivity between the vertices, rather than the specific values associated with the edges.
On the other hand, a weighted graph assigns a numerical value, known as weight or cost, to each edge. These weights represent some measure of distance, cost, time, or any other relevant metric associated with the connection between the vertices. The weights can be positive, negative, or zero, depending on the specific application or problem being solved.
The presence of weights in a weighted graph allows for a more detailed representation of real-world scenarios. It enables the graph algorithms to consider the varying costs or distances associated with different paths between vertices. Weighted graphs are commonly used in applications such as network routing, shortest path algorithms, and optimization problems.
In summary, the key difference between a weighted graph and an unweighted graph is that a weighted graph assigns specific weights to the edges, while an unweighted graph assumes all edges have equal weight.