What are weighted graphs, and how are they represented in data structures?

Quick Overview

Explain what a weighted graph is and how its edge weights are stored in common graph representations. Tests understanding of the memory and lookup trade-offs between representations and how the choice affects shortest-path and spanning-tree algorithms.

What are weighted graphs, and how are they represented in data structures?

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Other

What are weighted graphs, and how are they represented in data structures? Describe the common ways to store one in memory and where the weights live in each. ```hint Where the weight goes Start from the usual ways to store an unweighted graph. Ask where one extra number per edge would fit in each, and how each one shows that there is no edge at all. ``` ### What a Strong Answer Covers - A definition of a weighted graph, with examples of what weights model - At least two representations, and where the weight is stored in each - The memory and operation costs of each representation, and how graph density decides between them - Pitfalls such as marking a missing edge, zero or negative weights, and parallel edges - How the representation fits the algorithms that use weights ### Follow-up Questions - Which representation would you use to run Dijkstra's algorithm on a road network with 10 million intersections, and why? - How do you store an undirected weighted graph in adjacency lists so the two copies of an edge never disagree? - Why does Kruskal's algorithm usually work from an edge list? - How would you store a graph that has several edges with different weights between the same two nodes?

Overview: Explain what a weighted graph is and how its edge weights are stored in common graph representations. Tests understanding of the memory and lookup trade-offs between representations and how the choice affects shortest-path and spanning-tree algorithms.

General logo
General
Nov 24, 2026
easySoftware EngineerOtherSoftware Engineering Fundamentals
0
0

What are weighted graphs, and how are they represented in data structures? Describe the common ways to store one in memory and where the weights live in each.

What a Strong Answer Covers Guidance

  • A definition of a weighted graph, with examples of what weights model
  • At least two representations, and where the weight is stored in each
  • The memory and operation costs of each representation, and how graph density decides between them
  • Pitfalls such as marking a missing edge, zero or negative weights, and parallel edges
  • How the representation fits the algorithms that use weights

Follow-up Questions Guidance

  • Which representation would you use to run Dijkstra's algorithm on a road network with 10 million intersections, and why?
  • How do you store an undirected weighted graph in adjacency lists so the two copies of an edge never disagree?
  • Why does Kruskal's algorithm usually work from an edge list?
  • How would you store a graph that has several edges with different weights between the same two nodes?