WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Data Structures & Algorithms · Intermediate · question 28 of 100

Explain the difference between weighted and unweighted graphs.?

📕 Buy this interview preparation book: 100 Data Structures & Algorithms questions & answers — PDF + EPUB for $5

The difference between weighted and unweighted graphs lies in the values associated with their edges.

In an unweighted graph, all edges have the same value or weight, which is typically 1. This means that there is no distinction between different edges, and the shortest path between two vertices is the path with the fewest number of edges. For example, consider a graph representing a road network between cities, where each city is a vertex and each edge represents a road connecting two cities. In an unweighted graph, each road has the same weight, so the shortest path between two cities is the path with the fewest number of roads.

In a weighted graph, each edge has a value or weight associated with it, which can represent a variety of quantities such as distance, cost, or time. This means that some edges may be more important than others, and the shortest path between two vertices is not necessarily the path with the fewest number of edges. For example, consider a graph representing a flight network between cities, where each city is a vertex and each edge represents a flight between two cities. In a weighted graph, each flight has a different duration or cost, so the shortest path between two cities may involve taking a longer flight with a lower cost or a shorter flight with a higher cost.

Weighted graphs are useful for modeling real-world scenarios where the edges have varying degrees of importance or cost. They can be used in various applications such as route planning, resource allocation, and network optimization.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Data Structures & Algorithms interview — then scores it.
📞 Practice Data Structures & Algorithms — free 15 min
📕 Buy this interview preparation book: 100 Data Structures & Algorithms questions & answers — PDF + EPUB for $5

All 100 Data Structures & Algorithms questions · All topics