The CS Detective

An Algorithmic Tale of Crime, Conspiracy, and Computation

Look inside
Meet Frank Runtime. Disgraced ex-detective. Hard-boiled private eye. Search expert.

When a robbery hits police headquarters, it’s up to Frank Runtime and his extensive search skills to catch the culprits. In this detective story, you’ll learn how to use algorithmic tools to solve the case. Runtime scours smugglers’ boats with binary search, tails spies with a search tree, escapes a prison with depth-first search, and picks locks with priority queues. Joined by know-it-all rookie Officer Notation and inept tag-along Socks, he follows a series of leads in a best-first search that unravels a deep conspiracy. Each chapter introduces a thrilling twist matched with a new algorithmic concept, ending with a technical recap.

Perfect for computer science students and amateur sleuths alike, The CS Detective adds an entertaining twist to learning algorithms.

Follow Frank’s mission and learn:
–The algorithms behind best-first and depth-first search, iterative deepening, parallelizing, binary search, and more
–Basic computational concepts like strings, arrays, stacks, and queues
–How to adapt search algorithms to unusual data structures
–The most efficient algorithms to use in a given situation, and when to apply common-sense heuristic methods
Acknowledgments
A Note to Readers
Chapter 1: Search Problems
Chapter 2: Exhaustive Search for an Informant
Chapter 3: Arrays and Indexes on a Criminal's Farm
Chapter 4: Strings and Hidden Messages
Chapter 5: Binary Search for a Smuggler's Ship
Chapter 6: Binary Search for Clues
Chapter 7: Adapting Algorithms for a Daring Escape
Chapter 8: Socks: An Interlude and an Introduction
Chapter 9: Backtracking to Keep the Search Going
Chapter 10: Picking Locks with Breadth-First Search
Chapter 11: Depth-First Search in an Abandoned Prison
Chapter 12: Cafeteria Stacks and Queues
Chapter 13: Stacks and Queues for Search
Chapter 14: Let's Split Up: Parallelized Search
Chapter 15: Iterative Deepening Can Save Your Life
Chapter 16: Inverted Indexes: The Search Narrows
Chapter 17: A Binary Search Tree Trap
Chapter 18: Building Binary Search Ladders
Chapter 19: Binary Search Trees for Suspects
Chapter 20: Adding Suspects to the Search Tree
Chapter 21: The Binary Search Tree Property
Chapter 22: Tries for Paperwork
Chapter 23: Best-First Search: A Detective's Most Trusted Tool
Chapter 24: Priority Queues for Investigations
Chapter 25: Priority Queues for Lock Picking
Chapter 26: Heuristics in Search
Chapter 27: Heaps in Politics and Academia
Chapter 28: Difficult Search Problems
Chapter 29: Search Termination
Epilogue
Jeremy Kubica is a principal engineer at Google working on machine learning and algorithms. He has a PhD in robotics from Carnegie Mellon University and a BS in computer science from Cornell University. Kubica is the author of the popular Computational Fairy Tales blog.

About

Meet Frank Runtime. Disgraced ex-detective. Hard-boiled private eye. Search expert.

When a robbery hits police headquarters, it’s up to Frank Runtime and his extensive search skills to catch the culprits. In this detective story, you’ll learn how to use algorithmic tools to solve the case. Runtime scours smugglers’ boats with binary search, tails spies with a search tree, escapes a prison with depth-first search, and picks locks with priority queues. Joined by know-it-all rookie Officer Notation and inept tag-along Socks, he follows a series of leads in a best-first search that unravels a deep conspiracy. Each chapter introduces a thrilling twist matched with a new algorithmic concept, ending with a technical recap.

Perfect for computer science students and amateur sleuths alike, The CS Detective adds an entertaining twist to learning algorithms.

Follow Frank’s mission and learn:
–The algorithms behind best-first and depth-first search, iterative deepening, parallelizing, binary search, and more
–Basic computational concepts like strings, arrays, stacks, and queues
–How to adapt search algorithms to unusual data structures
–The most efficient algorithms to use in a given situation, and when to apply common-sense heuristic methods

Table of Contents

Acknowledgments
A Note to Readers
Chapter 1: Search Problems
Chapter 2: Exhaustive Search for an Informant
Chapter 3: Arrays and Indexes on a Criminal's Farm
Chapter 4: Strings and Hidden Messages
Chapter 5: Binary Search for a Smuggler's Ship
Chapter 6: Binary Search for Clues
Chapter 7: Adapting Algorithms for a Daring Escape
Chapter 8: Socks: An Interlude and an Introduction
Chapter 9: Backtracking to Keep the Search Going
Chapter 10: Picking Locks with Breadth-First Search
Chapter 11: Depth-First Search in an Abandoned Prison
Chapter 12: Cafeteria Stacks and Queues
Chapter 13: Stacks and Queues for Search
Chapter 14: Let's Split Up: Parallelized Search
Chapter 15: Iterative Deepening Can Save Your Life
Chapter 16: Inverted Indexes: The Search Narrows
Chapter 17: A Binary Search Tree Trap
Chapter 18: Building Binary Search Ladders
Chapter 19: Binary Search Trees for Suspects
Chapter 20: Adding Suspects to the Search Tree
Chapter 21: The Binary Search Tree Property
Chapter 22: Tries for Paperwork
Chapter 23: Best-First Search: A Detective's Most Trusted Tool
Chapter 24: Priority Queues for Investigations
Chapter 25: Priority Queues for Lock Picking
Chapter 26: Heuristics in Search
Chapter 27: Heaps in Politics and Academia
Chapter 28: Difficult Search Problems
Chapter 29: Search Termination
Epilogue

Author

Jeremy Kubica is a principal engineer at Google working on machine learning and algorithms. He has a PhD in robotics from Carnegie Mellon University and a BS in computer science from Cornell University. Kubica is the author of the popular Computational Fairy Tales blog.

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