top of page
Inaugurated by IN-SPACe
ISRO Registered Space Tutor

S3-SA5-0231

What is a Weighted Graph?

Grade Level:

Class 10

AI/ML, Data Science, Physics, Economics, Cryptography, Computer Science, Engineering

Definition
What is it?

A weighted graph is a type of graph where each edge (the connection between two points) has a numerical value or 'weight' assigned to it. This weight represents some cost, distance, time, or capacity associated with that connection.

Simple Example
Quick Example

Imagine a map of your city showing different bus stops. If you connect two bus stops with a line, that's an edge. In a weighted graph, this line would also have a number next to it, like '5 km' or '10 minutes', showing the distance or travel time between those stops.

Worked Example
Step-by-Step

Let's say you want to find the shortest path from your home (A) to your friend's house (D) through a network of streets.

Here are the connections and their distances (weights):
Home (A) to Shop (B): 3 km
Home (A) to Park (C): 5 km
Shop (B) to Friend's House (D): 4 km
Park (C) to Friend's House (D): 2 km

---

Step 1: List all possible paths from A to D.
Path 1: A -> B -> D
Path 2: A -> C -> D

---

Step 2: Calculate the total weight (distance) for Path 1.
Weight (A -> B -> D) = Weight (A -> B) + Weight (B -> D) = 3 km + 4 km = 7 km

---

Step 3: Calculate the total weight (distance) for Path 2.
Weight (A -> C -> D) = Weight (A -> C) + Weight (C -> D) = 5 km + 2 km = 7 km

---

Step 4: Compare the total weights of all paths.
Both paths have a total distance of 7 km.

---

Answer: The shortest path from your home to your friend's house is 7 km. Both Path 1 (A->B->D) and Path 2 (A->C->D) are equally short.

Why It Matters

Weighted graphs are super important in computer science, helping algorithms find the best routes for delivery apps like Swiggy or Zomato. They're also used in AI/ML to optimize processes and in economics to model supply chains, opening doors to careers in data science, logistics, and software development.

Common Mistakes

MISTAKE: Confusing a regular graph with a weighted graph, thinking all connections are equal. | CORRECTION: Remember that in a weighted graph, each connection (edge) has a specific numerical value attached to it, which is crucial for calculations.

MISTAKE: Adding up node values instead of edge weights when calculating path costs. | CORRECTION: Weights are always on the edges (the lines connecting nodes), not on the nodes (the points themselves). Always sum the values on the lines you travel.

MISTAKE: Ignoring weights and just counting the number of steps in a path to find the 'shortest' one. | CORRECTION: The 'shortest' path in a weighted graph is the one with the smallest total weight, not necessarily the fewest number of edges. A path with more steps might be shorter in terms of total weight.

Practice Questions
Try It Yourself

QUESTION: A road network has towns P, Q, R. P to Q is 10 km, Q to R is 5 km, P to R is 12 km. What is the weight of the edge connecting Q and R? | ANSWER: 5 km

QUESTION: In a weighted graph representing flight routes, Mumbai to Delhi costs Rs. 5000 and Delhi to Bangalore costs Rs. 7000. What is the total 'weight' (cost) of a journey from Mumbai to Bangalore via Delhi? | ANSWER: Rs. 12000

QUESTION: Consider a weighted graph where points A, B, C, D are connected. A-B (weight 4), B-C (weight 2), C-D (weight 5), A-D (weight 8). Find the path from A to D with the minimum total weight. | ANSWER: A -> B -> C -> D with a total weight of 4 + 2 + 5 = 11. (Path A->D directly has weight 8, so A->D is the minimum total weight).

MCQ
Quick Quiz

What does the 'weight' on an edge in a weighted graph typically represent?

The number of nodes in the graph

The value or cost associated with traversing that connection

The color of the edge

The total number of paths available

The Correct Answer Is:

B

The weight on an edge represents a numerical value like distance, time, or cost for using that connection. It's not about the number of nodes, edge color, or total paths.

Real World Connection
In the Real World

When you use Google Maps or Ola/Uber, the app calculates the fastest or shortest route for your auto-rickshaw or cab. It uses weighted graphs where roads are edges and their lengths or typical travel times are the weights. This helps delivery services like Dunzo or Zepto optimize their routes to get your groceries or food to you quickly.

Key Vocabulary
Key Terms

GRAPH: A collection of points (nodes) connected by lines (edges) | NODE (VERTEX): A point or location in a graph | EDGE: A connection or line between two nodes | WEIGHT: A numerical value assigned to an edge, representing cost, distance, or time | PATH: A sequence of connected edges from one node to another

What's Next
What to Learn Next

Now that you understand weighted graphs, you can explore algorithms like Dijkstra's Algorithm or Prim's Algorithm. These algorithms use weights to find the shortest paths or minimum spanning trees, which are super useful in many real-world problems!

bottom of page