Junior — Middle
Can you explain what a graph is, where each edge is assigned a certain weight?
sobes.tech AI
Answer from AI
A weighted graph on edges is a data structure consisting of a set of vertices and edges, where each edge has a numerical weight (cost, length, time, etc.). Such a graph is often used to model problems where the cost of transitioning between nodes is important, for example, in navigation or network routing.
Example: in a graph of cities, an edge between two cities may have a weight equal to the distance between them. This allows finding the shortest path with the minimal total length.
In programming, weighted graphs are usually represented using adjacency lists or adjacency matrices, which store information about the weights of edges.