Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
algo-bsc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vuillemot Romain
algo-bsc
Commits
8194b057
Commit
8194b057
authored
1 year ago
by
Romain Vuillemot
Browse files
Options
Downloads
Patches
Plain Diff
exercices + updates syllabus
parent
01a64b53
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
01-data-structures-complexity-exercices.ipynb
+255
-0
255 additions, 0 deletions
01-data-structures-complexity-exercices.ipynb
README.md
+12
-8
12 additions, 8 deletions
README.md
with
267 additions
and
8 deletions
01-data-structures-complexity-exercices.ipynb
0 → 100644
+
255
−
0
View file @
8194b057
{
"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
}
%% Cell type:markdown id:2bb7e285 tags:
# UE5 Fundamentals of Algorithms
## Exercices
### Ecole Centrale de Lyon, Bachelor of Science in Data Science for Responsible Business
#### [Romain Vuillemot](https://romain.vuillemot.net/)
Before you turn this problem in:
-
make sure everything runs as expected.
-
first,
**restart the kernel**
(in the menubar, select Kernel$
\r
ightarrow$Restart)
-
then
**run all cells**
(in the menubar, select Cell$
\r
ightarrow$Run All).
-
make sure you fill in any place that says
`YOUR CODE HERE`
or "YOUR ANSWER HERE"
-
remove
`raise NotImplementedError()`
to get started with your answer
-
bonus points (at the end of this notebook) are optionals
-
write your name (and collaborators as a list if any) below:
%% Cell type:code id:20dd5861 tags:
```
python
ID
=
""
COLLABORATORS_ID
=
[]
```
%% Cell type:markdown id:f00472a3 tags:
---
%% Cell type:markdown id:a4e4fad3 tags:
# Data Structures and Complexity
%% Cell type:markdown id:a8adef9b tags:
---
%% Cell type:code id:761a1dba-a197-4206-92a2-78920211f9f1 tags:
```
python
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 tags:
### Exercise 1: Identify the complexity
%% Cell type:code id:431fe8c1-91d1-40f3-a7a4-f4a3770a4a01 tags:
```
python
def
nested_loop_example
(
arr
):
n
=
len
(
arr
)
for
i
in
range
(
n
):
for
j
in
range
(
n
):
print
(
arr
[
i
]
+
arr
[
j
])
```
%% Cell type:code id:e68b3e9a-418f-4950-9f27-18bb0fe90794 tags:
```
python
# nested_loop_example_complexity = ?
# YOUR CODE HERE
raise
NotImplementedError
()
```
%% Cell type:markdown id:612dc873-419b-42c5-be36-0accd03ffa79 tags:
### Exercise 2: Identify the complexity
%% Cell type:code id:76102853-e1f3-4717-8a59-1091195a19eb tags:
```
python
def
fibonacci_recursive
(
n
):
if
n
<=
1
:
return
n
return
fibonacci_recursive
(
n
-
1
)
+
fibonacci_recursive
(
n
-
2
)
```
%% Cell type:code id:dead6a52-7996-4eae-9d2a-f75d5d26bbb7 tags:
```
python
# fibonacci_recursive_complexity = ?
# YOUR CODE HERE
raise
NotImplementedError
()
```
%% Cell type:markdown id:aa4a6ce7-e542-4b23-8a10-ca0bf93de041 tags:
### Exercise 3: Identify the complexity
%% Cell type:code id:70af3e43-8053-49c9-ba58-346a3e915bdb tags:
```
python
def
binary_search
(
arr
,
target
):
low
,
high
=
0
,
len
(
arr
)
-
1
while
low
<=
high
:
mid
=
(
low
+
high
)
//
2
if
arr
[
mid
]
==
target
:
return
mid
elif
arr
[
mid
]
<
target
:
low
=
mid
+
1
else
:
high
=
mid
-
1
return
-
1
```
%% Cell type:code id:9c22866c-b4fc-4228-b0ab-5882d964f5f6 tags:
```
python
# binary_searche_complexity = ?
# YOUR CODE HERE
raise
NotImplementedError
()
```
This diff is collapsed.
Click to expand it.
README.md
+
12
−
8
View file @
8194b057
...
@@ -27,6 +27,14 @@ Instructor: [Romain Vuillemot](romain.vuillemot@ec-lyon.fr)
...
@@ -27,6 +27,14 @@ Instructor: [Romain Vuillemot](romain.vuillemot@ec-lyon.fr)
📖
[
Python for Everybody
](
pdf/pythonlearn.pdf
)
chapter 8 (lists)
📖
[
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:
Next topics:
1.
**Advanced sorting**
1.
**Advanced sorting**
...
@@ -37,19 +45,15 @@ Next topics:
...
@@ -37,19 +45,15 @@ Next topics:
4.
**Trees and their representation**
4.
**Trees and their representation**
5.
**Tree
A
lgorithms**
5.
**Tree
a
lgorithms**
6.
**Binary and n-trees**
6.
**Binary and n-trees**
7.
**Graphs**
8.
**Graphs**
8.
**Divide and conquer Programming**
9.
**Dynamic Programming**
10.
**Gr
eedy A
lgorithms**
9.
**Gr
aphs a
lgorithms**
1
1.
**Graphs shortest path algorithm**
1
0.
**Graphs shortest path algorithm**
## Books
## Books
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment