Skip to main content

Graph Algorithms

Learn Graph Algorithms (Algorithms, Programming Fundamentals) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

A graph is a collection of nodes (vertices) connected by edges . Graphs model networks: social connections, road maps, web pages, and more. The most common way to represent a graph in code is an adjacency list - for each node, keep a list of the nodes it directly connects to. The two fundamental ways to explore (traverse) a graph are: • BFS (Breadth-First Search) - explore level by level, using a Queue. • DFS (Depth-First Search) - explore as deep as possible before backtracking, using a Stack (or recursion).

More lessons in Algorithms