Skip to content

Commit

Permalink
Added W01 materials
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanSol committed Oct 4, 2023
1 parent 2eea03a commit ec99e96
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Semester content:

[ContestID_W01]: https://contest.yandex.ru/contest/<CID>/?lang=en
[ContestID_W01]: https://contest.yandex.ru/contest/53597/?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/4LDQdf3Dw21cF3xYA
[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 @@ -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] | 11.10.2023 19:00 UTC+3 |
<!---
| 01 | Sorting algorithms | [Slides][Slides_W01] | [Test][WarmUp_test_W01] | [Contest][ContestID_W01] | ??.10.2023 19:30 UTC+3 |
| 02 | Binary search | [Slides][Slides_W02] | [Test][WarmUp_test_W02] | [Contest][ContestID_W02] | ??.10.2023 19:00 UTC+3 |
| 03 | Basic Data sturctures | [Slides][Slides_W03] | [Test][WarmUp_test_W03] | [Contest][ContestID_W03] | ??.11.2023 19:00 UTC+3 |
| 04 | Dynamic programming | [Slides][Slides_W04] | [Test][WarmUp_test_W04] | [Contest][ContestID_W04] | ??.11.2023 19:00 UTC+3 |
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 ec99e96

Please sign in to comment.