Overview

1 Starting a fabulous adventure

This chapter introduces the book’s central idea: algorithms are finite procedures for solving problems, and data structures are organized ways of storing information. What makes them “fabulous” is not just correctness, but qualities like tackling real-world problems creatively, producing counterintuitive but powerful results, revealing common patterns across many domains, and making code easier to understand by focusing on meaning rather than low-level mechanics. The chapter also frames the author’s goal of moving beyond standard undergraduate topics into practical and unusual techniques that expand a programmer’s toolkit and sense of discovery.

The chapter then defines complexity as the relationship between problem size and resource cost, especially time and memory, and uses big-O notation to describe common growth rates. It contrasts constant, logarithmic, linear, quasilinear, quadratic, exponential, and factorial behavior, emphasizing how quickly costs can rise as inputs grow. At the same time, it warns that asymptotically better algorithms are not always the best choice in practice, because real performance depends on typical input sizes and actual usage patterns, not just worst-case theory.

As a concrete warmup, the chapter builds an immutable linked list in C# and shows how to reverse it by iterating through the list and pushing items onto a new list. This example highlights both the simplicity and the hidden pitfalls of small designs, including nullable representations, automatically generated equality behavior, and accidental quadratic performance in string concatenation. The chapter closes by previewing the adventures ahead: unusual twists on familiar structures, techniques like persistence and memoization, algorithms used in developer tools, and tools for randomness, probability, and statistical inference.

A graph comparing the growth curves for logarithmic, linear, quasilinear, quadratic, and exponential growth. The logarithmic curve is the shallowest, growing slowly, and the exponential curve is the fastest.

Summary

  • There are lots of books about standard data structures, such as lists, trees, and hash tables, and the algorithms for sorting and searching them. Lots of implementations of them are already in class libraries. In this book, we’ll look at the less well-known, more off-the-beaten-path data structures and algorithms that I had to learn about during my career. I chose the topics that I found the most fabulous: the ones that are counterintuitive or seemingly magical or that push the boundaries of languages.
  • I had to learn about almost all the topics in this book when I needed a new tool in my toolbox to solve a job-related problem. I hope that this book saves you from having to read all the abstruse papers I had to digest if you too have such a problem to solve.
  • More important to me, all these fabulous adventures gave me a deeper appreciation for what computer programmers are capable of doing. They changed how I think about the craft of programming. I had a lot of fun along the way, and I hope you do too.
  • Asymptotic complexity measures how well a solution scales with the size of the problem you’re throwing at it. You generally want algorithms to be better than quadratic if you want them to scale to large problems.
  • Complexity analysis can be subtle. It’s important to remember that time is not the only resource users care about; they might also have opinions about whether avoiding a bad worst-case scenario is more or less important than achieving excellent average performance.
  • If problems are always small, asymptotic complexity matters less.
  • Reversing a linked list is straightforward if you have an immutable list. Chapter 2 looks at other kinds of immutable lists.

FAQ

What makes data structures and algorithms “fabulous” in this chapter?They become fabulous when they help solve real problems, produce counterintuitive results, apply the same idea across different domains, emphasize meaning over mechanism, reveal hidden implementation tricks, make good use of language features, challenge your assumptions, connect to theory, and are simply fun to build and use.
What is the difference between an algorithm and a data structure?An algorithm is a finite sequence of steps used to solve a problem. A data structure is a way to store and organize information in a structured manner.
What does “complexity” mean in the context of algorithms?Complexity describes the relationship between the size of a problem and the cost of solving it, measured in time, memory, or another resource.
What is big O notation used for?Big O notation is used to describe how an algorithm’s cost grows as the problem size grows, especially for comparing scalability.
What are some common complexity classes introduced in the chapter?The chapter introduces O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n) quasilinear, O(n2) quadratic, and O(2n) / O(n!) exponential or factorial complexity.
Why is a quadratic algorithm often considered a problem?Quadratic algorithms get much more expensive as input size grows; if the problem size doubles, the cost roughly quadruples, which can make them impractical for large inputs.
Why does the chapter warn that asymptotically better algorithms are not always better in practice?Because scalability matters most for large inputs. For small or typical inputs, a simpler algorithm with worse worst-case complexity may still be faster and more practical.
How is an immutable linked list represented in this chapter?It is represented as either an empty list or a value followed by a tail linked list, using a recursive definition. The example uses a C# record type with a value and a tail reference.
What is the performance of reversing an immutable linked list in the example?The reverse method is O(n) in both time and extra memory, because it walks through the list once and builds a new reversed list by pushing each item.
What topics does the chapter say are coming next in the book?It says the book will explore traditional structures with twists, such as persistent and memoized structures, list reordering, a constant-time-looking linked list reversal trick, backtracking and graph coloring, code formatting, tree unification and anti-unification, probability and statistical inference tools, and some theory connections like category theory.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Fabulous Adventures in Data Structures and Algorithms ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Fabulous Adventures in Data Structures and Algorithms ebook for free