Algorithms and projects

Measuring how fast code is, sorting and searching, useful patterns for lists, and two complete programs that bring the course together.

About 9 hours of study

Learning objectives

Lessons

  1. 1

    How fast is your code? Intermediate

    Count the steps a program takes, compare linear and binary search, and meet O(n) and O(n²).

  2. 2

    Sorting algorithms Intermediate

    Watch bubble sort and selection sort move values, then sort anything with sorted() and a key.

  3. 3

    Two pointers and sliding windows Intermediate

    Solve list problems in one pass by moving two positions through the data.

  4. 4

    Project: a grade book Intermediate

    Combine dictionaries, functions, loops and formatting into one small, complete program.

  5. 5

    Project: a shop inventory Intermediate

    Design a small class around a dictionary, with methods that keep the stock correct.

  6. 6

    What comes next

    Review what you have learned, try one last classic program, and choose your next course.

Module practice

Module quiz

1. Doubling the input of an O(n²) program makes it take about how much longer?
2. Why must a list be sorted for binary search?
3. What is wrong with nums = nums.sort()?
4. What does a sliding window avoid?
5. In a two-pointer search on a sorted list, the sum is too large. Which pointer moves?
6. Why keep calculation and printing in separate functions?

‹ Recursion and data structuresFinal assessment ›