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¶
3. Sorting algorithms¶
4. Linear and binary search¶
5. Numerical algorithms¶
| Algorithm | Python | C++ | Java |
|---|---|---|---|
ChangeOfBase |
|||
BasicPrimalityTest |
|||
PrimalityTest |
|||
SieveOfEratosthenes |
|||
EuclideanAlgorithm |
11. Input size¶
12. Running time¶
13. Correctness¶
14. Recursion¶
15. Recurrences¶
17. Recursive algorithms¶
| Algorithm | Python | C++ | Java |
|---|---|---|---|
SumIterative, RecursiveSum and RecursiveSumLinear |
|||
MergeSort and Merge |
|||
RecursiveBinarySearch |
|||
BruteForceMaximumSubarray |
|||
FindMaximumSubarray and FindMaxCrossingSubarray |
|||
Kadane |