diff --git a/README.md b/README.md index f3d96304c4797869646388ddf9c8d7197c65e37f..8e8e609c6fdc93109d6cfad7a051bf76db43f275 100644 --- a/README.md +++ b/README.md @@ -1,112 +1,249 @@ # UE5 Fundamentals of Algorithms +### Bachelor of Science in Data Science for Responsible Business Instructor: [Romain Vuillemot](romain.vuillemot@ec-lyon.fr) -## Course Description +<div style="text-align: center;"> + <img src="figures/logo-ecl.png" style="width:250px; display:inline-block; vertical-align:middle;"> + <img src="figures/logo-emlyon.png" style="width:75px; display:inline-block; vertical-align:middle;"> +</div> + +## Course description - Basis of algorithms (sorting, search) and data structure (arrays, lists) - Justification of the choice of data structures - Calculate the complexity of an algorithm - Optimize algorithms -- Writing programs using algorithms +- Write advanced programs using efficient algorithms and data structures + +## Course material + +- [lectures](https://gitlab.ec-lyon.fr/rvuillem/algo-bsc/-/tree/main/lectures): lectures presented in class + +- [notebooks](https://gitlab.ec-lyon.fr/rvuillem/algo-bsc/-/tree/main/notebooks): notebook of the lectures with editable code + +- [📝 exercises](https://gitlab.ec-lyon.fr/rvuillem/algo-bsc/-/tree/main/exercises): lab exercices + +- [solutions](https://gitlab.ec-lyon.fr/rvuillem/algo-bsc/-/tree/main/solutions): solutions of lab exercises + +- [📖 books](https://gitlab.ec-lyon.fr/rvuillem/algo-bsc/-/tree/main/books): books and ressources to prepare the lecture & learn more + + +## Course outline and reading list + +### [Lecture 1 - **Data structures and complexity**](lectures/01-data-structures-complexity%20slides.pdf) + +- Introduction to data structures +- Asymptotic analysis (Big O notation) +- Data structures +- Trade-offs between time/space complexity and different data structures +- Empirical calculation of complexity + +<details> +<summary>📖 </summary> + +- [Python for Everybody](books/pythonlearn.pdf) chapter 9 (dictionnaries), chapter 10 (tuples) + +</details> + +### [Lab 1 - **Data structures and complexity**](exercices/02-recurion-exercises.ipynb) + +--- + +### Lecture 2 - **Recursion and lists** + +- Definition and principles of recursion +- Base cases and recursive cases +- Recursion vs. iteration +- Tail recursion +- Lists, Search +- Introduction to lists (arrays vs. linked lists) +- Operations on lists (insertion, deletion, traversal) +- Searching algorithms (linear, binary) + +<details> +<summary>📖 </summary> +- [Think Python](books/thinkpython2.pdf) chapter 11 (lists), chapter 12 (tuples) +- [Python for Everybody](books/pythonlearn.pdf) chapter 8 (lists) and Real Python [lists](https://realpython.com/python-list/) +- [sorts](https://realpython.com/sorting-algorithms-python/). +- [Think Python](books/thinkpython2.pdf) chapter 5 (Conditionals and recursion) and Real Python [recursion](https://realpython.com/python-recursion/). +</details> + +### Lab 2 - **Recursion and lists** -## Course Material +--- +### Assignment 1 +--- -- [lectures](https://gitlab.ec-lyon.fr/rvuillem/algo-bsc/-/tree/main/lectures): pdf of the lectures +### Lecture 3 - **Stacks and queues** -- [notebooks](https://gitlab.ec-lyon.fr/rvuillem/algo-bsc/-/tree/main/notebooks): notebook of the lectures +- Definition and characteristics of stacks and queues +- Stack operations (push, pop, peek) +- Queue operations (enqueue, dequeue, peek) +- Applications -- [exercises](https://gitlab.ec-lyon.fr/rvuillem/algo-bsc/-/tree/main/exercises): exercises +<details> +<summary>📖 </summary> -- [solutions](https://gitlab.ec-lyon.fr/rvuillem/algo-bsc/-/tree/main/solutions): solutions of exercises +- 📖 Chapter 1.2.1 (Queue/Stacks), [Open Data Structures](pdf/ods-python.pdf) +- 📝 Quizz 1 -- [pdf](https://gitlab.ec-lyon.fr/rvuillem/algo-bsc/-/tree/main/pdf): books (pdf) +</details> -## Outline and Reading List -### Lecture 1 - **Data structures and complexity** +### Lab 3 - **Stacks and queues** -📖 [Python for Everybody](pdf/pythonlearn.pdf) chapter 9 (dictionnaries), chapter 10 (tuples) +--- -### Lecture 2 - **Recursion** +### Lecture 4 - **Priority queues** -📖 [Think Python](pdf/thinkpython2.pdf) chapter 5 (Conditionals and recursion) and Real Python [recursion](https://realpython.com/python-recursion/). +- Definition and characteristics of priority queues +- Comparison with regular queues (FIFO) and stacks (LIFO) +- Min/Max-priority queues +- Binary heaps -### Lecture 3 - **Lists, search, sort** +<details> +<summary>📖 </summary> +</details> -📖 [Think Python](pdf/thinkpython2.pdf) chapter 11 (lists), chapter 12 (tuples), [Python for Everybody](pdf/pythonlearn.pdf) chapter 8 (lists) and Real Python [lists](https://realpython.com/python-list/) and [sorts](https://realpython.com/sorting-algorithms-python/). +### Lab 4 - **Priority queues** -### Lecture 4 - **Programming strategies: divide and conquer** +--- -📖 [Divide & conquer](https://en.wikibooks.org/wiki/Algorithms/Divide_and_Conquer) +### Lecture 5 - **Programming strategies: divide and conquer, greedy** -### Lecture 5 - **Programming strategies: greedy algorithms** +- Recursive, independent problem-solving strategy +- Application to sorting (merge sort, quick sort) and search (binary search) +- Examples: Fibonacci +- Knapsack Problem (greedy) -📖 [Greedy algorithms](https://en.wikibooks.org/wiki/Algorithms/Greedy_Algorithms) +<details> +<summary>📖 </summary> + +- [Divide & conquer](https://en.wikibooks.org/wiki/Algorithms/Divide_and_Conquer) + +- [Greedy algorithms](https://en.wikibooks.org/wiki/Algorithms/Greedy_Algorithms) +</details> + +### Lab 5 - **Programming strategies: divide and conquer, greedy** + +--- ### Lecture 6 - **Programming strategies: dynamic programming** -📖 [Dynamic programing](https://en.wikibooks.org/wiki/Algorithms/Dynamic_Programming) +- Definition and characteristics of dynamic programming +- Memoization data structures +- Examples (using dynamic programming): Fibonacci, Knapsack Problem + + +<details> +<summary>📖 </summary> +- [Dynamic programing](https://en.wikibooks.org/wiki/Algorithms/Dynamic_Programming) +</details> + + +### Lab 6 - **Programming strategies: dynamic programming** + +--- + +### Lecture 7 - **Binary trees** + +- Data structures (arrays, adjacency lists) +- Converting between tree representations +- Tree traversal techniques (preorder, inorder, postorder, level-order) + +<details> +<summary>📖 </summary> + +- Chapter I.3 (Binary Search Trees), [Data Structures and Algorithms](pdf/Dsa.pdf) +- Video on [Binary Tree](https://www.youtube.com/watch?v=pkYVOmU3MgA&t=11510s) + +</details> + + +### Lab 7 - **Binary trees** + +--- + +### Lecture 8 - **Trees** + +- Data structures (arrays, adjacency lists) +- Converting between tree representations +- Tree traversal techniques (preorder, inorder, postorder, level-order) + +<details> +<summary>📖 </summary> -### Lecture 7 - **Stacks and queues** +- Chapter 6 (Trees), [Open Data Structures](pdf/ods-python.pdf) +- [Problem Solving with Algorithms](pdf/problemsolving.pdf) chapter 6 (trees and tree algorithms) +- [Data Structures and Algorithms](pdf/Dsa.pdf) chapter 13 (binary trees) + +</details> -📖 Chapter 1.2.1 (Queue/Stacks), [Open Data Structures](pdf/ods-python.pdf) +### Lab 8 - **Trees** -### Lecture 8 - **Binary trees** -📖 [Problem Solving with Algorithms](pdf/problemsolving.pdf) chapter 6 (trees and tree algorithms) +--- -📖 [Data Structures and Algorithms](pdf/Dsa.pdf) chapter 13 (binary trees) +### Lecture 9 - **Graphs** -📝 Quizz 1 + - Introduction to graphs (vertices and edges) + - Types of graphs (directed, undirected, weighted, unweighted) + - Representing graphs as adjacency matrix, adjacency list + - Graph properties (connectivity, cycles) -### Lecture 9 - **Binary trees traversals** +<details> +<summary>📖 </summary> -📖 [Problem Solving with Algorithms](pdf/problemsolving.pdf) chapter 6.7 (trees traversal) +- [Problem Solving with Algorithms](pdf/problemsolving.pdf) chapter 6.7 (trees traversal) -📖 [Data Structures and Algorithms](pdf/Dsa.pdf) chapter 14 (traversing trees) +- [Data Structures and Algorithms](pdf/Dsa.pdf) chapter 12 (introduction to graphs) -📝 Quizz 2 +- [Data Structures and Algorithms](pdf/Dsa.pdf) chapter 14 (traversing trees) -### Lecture 10 - **Trees** +</details> -📖 Chapter I.3 (Binary Search Trees), [Data Structures and Algorithms](pdf/Dsa.pdf) +### Lab 9 -Video on [Binary Tree](https://www.youtube.com/watch?v=pkYVOmU3MgA&t=11510s) +--- -📝 Quizz 3 +### Lecture 10 - **Graphs algorithms (1/2)** -### Lecture 11 - **Trees algorithms** +- Minimum spanning tree algorithms (Prim & Kruskal algorithms) +- Topological sorting +- Graph traversal algorithms (depth-first search, breadth-first search) -📖 Chapter 6 (Trees), [Open Data Structures](pdf/ods-python.pdf) +<details> +<summary>📖 </summary> -📝 Quizz 4 +- .. -### Lecture 12 - **Trees algorithms** +</details> -📝 Quizz 5 +### Lab 10 -### Lecture 13 - **Trees algorithms** +--- -📝 Quizz 6 +### Lecture 11 - **Graphs algorithms (2/2)** -### Lecture 14 - **Graphs** +- Shortest path algorithms (Bellman-Ford & Dijkstra algorithms) -📖 [Data Structures and Algorithms](pdf/Dsa.pdf) chapter 12 (introduction to graphs) +<details> +<summary>📖 </summary> -📝 Quizz 7 +- .. -### Lecture 15 - **Graphs algorithms** +</details> -📝 Quizz 8 +### Lab 11 +--- -📝 [Assignment 1 - Analyzing a dataset](assignments/assignment-01.ipynb) -### Exam (december 5th) +### Exam - Final written exam on paper - 2h diff --git a/pdf/Dsa.pdf b/books/Dsa.pdf similarity index 100% rename from pdf/Dsa.pdf rename to books/Dsa.pdf diff --git a/pdf/Python_Algorithms_Data_Structures.pdf b/books/Python_Algorithms_Data_Structures.pdf similarity index 100% rename from pdf/Python_Algorithms_Data_Structures.pdf rename to books/Python_Algorithms_Data_Structures.pdf diff --git a/pdf/ods-python.pdf b/books/ods-python.pdf similarity index 100% rename from pdf/ods-python.pdf rename to books/ods-python.pdf diff --git a/pdf/problemsolving.pdf b/books/problemsolving.pdf similarity index 100% rename from pdf/problemsolving.pdf rename to books/problemsolving.pdf diff --git a/pdf/pythonlearn.pdf b/books/pythonlearn.pdf similarity index 100% rename from pdf/pythonlearn.pdf rename to books/pythonlearn.pdf diff --git a/pdf/thinkpython2.pdf b/books/thinkpython2.pdf similarity index 100% rename from pdf/thinkpython2.pdf rename to books/thinkpython2.pdf diff --git a/exercises/.ipynb_checkpoints/01-data-structures-complexity-exercises-checkpoint.ipynb b/exercises/.ipynb_checkpoints/01-data-structures-complexity-exercises-checkpoint.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..eb87658d88cb93d1ccc8a931346c7a6bfeccfcba --- /dev/null +++ b/exercises/.ipynb_checkpoints/01-data-structures-complexity-exercises-checkpoint.ipynb @@ -0,0 +1,253 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "a0b1f35b", + "metadata": {}, + "source": [ + "NAME:" + ] + }, + { + "cell_type": "markdown", + "id": "a4e4fad3", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "# Data Structures and Complexity" + ] + }, + { + "cell_type": "markdown", + "id": "a8adef9b", + "metadata": { + "slideshow": { + "slide_type": "skip" + } + }, + "source": [ + "---" + ] + }, + { + "cell_type": "markdown", + "id": "827ebb43-1e5d-4756-83ba-97af3e36b6af", + "metadata": {}, + "source": [ + "_For the following question, if a complexity is needed please pick one in this list_" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b54157fc-f0d5-4689-bf2b-344a608bc5a9", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "list_complexities = [\"O(1)\", \"O(log(n))\", \"O(n)\", \"O(n^2)\", \"O(nlog(n))\", \"O(n^3)\", \"O(2^n)\", \"O(n!)\", \"O(n^n)\"]" + ] + }, + { + "cell_type": "markdown", + "id": "568202fd", + "metadata": { + "slideshow": { + "slide_type": "subslide" + } + }, + "source": [ + "### Exercise 1: Identify the complexity of the following function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "431fe8c1-91d1-40f3-a7a4-f4a3770a4a01", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "def nested_loop_example(L):\n", + " n = len(L)\n", + " for i in range(n):\n", + " for j in range(n):\n", + " print(L[i] + L[j])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e68b3e9a-418f-4950-9f27-18bb0fe90794", + "metadata": { + "deletable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "1a3b054c6051bc0e03a25ef29d1c373b", + "grade": false, + "grade_id": "cell-a06bfe9af33fe998", + "locked": false, + "schema_version": 3, + "solution": true, + "task": false + }, + "tags": [] + }, + "outputs": [], + "source": [ + "# nested_loop_example_complexity = ?\n", + "# YOUR CODE HERE\n", + "raise NotImplementedError()" + ] + }, + { + "cell_type": "markdown", + "id": "612dc873-419b-42c5-be36-0accd03ffa79", + "metadata": {}, + "source": [ + "### Exercise 2: Identify the complexity of the following function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "76102853-e1f3-4717-8a59-1091195a19eb", + "metadata": {}, + "outputs": [], + "source": [ + "def fibonacci_recursive(n):\n", + " if n <= 1:\n", + " return n\n", + " return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dead6a52-7996-4eae-9d2a-f75d5d26bbb7", + "metadata": { + "deletable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "1eadb247ef5c5224aa6800e2d7846174", + "grade": false, + "grade_id": "cell-34e130eb0c6b7e82", + "locked": false, + "schema_version": 3, + "solution": true, + "task": false + }, + "tags": [] + }, + "outputs": [], + "source": [ + "# fibonacci_recursive_complexity = ?\n", + "# YOUR CODE HERE\n", + "raise NotImplementedError()" + ] + }, + { + "cell_type": "markdown", + "id": "aa4a6ce7-e542-4b23-8a10-ca0bf93de041", + "metadata": {}, + "source": [ + "### Exercise 3: Identify the complexity of the following function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "70af3e43-8053-49c9-ba58-346a3e915bdb", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "def binary_search(L, target):\n", + " low, high = 0, len(L) - 1\n", + " while low <= high:\n", + " mid = (low + high) // 2\n", + " if L[mid] == target:\n", + " return mid\n", + " elif L[mid] < target:\n", + " low = mid + 1\n", + " else:\n", + " high = mid - 1\n", + " return -1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9c22866c-b4fc-4228-b0ab-5882d964f5f6", + "metadata": { + "deletable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "5f3471162e0167bb6022ece5eed0a4f7", + "grade": false, + "grade_id": "cell-ea8595a5923fbb0e", + "locked": false, + "schema_version": 3, + "solution": true, + "task": false + }, + "tags": [] + }, + "outputs": [], + "source": [ + "# binary_searche_complexity = ?\n", + "# YOUR CODE HERE\n", + "raise NotImplementedError()" + ] + }, + { + "cell_type": "markdown", + "id": "87b4921b-ef55-4083-b4f1-a3ca5bb7b011", + "metadata": {}, + "source": [ + "### Additional checks (do not change)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e8f2878-ce5f-4cd8-a5a5-7bce8f655ab8", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "assert nested_loop_example_complexity in list_complexities\n", + "assert fibonacci_recursive_complexity in list_complexities\n", + "assert binary_searche_complexity in list_complexities" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/figures/logo-ecl.png b/figures/logo-ecl.png new file mode 100644 index 0000000000000000000000000000000000000000..64dbe6a8dbcc291560a7d01f352614c0eafb5cba Binary files /dev/null and b/figures/logo-ecl.png differ diff --git a/figures/logo-emlyon.png b/figures/logo-emlyon.png new file mode 100644 index 0000000000000000000000000000000000000000..d55b2f66777a0e61adeeecf372e08e414f9353e0 Binary files /dev/null and b/figures/logo-emlyon.png differ