feat: add theory guides (terminology, algorithms, testing, debugging) and 2 new chapters

This commit is contained in:
soda64 committed 2026-11-30 23:08:04 +01:00
1 parent ae4c421815
commit 0ac80d60d4
14 files changed
+380 -3

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
# 11 — Algorytmy i Złożoność Obliczeniowa (`O(log n)`, `O(n)`)
Teoria: [notes/03-algorithms-and-complexity.md](../../../notes/03-algorithms-and-complexity.md)
## Zadania (`algorithms.py`)
1. `binary_search(sorted_nums: list[int], target: int) -> int | None` — wyszukiwanie binarne w `O(log n)` (zwróć indeks lub `None`).
2. `two_sum(nums: list[int], target: int) -> tuple[int, int] | None` — znajdź parę indeksów `(i, j)` (`i < j`) dającą `nums[i] + nums[j] == target` w czasie `O(n)` przy pomocy `dict`.
3. `is_palindrome(text: str) -> bool` — sprawdź palindrom metodą **dwóch wskaźników** (*two pointers*), ignorując wielkość liter i znaki niebędące literami/cyframi.
4. `max_window_sum(nums: list[int], k: int) -> int | None` — maksymalna suma spójnego podciągu długości `k` metodą **okna przesuwnego** (*sliding window*) w `O(n)`.
## Uruchomienie testów
```bash
make test MOD=01-core/11-algorithms
```
@@ -0,0 +1,14 @@
def binary_search(sorted_nums: list[int], target: int) -> int | None:
raise NotImplementedError("Wyszukiwanie binarne O(log n): zwróć indeks lub None")
def two_sum(nums: list[int], target: int) -> tuple[int, int] | None:
raise NotImplementedError("Znajdź parę indeksów (i, j) w O(n) używając dict")
def is_palindrome(text: str) -> bool:
raise NotImplementedError("Dwa wskaźniki (two pointers), tylko znaki alfanumeryczne, lowercase")
def max_window_sum(nums: list[int], k: int) -> int | None:
raise NotImplementedError("Okno przesuwne (sliding window) O(n); None gdy k <= 0 lub k > len")
@@ -0,0 +1,25 @@
from algorithms import binary_search, is_palindrome, max_window_sum, two_sum
def test_binary_search() -> None:
assert binary_search([], 5) is None
assert binary_search([1, 3, 5, 7, 9], 7) == 3
assert binary_search([1, 3, 5, 7, 9], 4) is None
def test_two_sum() -> None:
assert two_sum([2, 7, 11, 15], 9) == (0, 1)
assert two_sum([3, 2, 4], 6) == (1, 2)
assert two_sum([1, 2, 3], 99) is None
def test_is_palindrome() -> None:
assert is_palindrome("Kobyła ma mały bok") is True
assert is_palindrome("A man, a plan, a canal: Panama") is True
assert is_palindrome("devops") is False
def test_max_window_sum() -> None:
assert max_window_sum([2, 1, 5, 1, 3, 2], 3) == 9
assert max_window_sum([1, 2], 3) is None
assert max_window_sum([1, 2], 0) is None