liveBook · Manning

Algorithm

As explained in Fabulous Adventures in Data Structures and Algorithms

An algorithm is a finite, precise procedure for solving a problem or computing a result.

An algorithm is a finite sequence of steps that solves a problem. It need not be complicated, deterministic, or executed by a computer: a step may say “choose a random number.” Data structures organize information; algorithms use that information to get a result. section 1.1

A simple procedure with substantial work

To choose an ad, estimate the revenue each candidate would generate for a user, then show the one with the highest expected revenue. The procedure is easy to state even if evaluating every candidate takes considerable computation. section 1.1

A useful algorithm solves a real problem, but its cost matters too. Complexity relates problem size to resources such as time or memory. Big O notation describes how that cost grows: reading the first array value is O(1), while summing n integers is O(n). A logarithmic cost grows much more slowly as input size increases. section 1.1

Figure 1.1 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.

Compare growth curves before choosing between approaches: logarithmic growth stays shallow, while exponential growth rises fastest. section 1.1

The same algorithmic idea can cross domains. Backtracking search can find an item in a tree, color a map, or solve Sudoku; related search also appears in automatic code formatting. Conversely, a familiar problem can invite an unusual approach: immutable data structures can support undo and redo, and a basic Game of Life implementation offers a starting point for finding optimizations. section 1.0 section 4.1

How Fabulous Adventures in Data Structures and Algorithms covers it

How deep it goes
Defines algorithms and their complexity, then illustrates cost growth; it does not derive a general implementation method.
Examples
Uses ad selection, array access, integer summation, map coloring, Sudoku, and Game of Life optimization.
What it assumes
Assumes familiarity with programming while defining algorithms, data structures, and complexity from first principles.
What you can do after
Evaluate/understand it by identifying a procedure and comparing how its resource cost grows with problem size.
How it connects
Connects algorithms to data structures, big O notation, backtracking, immutable data structures, and memoization.

Also explained in

Compare how 2 books explain algorithm →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fabulous Adventures in Data Structures and Algorithms. The section links point to the parts of the book it draws on.