algokit-py 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: algokit-py
3
- Version: 0.2.0
4
- Summary: A minimal Python algorithms library with clean implementations of search algorithms
3
+ Version: 0.3.0
4
+ Summary: A minimal Python algorithms library with clean implementations of search algorithms and sort algorithms
5
5
  Author: Chanaka Prasanna
6
6
  License: MIT
7
7
  Classifier: Programming Language :: Python :: 3
@@ -23,6 +23,7 @@ Designed for learning, interviews, and real-world algorithm reasoning.
23
23
 
24
24
  ### Sorting Algorithms
25
25
  - Insertion Sort (in-place, stable)
26
+ - Merge Sort (divide-and-conquer, O(n log n))
26
27
 
27
28
  ## Usage
28
29
 
@@ -42,9 +43,12 @@ print(binary_search([1, 2, 3], 2))
42
43
 
43
44
  ### Sorting
44
45
  ```python
45
- from algokit_py.sort import insertion_sort
46
+ from algokit_py.sort import insertion_sort, merge_sort
46
47
 
47
48
  data = [3, 1, 2]
49
+
48
50
  insertion_sort(data)
49
- print(data) # [1, 2, 3]
51
+ print(data) # [1, 2, 3]
52
+
53
+ print(merge_sort([3, 1, 2])) # [1, 2, 3]
50
54
  ```
@@ -11,6 +11,7 @@ Designed for learning, interviews, and real-world algorithm reasoning.
11
11
 
12
12
  ### Sorting Algorithms
13
13
  - Insertion Sort (in-place, stable)
14
+ - Merge Sort (divide-and-conquer, O(n log n))
14
15
 
15
16
  ## Usage
16
17
 
@@ -30,9 +31,12 @@ print(binary_search([1, 2, 3], 2))
30
31
 
31
32
  ### Sorting
32
33
  ```python
33
- from algokit_py.sort import insertion_sort
34
+ from algokit_py.sort import insertion_sort, merge_sort
34
35
 
35
36
  data = [3, 1, 2]
37
+
36
38
  insertion_sort(data)
37
- print(data) # [1, 2, 3]
39
+ print(data) # [1, 2, 3]
40
+
41
+ print(merge_sort([3, 1, 2])) # [1, 2, 3]
38
42
  ```
@@ -0,0 +1,8 @@
1
+ """
2
+ algokit_py - A minimal Python algorithms library
3
+ """
4
+
5
+ from algokit_py.search import binary_search, linear_search
6
+ from algokit_py.sort import insertion_sort, merge_sort
7
+
8
+ __all__ = ["binary_search", "linear_search","insertion_sort","merge_sort"]
@@ -0,0 +1,4 @@
1
+ from .insertion import insertion_sort
2
+ from .merge import merge_sort
3
+
4
+ __all__ = ["insertion_sort", "merge_sort"]
@@ -5,7 +5,7 @@ def insertion_sort(sequence: MutableSequence[T])-> None:
5
5
  """
6
6
  At the start of iteration i, the subarray sequence[0:i] is sorted.
7
7
 
8
- :param sequence
8
+ :param Mutable sequence
9
9
  :return None
10
10
 
11
11
  Worst Case Time Complexity: O(n²)
@@ -0,0 +1,43 @@
1
+ from typing import Sequence, TypeVar
2
+
3
+ T = TypeVar('T')
4
+
5
+ def merge_sort(sequence: Sequence[T]) -> list[T]:
6
+ """
7
+ Merge sort implementation.
8
+
9
+ Base case:
10
+ - Sequences of length 0 or 1 are already sorted.
11
+
12
+ Worst Case Time Complexity: O(n log n)
13
+ Space Complexity: O(n)
14
+ """
15
+ if len(sequence) <= 1:
16
+ return list(sequence)
17
+
18
+ middle = len(sequence) // 2
19
+ left = sequence[:middle]
20
+ right = sequence[middle:]
21
+
22
+ sorted_left = merge_sort(left)
23
+ sorted_right = merge_sort(right)
24
+
25
+ merged = []
26
+ i = j = 0
27
+
28
+ while i < len(sorted_left) and j < len(sorted_right):
29
+ if sorted_left[i] <= sorted_right[j]:
30
+ merged.append(sorted_left[i])
31
+ i += 1
32
+ else:
33
+ merged.append(sorted_right[j])
34
+ j += 1
35
+
36
+ merged.extend(sorted_left[i:])
37
+ merged.extend(sorted_right[j:])
38
+
39
+ return merged
40
+
41
+
42
+
43
+
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: algokit-py
3
- Version: 0.2.0
4
- Summary: A minimal Python algorithms library with clean implementations of search algorithms
3
+ Version: 0.3.0
4
+ Summary: A minimal Python algorithms library with clean implementations of search algorithms and sort algorithms
5
5
  Author: Chanaka Prasanna
6
6
  License: MIT
7
7
  Classifier: Programming Language :: Python :: 3
@@ -23,6 +23,7 @@ Designed for learning, interviews, and real-world algorithm reasoning.
23
23
 
24
24
  ### Sorting Algorithms
25
25
  - Insertion Sort (in-place, stable)
26
+ - Merge Sort (divide-and-conquer, O(n log n))
26
27
 
27
28
  ## Usage
28
29
 
@@ -42,9 +43,12 @@ print(binary_search([1, 2, 3], 2))
42
43
 
43
44
  ### Sorting
44
45
  ```python
45
- from algokit_py.sort import insertion_sort
46
+ from algokit_py.sort import insertion_sort, merge_sort
46
47
 
47
48
  data = [3, 1, 2]
49
+
48
50
  insertion_sort(data)
49
- print(data) # [1, 2, 3]
51
+ print(data) # [1, 2, 3]
52
+
53
+ print(merge_sort([3, 1, 2])) # [1, 2, 3]
50
54
  ```
@@ -10,6 +10,8 @@ algokit_py/search/binary.py
10
10
  algokit_py/search/linear.py
11
11
  algokit_py/sort/__init__.py
12
12
  algokit_py/sort/insertion.py
13
+ algokit_py/sort/merge.py
13
14
  tests/test_binary.py
14
15
  tests/test_insertion.py
15
- tests/test_linear.py
16
+ tests/test_linear.py
17
+ tests/test_merge.py
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "algokit-py"
7
- version = "0.2.0"
8
- description = "A minimal Python algorithms library with clean implementations of search algorithms"
7
+ version = "0.3.0"
8
+ description = "A minimal Python algorithms library with clean implementations of search algorithms and sort algorithms"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
11
11
  license = {text = "MIT"}
@@ -0,0 +1,25 @@
1
+ from algokit_py.sort import merge_sort
2
+
3
+
4
+ def test_merge_sort_basic():
5
+ assert merge_sort([3, 1, 2]) == [1, 2, 3]
6
+
7
+
8
+ def test_merge_sort_already_sorted():
9
+ assert merge_sort([1, 2, 3, 4]) == [1, 2, 3, 4]
10
+
11
+
12
+ def test_merge_sort_reverse():
13
+ assert merge_sort([4, 3, 2, 1]) == [1, 2, 3, 4]
14
+
15
+
16
+ def test_merge_sort_single_element():
17
+ assert merge_sort([5]) == [5]
18
+
19
+
20
+ def test_merge_sort_empty():
21
+ assert merge_sort([]) == []
22
+
23
+
24
+ def test_merge_sort_duplicates():
25
+ assert merge_sort([3, 1, 2, 1]) == [1, 1, 2, 3]
@@ -1,9 +0,0 @@
1
- """
2
- algokit_py - A minimal Python algorithms library
3
- """
4
-
5
- from algokit_py.search import binary_search, linear_search
6
- from algokit_py.sort import insertion_sort
7
-
8
- __version__ = "0.1.0"
9
- __all__ = ["binary_search", "linear_search","insertion_sort"]
@@ -1 +0,0 @@
1
- from .insertion import insertion_sort
File without changes