Tags

Directed Graphs

Directed Graphs

1 lesson
5 problems
1 community item

directed-graphs

Data Structures

1 lesson

Graphs: Representation Basics

Free
Beginner

55 min

2 prereqs

A social network is a graph, a road map is a graph, an `import` graph in your codebase is a graph, and so is the dependency tree of a package manager. The reason graphs feel everywhere is that they are the most general relationship structure: just vertices and edges, with no required root, no acyclic constraint, and no fixed branching factor. **Graphs: Representation Basics** is where you stop drawing them on whiteboards and start storing them in code. This lesson defines the core vocabulary (vertex, edge, degree, path, cycle, directed and undirected, connected and disconnected) and walks through the three canonical representations: an adjacency list backed by a hash map of vertex to neighbors, an adjacency matrix for dense graphs and `O(1)` edge-existence queries, and an edge list for algorithms that just iterate over edges. You will analyze the space and time trade-offs of each so you can pick the right one before writing any traversal logic. In **Hash Map (Dictionary) Basics**, you saw that a hash map maps keys to values in expected `O(1)`; an adjacency list is exactly that, mapping each vertex to its list of neighbors. **Queue & Deque** gave you the FIFO machinery that BFS will run on top of these representations once traversal lessons begin. With a graph stored in memory, the algorithms track is where it comes alive: BFS, DFS, shortest paths, connected components, and the rest of the graph algorithm canon.

Not Started

0%

Graphs
Graph Representation
Adjacency List
Adjacency Matrix
Directed Graphs
Undirected Graphs
Data Structures
Beginner
Free

Practice Problems

5 problems

Alien Dictionary

Not Started
Hard

Given a sorted list of words in an alien language, determine the order of characters in the alien alphabet using topological sort.

Graphs
Topological Sort
Directed Graphs
BFS
DFS
Advanced

910

9

Cheapest Flights Within K Stops

Not Started
Medium

Find the cheapest price to fly from a source to a destination with at most k intermediate stops, given a list of flights with prices.

Graphs
Bellman-Ford Algorithm
BFS
Shortest Path
Weighted Graphs
Directed Graphs
Dynamic Programming
Intermediate

250

3

Course Schedule II

Not Started
Medium

Given courses and prerequisites, return a valid order to take all courses (topological ordering), or an empty array if impossible.

Graphs
Topological Sort
BFS
Directed Graphs
Intermediate

635

11

Course Schedule

Free
Not Started
Medium

Given a number of courses and their prerequisites, determine if it is possible to finish all courses (detect if the dependency graph has a cycle).

Graphs
Topological Sort
DFS
BFS
Directed Graphs
Cycle Detection
Intermediate

268

2

Network Delay Time

Not Started
Medium

Given a network of n nodes and weighted directed edges representing signal travel times, find the time it takes for a signal sent from node k to reach all nodes.

Graphs
Dijkstra's Algorithm
Shortest Path
Weighted Graphs
Directed Graphs
Heap
Intermediate

1k

24