Graph Algorithms the Fun Way

Powerful Algorithms Decoded, Not Oversimplified

Enter the wonderful world of graph algorithms, where you’ll learn when and how to apply these highly useful data structures to solve a wide range of fascinating (and fantastical) computational problems.

Graph Algorithms the Fun Way offers a refreshing approach to complex concepts by blending humor, imaginative examples, and practical Python implementations to reveal the power and versatility of graph based problem-solving in the real world. Through clear diagrams, engaging examples, and Python code, you’ll build a solid foundation for addressing graph problems in your own projects.

Explore a rich landscape of cleverly constructed scenarios where:

  • Hedge mazes illuminate depth-first search
  • Urban explorations demonstrate breadth-first search
  • Intricate labyrinths reveal bridges and articulation points
  • Strategic planning illustrates bipartite matching

From fundamental graph structures to advanced topics, you will:
  • Implement powerful algorithms, including Dijkstra’s, A*, and Floyd-Warshall
  • Tackle puzzles and optimize pathfinding with newfound confidence
  • Uncover real-world applications in social networks  and transportation systems
  • Develop robust intuition for when and why to apply specific graph techniques

Delve into topological sorting, minimum spanning trees, strongly connected components, and random walks. Confront challenges like graph coloring and the traveling salesperson problem.

Prepare to view the world through the lens of graphs—where connections reveal insights and algorithms unlock new possibilities.
Introduction

Part I: Graph Basics
Chapter 1: Representing Graphs
Chapter 2: Neighbors and Neighborhoods
Chapter 3: Paths Through Graphs

Part II: Search and Shortest Paths
Chapter 4: Depth-First Search
Chapter 5: Breadth-First Search
Chapter 6: Solving Puzzles
Chapter 7: Shortest Paths
Chapter 8: Heuristic Guided Searches

Part III: Connectivity and Ordering
Chapter 9: Topological Sort
Chapter 10: Minimum Spanning Tree
Chapter 11: Bridges and Articulation Points
Chapter 12: Strongly Connected Components
Chapter 13: Random Walks

Part IV: Max-Flow and Bipartite Matching
Chapter 14: Max-Flow Algorithms
Chapter 15: Bipartite Graphs and Bipartite Matching

Part V: Hard Graph Problems
Chapter 16: Graph Coloring
Chapter 17: Independent Sets and Cliques
Chapter 18: Tours Through Graphs

Appendix A: Constructing Graphs
Appendix B: Priority Queue
Appendix C: Union-Find

Conclusion
Jeremy Kubica is an engineering director working at the intersection of computer science and astrophysics. He holds a PhD in robotics from Carnegie Mellon University and a BS in computer science from Cornell University. He is the author of The CS Detective, Data Structures the Fun Way (both from No Starch Press), and Computational Fairy Tales.

About

Enter the wonderful world of graph algorithms, where you’ll learn when and how to apply these highly useful data structures to solve a wide range of fascinating (and fantastical) computational problems.

Graph Algorithms the Fun Way offers a refreshing approach to complex concepts by blending humor, imaginative examples, and practical Python implementations to reveal the power and versatility of graph based problem-solving in the real world. Through clear diagrams, engaging examples, and Python code, you’ll build a solid foundation for addressing graph problems in your own projects.

Explore a rich landscape of cleverly constructed scenarios where:

  • Hedge mazes illuminate depth-first search
  • Urban explorations demonstrate breadth-first search
  • Intricate labyrinths reveal bridges and articulation points
  • Strategic planning illustrates bipartite matching

From fundamental graph structures to advanced topics, you will:
  • Implement powerful algorithms, including Dijkstra’s, A*, and Floyd-Warshall
  • Tackle puzzles and optimize pathfinding with newfound confidence
  • Uncover real-world applications in social networks  and transportation systems
  • Develop robust intuition for when and why to apply specific graph techniques

Delve into topological sorting, minimum spanning trees, strongly connected components, and random walks. Confront challenges like graph coloring and the traveling salesperson problem.

Prepare to view the world through the lens of graphs—where connections reveal insights and algorithms unlock new possibilities.

Table of Contents

Introduction

Part I: Graph Basics
Chapter 1: Representing Graphs
Chapter 2: Neighbors and Neighborhoods
Chapter 3: Paths Through Graphs

Part II: Search and Shortest Paths
Chapter 4: Depth-First Search
Chapter 5: Breadth-First Search
Chapter 6: Solving Puzzles
Chapter 7: Shortest Paths
Chapter 8: Heuristic Guided Searches

Part III: Connectivity and Ordering
Chapter 9: Topological Sort
Chapter 10: Minimum Spanning Tree
Chapter 11: Bridges and Articulation Points
Chapter 12: Strongly Connected Components
Chapter 13: Random Walks

Part IV: Max-Flow and Bipartite Matching
Chapter 14: Max-Flow Algorithms
Chapter 15: Bipartite Graphs and Bipartite Matching

Part V: Hard Graph Problems
Chapter 16: Graph Coloring
Chapter 17: Independent Sets and Cliques
Chapter 18: Tours Through Graphs

Appendix A: Constructing Graphs
Appendix B: Priority Queue
Appendix C: Union-Find

Conclusion

Author

Jeremy Kubica is an engineering director working at the intersection of computer science and astrophysics. He holds a PhD in robotics from Carnegie Mellon University and a BS in computer science from Cornell University. He is the author of The CS Detective, Data Structures the Fun Way (both from No Starch Press), and Computational Fairy Tales.

Three Penguin Random House Authors Win Pulitzer Prizes

On Monday, May 5, three Penguin Random House authors were honored with a Pulitzer Prize. Established in 1917, the Pulitzer Prizes are the most prestigious awards in American letters. To date, PRH has 143 Pulitzer Prize winners, including William Faulkner, Eudora Welty, Josh Steinbeck, Ron Chernow, Anne Applebaum, Colson Whitehead, and many more. Take a look at our 2025 Pulitzer Prize

Read more

Books for LGBTQIA+ Pride Month

In June we celebrate Lesbian, Gay, Bisexual, Transgender, Queer, Intersex, and Asexual + (LGBTQIA+) Pride Month, which honors the 1969 Stonewall riots in Manhattan. Pride Month is a time to both celebrate the accomplishments of those in the LGBTQ+ community and recognize the ongoing struggles faced by many across the world who wish to live

Read more