A graph is a set of nodes connected by edges, and it is the most general structure in this course. Trees are graphs with no cycles, but a graph can have loops, one-way links and weights on its edges. Maps and routes, social networks, web pages that link to each other and task dependencies are all graphs, so many real problems come down to a graph question.
This module starts with how to represent a graph: the adjacency list and the adjacency matrix, and why the right choice depends on how many edges the graph has. It then covers the two core traversals, breadth-first search (BFS), which uses a queue and explores level by level, and depth-first search (DFS), which uses a stack or recursion and goes as deep as possible first.
The second half puts them to work. Number of Islands shows that a grid is a graph in disguise, and that counting connected regions is a traversal problem. Dijkstra's algorithm then finds the shortest path in a weighted graph, using the priority queue from the previous module. Watch the lessons in order, then continue on to Dynamic Programming.
The three main ways to store a graph, each explained in detail with its benefits and drawbacks, including time and space complexity.
BFS and DFS step by step: queues versus stacks, the traversal order each one produces, and when to use breadth-first or depth-first search.
The popular interview problem solved with both DFS and BFS, showing how to apply graph traversal to a grid.
Dr Mike Pound explains how Dijkstra's algorithm finds the shortest path between two points in a graph.