AI Glossary / Graphs and symbolic AI / Intermediate
Weighted graph
Definition
A weighted graph is a graph whose edges have numerical values called weights. The nodes represent entities, the edges represent relationships, and the weights describe a chosen property of those relationships. Depending on the model, a weight might mean travel time, cost, capacity, similarity, or interaction frequency. The meaning determines how an algorithm should use the numbers.
What it means
An unweighted graph records whether a relationship exists. A weighted graph adds quantitative information about that relationship. It can be directed or undirected, so edge direction and edge weight are separate choices.
Larger does not always mean better. A larger travel-time weight means a slower connection, while a larger capacity weight may mean a connection can carry more traffic. A similarity score might indicate stronger resemblance. Treating these meanings as interchangeable can produce an answer that is mathematically consistent with the input but inappropriate for the actual question.
How it works
Define the nodes, decide which relationships deserve edges, and attach weights with documented units and interpretation. Then select an operation appropriate to that interpretation. A shortest-path calculation commonly minimizes the sum of edge costs along a route. A capacity problem asks a different question and may need flow or bottleneck reasoning.
Weights can be stored as edge attributes or in a suitable matrix representation. An algorithm must be told which attribute to use. Some implementations ignore stored weights unless explicitly selected, or supply defaults for missing values. Check these conventions rather than assuming that a field labeled weight automatically controls every calculation.
Three practical examples
- A delivery model can attach estimated minutes to road segments and compare routes by total modeled travel time.
- A document-similarity network can attach scores expressing how closely pairs of documents resemble one another.
- A communications model can attach link capacities to investigate throughput constraints rather than treating all connections as equally capable.
Think of it this way
Think of a map whose lines have labels. The labels add information, but the legend tells you whether they represent minutes, kilometers, or vehicles per hour. The analogy is limited because abstract graph weights can describe relationships with no physical route at all, and the correct way to combine them depends on the modeled task.
Worked example
Consider an original undirected graph with nodes A, B, and C. Let the edge weights be A-B = 3, B-C = 3, and A-C = 8. First interpret every weight as travel time in minutes.
The direct A-C route takes 8 minutes. The route A-B-C takes 3 + 3 = 6 minutes, so it is the shorter weighted route despite using two edges. If the graph is treated as unweighted, the direct edge wins because it has one hop rather than two. The topology has not changed; the optimization question has.
Now consider a separate interpretation of the same numerical labels as link capacities in units per second. Sending traffic along A-B-C is limited by the smaller capacity on that route, which is 3. The direct A-C link supports 8. Adding 3 + 3 to describe the indirect route's capacity would be incorrect because the same traffic must pass through both links.
If the question instead allows simultaneous flow along both routes with no other constraints, the direct route can carry 8 and the route through B can carry 3, for a total of 11. This differs again from choosing one route.
The example shows why a weighted graph is a representation, not a complete specification of the problem. You must also define the units, allowed movement or flow, and objective. Reusing the same stored numbers under a different interpretation changes what a valid calculation means.
Illustrative case study
Fictional case: a content team creates a graph in which stronger similarity produces larger edge weights. It then runs a shortest-path routine directly on those scores and discovers that weakly related links are being treated as cheap.
The team revisits the intended task. It decides whether it needs similarity-based grouping, relationship visualization, or a defensible conversion to distance for path analysis. It documents the choice and tests small examples before using the graph in recommendations. The case does not assume that one universal similarity-to-distance formula suits every dataset.
Common misconceptions and mistakes
Do not assume weights are probabilities or that they must sum to one. Do not assume all graph algorithms interpret larger weights in the same direction. A zero-weight edge can be a real connection with zero modeled cost; it is not automatically the absence of an edge.
Negative weights are possible in some formulations, but they require compatible algorithms and attention to negative cycles for shortest-path questions. Common Dijkstra-style shortest-path methods require nonnegative weights. Also distinguish edge weights from node weights, which attach values to entities rather than relationships.
Business use
Weighted graphs help organizations model trade-offs that simple connectivity misses. They can support routing, allocation, network analysis, and relationships among data items.
Before trusting an output, document how each weight was measured or estimated, its units, and whether it changes over time. Check missing and zero values separately. Keep different meanings in different attributes, such as travel time and capacity, rather than collapsing them into one unexplained score. Validate the selected algorithm on a tiny example where the expected answer is easy to calculate.
People also ask
Can a weighted graph also be directed?
Yes. Direction specifies allowed orientation, while weight quantifies a property of an edge.
Does shortest mean fewest edges?
Only for the unweighted hop-count interpretation. A weighted shortest path usually minimizes the sum of selected edge costs.
Must every weight be positive?
No universal definition requires that, but a particular algorithm or application may impose positivity or nonnegativity.
Check your understanding
Why is A-B-C preferable for travel time but worse as a single capacity route in the example?
Answer: Its travel times add to 6, below 8, but its route capacity is limited to 3, below the direct link's 8.
Related terms
- Graph
- Edge weight
- Directed graph
- Shortest Paths
- Dijkstra's algorithm
- Maximum Flow
- Similarity graph
- Shortest path
- Capacity
- Adjacency matrix
Learn next
Add a fourth node D with travel-time edges A-D = 2 and D-C = 3. Compare the new route with the existing alternatives. Then reinterpret those labels as capacities and explain why the arithmetic and preferred single route differ. Keep the two interpretations in separate diagrams or tables.
More in Graphs and symbolic AI
- Type signature - A type signature specifies the types of inputs and outputs associated with a function or operation.
- UCB1 - UCB1 is a multi-armed bandit algorithm that selects an action using its average observed reward plus an exploration bonus.
- UCT - UCT is a method for guiding Monte Carlo tree search by applying upper-confidence-bound ideas at decision nodes.
- Łukasiewicz logic - Łukasiewicz logic is a family of many-valued logics associated with Jan Łukasiewicz.
- Unary constraint - A unary constraint is a rule that restricts the allowed values of one variable in a constraint satisfaction problem.
- Unbounded cost search - Unbounded-cost search seeks a valid solution without requiring its cost to fall below a specified threshold or within a specified factor of the best...
Sources
Primary sources: Aalto Dictionary of Machine Learning, weighted graph definition: https://aaltodictionaryofml.github.io/ADictML_Main.pdf ; NetworkX 3.6 official shortest-path documentation: https://networkx.org/documentation/networkx-3.6/reference/algorithms/shortest_paths/index.html . The three-node calculations and case study are original.
Previous: Weighted correlation network analysis Next: Weighted least squares