- Tutorials
- DSA Tutorial
- Graphs
Graphs
4 lessonsAbout 24 minutesAdvanced
This part of the DSA Tutorial runs from Graphs and How to Represent Them through to Dijkstra's Algorithm. There are 4 lessons here, and working through them takes about 24 minutes at a steady pace.
It follows on from Tries, so finish that first if you have not already — the examples below assume you are comfortable with it.
Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.
- 1Graphs and How to Represent ThemA graph is nodes connected by edges. Learn adjacency lists versus matrices in JavaScript, when each is right, and how to spot a graph problem that is not described as one.
- 2Graph Traversal: BFS and DFSBreadth-first search finds shortest paths; depth-first explores deeply. Learn both in JavaScript, why every graph traversal needs a visited set, and how to choose between them.
- 3Topological SortTopological sort orders tasks so every dependency comes first. Learn Kahn's algorithm in JavaScript, how it detects impossible cycles, and where build tools use it.
- 4Dijkstra's AlgorithmDijkstra finds the cheapest path when edges have weights, where BFS only finds the fewest edges. Learn the implementation in JavaScript with a priority queue, and why negative weights break it.
