Skip to content

Commit

Permalink
Added W01 materials
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanSol committed May 6, 2024
1 parent d92d2d7 commit 7b987e0
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 9 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## MSAI Fall 2021 Launch.
## Harbour.Space BKK 2024 M12.

### Semester content:

[ContestID_W01]: https://contest.yandex.ru/contest/<CID>/?lang=en
[ContestID_W01]: https://contest.yandex.ru/contest/62321/?lang=en
[ContestID_W02]: https://contest.yandex.ru/contest/<CID>/?lang=en
[ContestID_W03]: https://contest.yandex.ru/contest/<CID>/?lang=en
[ContestID_W04]: https://contest.yandex.ru/contest/<CID>/?lang=en
Expand All @@ -13,7 +13,7 @@
[ContestID_W09]: https://contest.yandex.ru/contest/<CID>/?lang=en
[ContestID_W10]: https://contest.yandex.ru/contest/<CID>/?lang=en

[WarmUp_test_W01]: https://forms.gle/<form_id>
[WarmUp_test_W01]: https://forms.gle/6tHJ6acUJC1ekVjeA
[WarmUp_test_W02]: https://forms.gle/<form_id>
[WarmUp_test_W03]: https://forms.gle/<form_id>
[WarmUp_test_W04]: https://forms.gle/<form_id>
Expand All @@ -25,7 +25,7 @@
[WarmUp_test_W10]: https://forms.gle/<form_id>
[WarmUp_test_W11]: https://forms.gle/<form_id>

[Slides_W01]: ../master/week01_sorting_algorithms/MSAI.2021.Algo.W01.slides.pdf
[Slides_W01]: ../master/week01_sorting_algorithms/BKK.2024.Algo.Class01.pdf
[Slides_W02]: ../master/week02_binary_search/MSAI.2021.Algo.W02.slides.pdf
[Slides_W03]: ../master/week03_basic_data_structures/MSAI.2021.Algo.W03.slides.pdf
[Slides_W04]: ../master/week04_dynamic_programming/MSAI.2021.Algo.W04.slides.pdf
Expand All @@ -39,8 +39,8 @@

| Week | Content | Slides | WarmUp test | Contest | Soft Deadline |
|:------:|:-----------------------|:--------------------:|:-----------------------:|:------------------------:|:----------------------:|
| 01 | Sorting algorithms | [Slides][Slides_W01] | [Test][WarmUp_test_W01] | [Contest][ContestID_W01] | 07.05.2024 09:00 UTC+7 |
<!---
| 01 | Sorting algorithms | [Slides][Slides_W01] | [Test][WarmUp_test_W01] | [Contest][ContestID_W01] | ??.10.2021 19:30 GMT+3 |
| 02 | Binary search | [Slides][Slides_W02] | [Test][WarmUp_test_W02] | [Contest][ContestID_W02] | ??.11.2021 19:00 GMT+3 |
| 03 | Basic Data sturctures | [Slides][Slides_W03] | [Test][WarmUp_test_W03] | [Contest][ContestID_W03] | ??.11.2021 19:00 GMT+3 |
| 04 | Dynamic programming | [Slides][Slides_W04] | [Test][WarmUp_test_W04] | [Contest][ContestID_W04] | ??.11.2021 19:00 GMT+3 |
Expand Down Expand Up @@ -69,23 +69,23 @@ Information about **theoretical exam** can be found [here](<link>).
### Final grade:
Final grade **`G`** consists of three parts:

- Homework grade: **`H`** is an integer number within range [0; 10] (rules given below).
- Homework grade: **`H`** is a number within range [0; 1] (rules given below).

- Practical exam grade: **`P`** is an integer number within range [0; 10] (rules will be provided later).

- Theoretical exam grade: **`T`** is an integer number within range [0; 10] (rules will be provided later).

Your final grade is:
<pre><b>G</b> = ceil(0.6 <b>H</b> + 0.2 <b>P</b> + 0.2 <b>T</b>)</pre>
<pre><b>G</b> = ceil(0.6 <b>H</b> * 100 + 0.2 <b>P</b> * 10 + 0.2 <b>T</b> * 10)</pre>


### Homework grade
Homework grade contributes the most into final grade. To increase homework grade you should solve problems from home assignments.

**Formally:**

Homework grade: **`H`** is an integer number within range [0; 10]:
<pre><b>H</b> = round(hw_score / hw_maximum_score * 10)</pre>
Homework grade: **`H`** is an integer number within range [0; 1]:
<pre><b>H</b> = hw_score / hw_maximum_score</pre>

`hw_score` is sum of scores for all problems in home assignment.

Expand Down
2 changes: 2 additions & 0 deletions week01_sorting_algorithms/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
webinar
qsort.py
Binary file not shown.
12 changes: 12 additions & 0 deletions week01_sorting_algorithms/bubble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def bubble_sort(x):
N = len(x)
for i in range(0, N - 1):
for j in range(0, N - i - 1):
if x[j] > x[j + 1]:
x[j], x[j + 1] = x[j + 1], x[j]


if __name__ == '__main__':
input()
x = list(map(int, input().split()))
print(' '.join(map(str, x)))
15 changes: 15 additions & 0 deletions week01_sorting_algorithms/insertion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def insertion_sort(x):
N = len(x)
for i in range(1, N):
key = x[i]
j = i - 1
while j >= 0 and key < x[j]:
x[j + 1] = x[j]
j -= 1
x[j + 1] = key


if __name__ == '__main__':
input()
x = list(map(int, input().split()))
print(' '.join(map(str, x)))
31 changes: 31 additions & 0 deletions week01_sorting_algorithms/merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
def merge(x, l, m, r):
tmp = []
i1 = l
i2 = m
while i1 < m or i2 < r:
if (i2 >= r) or ((i1 < m) and
(x[i1] < x[i2])):
tmp.append(x[i1])
i1 += 1
else:
tmp.append(x[i2])
i2 += 1
x[l:r] = tmp


def merge_sort(x, l=0, r=None):
if r is None:
r = len(x)
if r - l > 1:
m = (l + r) // 2 # Finding the mid of the array
merge_sort(x, l, m) # Sorting the first half
merge_sort(x, m, r) # Sorting the second half
merge(x, l, m, r)


if __name__ == '__main__':
input()
x = list(map(int, input().split()))
N = len(x)
merge_sort(x, 0, N)
print(' '.join(map(str, x)))
35 changes: 35 additions & 0 deletions week01_sorting_algorithms/qsort_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import random


def partition(x, l, r, pivot):
"""
:param x: Source array (list)
:param l: left border of partitioning range (int)
:param r: right border (not included) of partitioning range (int)
:param pivot: pivot element to divide array (any item from x[l, r)).
:return: il, ir -- desired partition
This function should reorder elements of x within [l, r) region
in the way, these conditions are true:
x[l:il] < pivot
x[il:ir] == pivot
x[ir:r] > pivot
"""
# Your code goes here
pass


def qsort(x, l=0, r=None):
if r is None:
r = len(x)
if (r - l) > 1:
pivot = x[random.randint(l, r - 1)]
il, ir = partition(x, l, r, pivot)
qsort(x, l, il)
qsort(x, ir, r)


if __name__ == '__main__':
N = int(input())
x = list(map(int, input().split()))
qsort(x)
print(' '.join(map(str, x)))
14 changes: 14 additions & 0 deletions week01_sorting_algorithms/selection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def selection_sort(x):
N = len(x)
for i in range(N - 1):
i_min = i
for j in range(i + 1, N):
if x[i_min] > x[j]:
i_min = j
x[i], x[i_min] = x[i_min], x[i]


if __name__ == '__main__':
input()
x = list(map(int, input().split()))
print(' '.join(map(str, x)))

0 comments on commit 7b987e0

Please sign in to comment.