Skip to content

The course notebooks

Every chapter on algorithms has its Colab notebooks, one per language: Python, C++ and Java; every algorithm also has its own notebook, in the three languages (the one opened by the buttons below the pseudo-code). On the pages of the website the algorithms are written in pseudo-code; in the notebooks the same algorithms are implemented (with arrays indexed from 0) and run on the examples of the pages, with step-by-step traces and «Try it» cells to run them on your own data.

  • What Colab is. Google Colab runs the notebooks in the browser, on a Google machine: all you need is a Google account, nothing is installed on your computer.
  • How to open one. Click a badge in the table, or the «Run in Colab» buttons below the pseudo-code on the chapter pages. To keep your changes: File → Save a copy in Drive.
  • How to run it. Runtime → Run all (Ctrl+F9) runs all the cells from top to bottom; a single cell runs with Shift+Enter.
  • C++ and Java. Each program is written to a file by one cell (%%writefile) and compiled and run in the next one (g++, javac, java): everything happens inside Colab.
  • One notebook per language. The three notebooks of a chapter contain the same algorithms and print the same results: pick the language you prefer, or compare them.

The .ipynb link opens the notebook on GitHub, where you can download it (Download raw file) to use it with Jupyter on your own computer.

The whole chapter

One notebook per chapter and per language, with all the algorithms of the chapter.

One notebook per algorithm

The same algorithms, one per notebook: each notebook contains only what that algorithm needs (code, run on the examples of the chapter, «Try it»). The algorithms that the chapter treats together (for example MergeSort and its procedure Merge) are in the same notebook.

2. Pseudo-code

Algorithm Python C++ Java
FindMaximum Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
CountPositive Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
IsSorted Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
ScalarProduct Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
ReverseArray Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)

3. Sorting algorithms

Algorithm Python C++ Java
InsertionSort Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
ExchangeSort Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
SelectionSort Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
Algorithm Python C++ Java
LinearSearch Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
BinarySearch Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)

5. Numerical algorithms

Algorithm Python C++ Java
ChangeOfBase Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
BasicPrimalityTest Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
PrimalityTest Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
SieveOfEratosthenes Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
EuclideanAlgorithm Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)

11. Input size

Algorithm Python C++ Java
SumArray Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)

12. Running time

Algorithm Python C++ Java
FindMaximum Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
InsertionSort Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
ChangeToBase2 Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
PrimalityTest Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)

13. Correctness

Algorithm Python C++ Java
FindMaximum Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
InsertionSort Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
BinarySearch Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
EuclideanAlgorithm Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)

14. Recursion

Algorithm Python C++ Java
Factorial Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
Fib Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
IterativeFib Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
RecursiveGCD Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
FastPower Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
Hanoi Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)

15. Recurrences

Algorithm Python C++ Java
RecursiveSum Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)

17. Recursive algorithms

Algorithm Python C++ Java
SumIterative, RecursiveSum and RecursiveSumLinear Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
MergeSort and Merge Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
RecursiveBinarySearch Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
BruteForceMaximumSubarray Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
FindMaximumSubarray and FindMaxCrossingSubarray Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
Kadane Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)

18. Recursive versus iterative algorithms

Algorithm Python C++ Java
SumExplicitStack Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
MergeSortBottomUp Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
PowerIt Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
Kadane Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
FibRec, FibMemo and FibIt Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
GCDRec and GCDIt Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)
RecBinarySearch and ItBinarySearch Open in Colab (Python) Open in Colab (C++) Open in Colab (Java)