What is a weighted graph?
A weighted graph is a graph in which every edge is assigned a weight (a numeric value).
Edge weight is a characteristic of the connection between vertices: distance, cost, time, connection strength, and so on.
Formally
A weighted graph is G = (V, E, w), where w(u, v) is a function that defines the weight of edge (u, v).
Example
Let there be vertices - cities: A, B, C, and edges with distances:
- A-B (5 km)
- B-C (3 km)
- A-C (8 km)
Then the edge weights are 5, 3, and 8.
Applications
- Maps and navigation (weight = distance or time).
- Cost optimization (weight = price).
- Shortest-path algorithms (Dijkstra, Bellman-Ford).
Summary: a weighted graph is a graph where every edge has a weight that reflects the "cost" of the connection between vertices.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.