liveBook · Manning

Edge weight

As explained in Advanced Algorithms and Data Structures

A weight is a numerical value associated with a graph edge to represent its cost, distance, or other measure.

An edge weight is a numerical value attached to a graph edge. It represents a cost, distance, travel time, or another domain-specific measure. For a path, add the weights of its edges; the minimum-distance path is the one with the smallest total. section 14.4.1

This changes how shortest-path algorithms choose what to explore. Breadth-first search counts edges, so a path with fewer hops wins. Dijkstra’s algorithm instead orders discovered vertices by accumulated edge weight, using a priority queue rather than a plain queue. section 14.4.1

A longer route can be cheaper

Suppose one route from v1 to v2 uses v1→v3→v2 with total weight 8. Another uses v1→v3→v5→v2 with three edges but total weight 5. The second route is longer by hop count yet preferable by edge weight, so Dijkstra’s algorithm updates v2’s priority from 8 to 5. section 14.4.3

Use edge weights to model different measurable objectives:

  • Use meters to represent physical distance between intersections. section 14.4.1
  • Use travel time when traffic, weather, or closures change the cost of traversing a road. section 14.5.2
  • Keep heuristic estimates comparable with edge weights by using compatible units or scaling. section 14.5.2
Figure 14.17 Overlaying a directed weighted graph over the map in figure 14.16. Edges’ weights are the distances (in meters) between the intersections modeled by the edge’s vertices.

View a directed road graph whose edge weights are distances in meters between modeled intersections. section 14.4.1

How Advanced Algorithms and Data Structures covers it

How deep it goes
Defines path totals and priority changes, then connects them to priority-queue choices and Dijkstra running times.
Examples
Uses intersection maps, competing routes, road distances, and changing travel times caused by traffic or closures.
What it assumes
Assumes familiarity with graphs, vertices, edges, paths, and breadth-first search while contrasting hop count with accumulated weight.
What you can do after
Apply it via Dijkstra’s algorithm to compare routes by accumulated cost and select an appropriate priority-queue implementation.
How it connects
Connects weighted graphs with shortest-path algorithms, breadth-first search, Dijkstra’s algorithm, priority queues, and heuristics.

Also explained in

Compare how 3 books explain edge weight →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Advanced Algorithms and Data Structures. The section links point to the parts of the book it draws on.