From 8194b0578e71683db12d847cb171fac21ac28e51 Mon Sep 17 00:00:00 2001 From: Romain Vuillemot <romain.vuillemot@gmail.com> Date: Tue, 26 Sep 2023 06:28:48 +0200 Subject: [PATCH] exercices + updates syllabus --- 01-data-structures-complexity-exercices.ipynb | 255 ++++++++++++++++++ README.md | 20 +- 2 files changed, 267 insertions(+), 8 deletions(-) create mode 100644 01-data-structures-complexity-exercices.ipynb diff --git a/01-data-structures-complexity-exercices.ipynb b/01-data-structures-complexity-exercices.ipynb new file mode 100644 index 0000000..6a7e9d4 --- /dev/null +++ b/01-data-structures-complexity-exercices.ipynb @@ -0,0 +1,255 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "2bb7e285", + "metadata": {}, + "source": [ + "# UE5 Fundamentals of Algorithms\n", + "## Exercices\n", + "### Ecole Centrale de Lyon, Bachelor of Science in Data Science for Responsible Business\n", + "#### [Romain Vuillemot](https://romain.vuillemot.net/)\n", + "\n", + "Before you turn this problem in:\n", + "- make sure everything runs as expected. \n", + " - first, **restart the kernel** (in the menubar, select Kernel$\\rightarrow$Restart) \n", + " - then **run all cells** (in the menubar, select Cell$\\rightarrow$Run All).\n", + "- make sure you fill in any place that says `YOUR CODE HERE` or \"YOUR ANSWER HERE\"\n", + "- remove `raise NotImplementedError()` to get started with your answer\n", + "- bonus points (at the end of this notebook) are optionals\n", + "- write your name (and collaborators as a list if any) below:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "20dd5861", + "metadata": {}, + "outputs": [], + "source": [ + "ID = \"\"\n", + "COLLABORATORS_ID = []" + ] + }, + { + "cell_type": "markdown", + "id": "f00472a3", + "metadata": {}, + "source": [ + "---" + ] + }, + { + "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": "code", + "execution_count": null, + "id": "761a1dba-a197-4206-92a2-78920211f9f1", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "list_complexities = [\"O(1)\", \"O(log(n))\", \"O(n)\", \"O(n^2)\", \"O(nlog(n))\", \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" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "431fe8c1-91d1-40f3-a7a4-f4a3770a4a01", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "def nested_loop_example(arr):\n", + " n = len(arr)\n", + " for i in range(n):\n", + " for j in range(n):\n", + " print(arr[i] + arr[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" + ] + }, + { + "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" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "70af3e43-8053-49c9-ba58-346a3e915bdb", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "def binary_search(arr, target):\n", + " low, high = 0, len(arr) - 1\n", + " while low <= high:\n", + " mid = (low + high) // 2\n", + " if arr[mid] == target:\n", + " return mid\n", + " elif arr[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()" + ] + } + ], + "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/README.md b/README.md index 4987100..0b496ec 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,14 @@ Instructor: [Romain Vuillemot](romain.vuillemot@ec-lyon.fr) 📖 [Python for Everybody](pdf/pythonlearn.pdf) chapter 8 (lists) +### Assignment 1 - TBD + +### Lecture 4 - **Divide and conquer and greedy algorithms** + +### Lecture 5 - **Dynamic programming** + +### Assignment 2 - TBD + Next topics: 1. **Advanced sorting** @@ -37,19 +45,15 @@ Next topics: 4. **Trees and their representation** -5. **Tree Algorithms** +5. **Tree algorithms** 6. **Binary and n-trees** -7. **Graphs** - -8. **Divide and conquer Programming** - -9. **Dynamic Programming** +8. **Graphs** -10. **Greedy Algorithms** +9. **Graphs algorithms** -11. **Graphs shortest path algorithm** +10. **Graphs shortest path algorithm** ## Books -- GitLab