From 02fb9fbb475b9170feec3b7a784801139915b721 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 1 Oct 2025 13:26:17 +0300 Subject: [PATCH 1/6] Remove HW2-PersonalPage folder --- HW2-PersonalPage/_config.yml | 3 --- HW2-PersonalPage/index.md | 10 ---------- 2 files changed, 13 deletions(-) delete mode 100644 HW2-PersonalPage/_config.yml delete mode 100644 HW2-PersonalPage/index.md diff --git a/HW2-PersonalPage/_config.yml b/HW2-PersonalPage/_config.yml deleted file mode 100644 index 418485a..0000000 --- a/HW2-PersonalPage/_config.yml +++ /dev/null @@ -1,3 +0,0 @@ -title: Grezin Danil -description: Personal page of Danil Grezin hosted via GitHub -theme: jekyll-theme-hacker diff --git a/HW2-PersonalPage/index.md b/HW2-PersonalPage/index.md deleted file mode 100644 index e1c0c7c..0000000 --- a/HW2-PersonalPage/index.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -layout: default ---- - -# Education -- Bachelor's degree student at St. Petersburg State University in the field of Programming Technology - -# Contacts -- email: grezindanil@gmail.com -- telegram: @dane4ka0_0 From dba0954ef9fbe0192b4b9fad7d8f770ed7cd90ec Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 27 Oct 2025 00:56:39 +0300 Subject: [PATCH 2/6] Add heap sort algorithm --- HW5/heapSort/src/heap_sort.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 HW5/heapSort/src/heap_sort.py diff --git a/HW5/heapSort/src/heap_sort.py b/HW5/heapSort/src/heap_sort.py new file mode 100644 index 0000000..6645153 --- /dev/null +++ b/HW5/heapSort/src/heap_sort.py @@ -0,0 +1,27 @@ +def heapify(arr, size, ind): + largest = ind + l_ind = 2 * ind + 1 + r_ind = 2 * ind + 2 + + if l_ind < size and arr[l_ind] > arr[largest]: + largest = l_ind + + if r_ind < size and arr[r_ind] > arr[largest]: + largest = r_ind + + if largest != ind: + arr[ind], arr[largest] = arr[largest], arr[ind] + heapify(arr, size, largest) + + +def heap_sort(arr): + size = len(arr) + + for i in range(size // 2 - 1, -1, -1): + heapify(arr, size, i) + + for i in range(size - 1, 0, -1): + arr[0], arr[i] = arr[i], arr[0] + heapify(arr, i, 0) + + return arr From 82c1a51361b15ae7b871874de6624e73a872eba6 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 27 Oct 2025 00:57:03 +0300 Subject: [PATCH 3/6] Add python sort and quick sort for property based tests --- HW5/heapSort/src/sorts.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 HW5/heapSort/src/sorts.py diff --git a/HW5/heapSort/src/sorts.py b/HW5/heapSort/src/sorts.py new file mode 100644 index 0000000..baa21c7 --- /dev/null +++ b/HW5/heapSort/src/sorts.py @@ -0,0 +1,27 @@ +def python_sorted(arr): + return sorted(arr) + + +def set_pivot(arr, low, high): + pivot = arr[high] + i = low - 1 + + for j in range(low, high): + if arr[j] < pivot: + i += 1 + arr[i], arr[j] = arr[j], arr[i] + + arr[high], arr[i + 1] = arr[i + 1], arr[high] + return i + 1 + + +def quick_sort(arr): + if len(arr) <= 1: + return arr + + pivot = arr[len(arr) // 2] + left = [x for x in arr if x < pivot] + middle = [x for x in arr if x == pivot] + right = [x for x in arr if x > pivot] + + return quick_sort(left) + middle + quick_sort(right) From 83a42069589aeac8b6ae952a4146cc94dfd40102 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 27 Oct 2025 00:58:32 +0300 Subject: [PATCH 4/6] Add unit tests and edge cases for heap sort --- HW5/heapSort/test/test_heapsort.py | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 HW5/heapSort/test/test_heapsort.py diff --git a/HW5/heapSort/test/test_heapsort.py b/HW5/heapSort/test/test_heapsort.py new file mode 100644 index 0000000..d3497bc --- /dev/null +++ b/HW5/heapSort/test/test_heapsort.py @@ -0,0 +1,33 @@ +from src.heap_sort import heap_sort + + +class TestHeapSort: + def test_empty_array(self): + assert heap_sort([]) == [] + + def test_single_element(self): + assert heap_sort([5]) == [5] + + def test_two_elements_unsorted(self): + assert heap_sort([2, 1]) == [1, 2] + + def test_positive_numbers(self): + assert heap_sort([4, 2, 8, 1, 3]) == [1, 2, 3, 4, 8] + + def test_negative_numbers(self): + assert heap_sort([-3, -1, -2, -5]) == [-5, -3, -2, -1] + + def test_mixed_numbers(self): + assert heap_sort([3, -2, 0, -1, 5]) == [-2, -1, 0, 3, 5] + + def test_duplicate_values(self): + assert heap_sort([3, 1, 3, 2, 1]) == [1, 1, 2, 3, 3] + + def test_already_sorted(self): + assert heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] + + def test_reverse_sorted(self): + assert heap_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] + + def test_identical_elements(self): + assert heap_sort([7, 7, 7, 7]) == [7, 7, 7, 7] From 0b3614c8aaeb64f80ebf4fa386a63119a3eac43b Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 27 Oct 2025 00:58:58 +0300 Subject: [PATCH 5/6] Add property based tests for heap sort --- HW5/heapSort/test/test_heapsort_properties.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 HW5/heapSort/test/test_heapsort_properties.py diff --git a/HW5/heapSort/test/test_heapsort_properties.py b/HW5/heapSort/test/test_heapsort_properties.py new file mode 100644 index 0000000..63b03ac --- /dev/null +++ b/HW5/heapSort/test/test_heapsort_properties.py @@ -0,0 +1,38 @@ +from hypothesis import given, strategies as strat +from collections import Counter +from src.heap_sort import heap_sort +from src.sorts import python_sorted, quick_sort + +SORTING_ALGORITHMS = [heap_sort, python_sorted, quick_sort] + + +class TestHeapSortProperties: + @given(strat.lists(strat.integers(), max_size=50)) + def test_heapsort_equals_other_sorts(self, arr): + heapsort_result = heap_sort(arr.copy()) + for other_sort in [quick_sort, python_sorted]: + other_result = other_sort(arr.copy()) + assert heapsort_result == other_result + + @given(strat.lists(strat.integers())) + def test_heapsort_preserves_length(self, arr): + result = heap_sort(arr.copy()) + assert len(result) == len(arr) + + @given(strat.lists(strat.integers())) + def test_heapsort_produces_sorted_output(self, arr): + result = heap_sort(arr.copy()) + for i in range(len(result) - 1): + assert result[i] <= result[i + 1] + + @given(strat.lists(strat.integers())) + def test_heapsort_preserves_elements(self, arr): + result = heap_sort(arr.copy()) + assert Counter(result) == Counter(arr) + + @given(strat.lists(strat.integers(), min_size=2, max_size=20)) + def test_heapsort_with_duplicates(self, arr): + test_arr = arr + arr.copy() + heapsort_result = heap_sort(test_arr.copy()) + python_result = python_sorted(test_arr.copy()) + assert heapsort_result == python_result From 7ff8dd92d298414888161a8f366f92d9e1796fd8 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 27 Oct 2025 01:03:03 +0300 Subject: [PATCH 6/6] Add final newline --- HW5/heapSort/src/heap_sort.py | 1 + HW5/heapSort/src/sorts.py | 1 + HW5/heapSort/test/test_heapsort.py | 1 + HW5/heapSort/test/test_heapsort_properties.py | 1 + 4 files changed, 4 insertions(+) diff --git a/HW5/heapSort/src/heap_sort.py b/HW5/heapSort/src/heap_sort.py index 6645153..4627ae7 100644 --- a/HW5/heapSort/src/heap_sort.py +++ b/HW5/heapSort/src/heap_sort.py @@ -25,3 +25,4 @@ def heap_sort(arr): heapify(arr, i, 0) return arr + diff --git a/HW5/heapSort/src/sorts.py b/HW5/heapSort/src/sorts.py index baa21c7..dddd17f 100644 --- a/HW5/heapSort/src/sorts.py +++ b/HW5/heapSort/src/sorts.py @@ -25,3 +25,4 @@ def quick_sort(arr): right = [x for x in arr if x > pivot] return quick_sort(left) + middle + quick_sort(right) + diff --git a/HW5/heapSort/test/test_heapsort.py b/HW5/heapSort/test/test_heapsort.py index d3497bc..f651de9 100644 --- a/HW5/heapSort/test/test_heapsort.py +++ b/HW5/heapSort/test/test_heapsort.py @@ -31,3 +31,4 @@ def test_reverse_sorted(self): def test_identical_elements(self): assert heap_sort([7, 7, 7, 7]) == [7, 7, 7, 7] + diff --git a/HW5/heapSort/test/test_heapsort_properties.py b/HW5/heapSort/test/test_heapsort_properties.py index 63b03ac..9efff31 100644 --- a/HW5/heapSort/test/test_heapsort_properties.py +++ b/HW5/heapSort/test/test_heapsort_properties.py @@ -36,3 +36,4 @@ def test_heapsort_with_duplicates(self, arr): heapsort_result = heap_sort(test_arr.copy()) python_result = python_sorted(test_arr.copy()) assert heapsort_result == python_result +