liveBook · Manning

Chapter 1: Introduction to algorithms

What you will learn in chapter 1 of Grokking Algorithms, Second Edition

The introduction defines an algorithm and explains why the book focuses on algorithms that speed up tasks or solve interesting problems.

After this chapter you will be able to

Section by section

Introduction

The introduction defines an algorithm and explains why the book focuses on algorithms that speed up tasks or solve interesting problems.

Key terms: algorithm, binary search

1.1 What you’ll learn about performance

The section explains why choosing an algorithm or data structure requires understanding tradeoffs, even when implementations are readily available.

Key terms: tradeoffs, algorithm, data structure

1.2 What you’ll learn about solving problems

The section previews problems the book will address and states the background needed to follow it.

Key terms: basic algebra, programming language, Python

1.3 Binary search

Introduces binary search as a way to find an item in a sorted list and contrasts it with guessing one item at a time.

Key terms: binary search, sorted list, position, null, simple search, guess

1.4 A better way to search

This section explains how binary search narrows a sorted search space by half at each step, why that makes searches fast, and how a Python function tracks the remaining range.

Key terms: binary search, middle number, sorted order, phone book, worst case, simple search, log2 n, logarithms, binary_search, sorted array

1.5 Running time

This section compares how the maximum number of guesses grows for one-by-one search and binary search, introducing linear and logarithmic running time.

Key terms: running time, linear time, logarithmic time, log time, binary search

1.6 Big O notation

This section introduces Big O notation as a way to describe algorithm speed and explains why that is useful when working with other people’s algorithms.

Key terms: Big O notation, algorithm, running time

1.7 Algorithm running times grow at different rates

This section uses simple and binary search to show why an algorithm’s running-time growth matters and introduces big O notation for expressing that growth.

Key terms: simple search, binary search, run time, big O notation, O(n), O(log n), operations

1.8 Visualizing different big O run times

A 16-box grid illustrates how doing one box per operation takes linear time, while doubling the number of boxes per fold takes logarithmic time.

Key terms: operation, running time, O(n), O(log n)

1.9 Big O establishes a worst-case run time

The section explains why a fast individual search does not change simple search’s worst-case Big O run time.

Key terms: simple search, O(n), O(1), best-case scenario, worst-case scenario

1.10 Some common big O run times

Introduces five common big O run times, compares how they grow, and emphasizes that big O describes growth rather than elapsed seconds.

Key terms: O(log n), O(n), O(n * log n), O(n2), O(n!), log time, operations, big O notation, number of operations, size of the input

1.11 The traveling salesperson

The section uses the traveling salesperson problem to show how checking every possible route produces factorial running time and why an approximate answer may be needed.

Key terms: traveling salesperson problem, permutations, n!, factorial time, O(n!), no fast known algorithm, approximate solution

1.12 Recap

The recap connects binary search’s growing advantage over simple search to measuring algorithm time by growth using big O notation.

Key terms: binary search, simple search, O(log n), O(n), algorithm speed, algorithm times, growth, big O notation

Where this is used later

Concepts explained in this chapter

Chapter 2: Selection sort →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.