diff --git a/README.md b/README.md index 93d0326..d45306b 100644 --- a/README.md +++ b/README.md @@ -11,23 +11,24 @@ ## Структура курса -| № | Тема | Секция | Папка | -|----|----------------------------------|------------------------------|-------------------| -| 1 | Введение в алгоритмы | Базовые алгоритмы | `a_intro` | -| 2 | Базовые структуры данных | Базовые алгоритмы | `b_base_ds` | -| 3 | Поиски | Базовые алгоритмы | `c_search` | -| 4 | Сортировки | Базовые алгоритмы | `d_sorting` | -| 5 | Два указателя | Методы решения | `e_two_pointers` | -| 6 | Сканирующая прямая | Методы решения | `f_scanline` | -| 7 | Разделяй и властвуй | Методы решения | `g_dnc` | -| 8 | Динамическое программирование | Методы решения | `h_dp` | -| 9 | Префиксные суммы | Продвинутые подходы | `i_prefix_sums` | -| 10 | Жадные алгоритмы | Продвинутые подходы | `j_greedy` | -| 11 | Теория чисел | Продвинутые подходы | `k_number_theory` | -| 12 | 2D Динамическое программирование | Продвинутые подходы | `l_dp2` | -| 13 | Деревья | Продвинутые структуры данных | `m_trees` | -| 14 | Кучи | Продвинутые структуры данных | `n_heaps` | -| 15 | Графы | Продвинутые структуры данных | `o_trees` | +| № | Тема | Секция | Папка | +|----|----------------------------------|------------------------------|-----------------| +| 1 | Введение в алгоритмы | Базовые алгоритмы | `intro` | +| 2 | Базовые структуры данных | Базовые алгоритмы | `base_ds` | +| 3 | Поиски | Базовые алгоритмы | `search` | +| 4 | Сортировки | Базовые алгоритмы | `sorting` | +| 5 | Два указателя | Методы решения | `two_pointers` | +| 6 | Сканирующая прямая | Методы решения | `scanline` | +| 7 | Разделяй и властвуй | Методы решения | `dnc` | +| 8 | Динамическое программирование | Методы решения | `dp` | +| 9 | Префиксные суммы | Продвинутые подходы | `prefix_sums` | +| 10 | Жадные алгоритмы | Продвинутые подходы | `greedy` | +| 11 | Теория чисел | Продвинутые подходы | `number_theory` | +| 12 | 2D Динамическое программирование | Продвинутые подходы | `dp2` | +| 13 | Деревья | Продвинутые структуры данных | `trees` | +| 14 | Кучи | Продвинутые структуры данных | `heaps` | +| 15 | Непересекающиеся множества | Продвинутые структуры данных | `dsu` | +| 16 | Графы | Продвинутые структуры данных | `graphs` | Каждая тема содержит: diff --git a/src/b_base_ds/ABSTRACT.md b/src/base_ds/ABSTRACT.md similarity index 100% rename from src/b_base_ds/ABSTRACT.md rename to src/base_ds/ABSTRACT.md diff --git a/src/b_base_ds/README.md b/src/base_ds/README.md similarity index 100% rename from src/b_base_ds/README.md rename to src/base_ds/README.md diff --git a/src/b_base_ds/__init__.py b/src/base_ds/__init__.py similarity index 100% rename from src/b_base_ds/__init__.py rename to src/base_ds/__init__.py diff --git a/src/b_base_ds/bank_queue.py b/src/base_ds/bank_queue.py similarity index 100% rename from src/b_base_ds/bank_queue.py rename to src/base_ds/bank_queue.py diff --git a/src/b_base_ds/brackets.py b/src/base_ds/brackets.py similarity index 100% rename from src/b_base_ds/brackets.py rename to src/base_ds/brackets.py diff --git a/src/b_base_ds/calculator.py b/src/base_ds/calculator.py similarity index 100% rename from src/b_base_ds/calculator.py rename to src/base_ds/calculator.py diff --git a/src/b_base_ds/max_stack.py b/src/base_ds/max_stack.py similarity index 100% rename from src/b_base_ds/max_stack.py rename to src/base_ds/max_stack.py diff --git a/src/b_base_ds/net_packets.py b/src/base_ds/net_packets.py similarity index 100% rename from src/b_base_ds/net_packets.py rename to src/base_ds/net_packets.py diff --git a/src/b_base_ds/sliding_window.py b/src/base_ds/sliding_window.py similarity index 100% rename from src/b_base_ds/sliding_window.py rename to src/base_ds/sliding_window.py diff --git a/src/g_dnc/ABSTRACT.md b/src/dnc/ABSTRACT.md similarity index 100% rename from src/g_dnc/ABSTRACT.md rename to src/dnc/ABSTRACT.md diff --git a/src/g_dnc/README.md b/src/dnc/README.md similarity index 100% rename from src/g_dnc/README.md rename to src/dnc/README.md diff --git a/src/c_search/__init__.py b/src/dnc/__init__.py similarity index 100% rename from src/c_search/__init__.py rename to src/dnc/__init__.py diff --git a/src/g_dnc/count_smaller.py b/src/dnc/count_smaller.py similarity index 100% rename from src/g_dnc/count_smaller.py rename to src/dnc/count_smaller.py diff --git a/src/g_dnc/kth_largest.py b/src/dnc/kth_largest.py similarity index 91% rename from src/g_dnc/kth_largest.py rename to src/dnc/kth_largest.py index 3901af3..5afc6b8 100644 --- a/src/g_dnc/kth_largest.py +++ b/src/dnc/kth_largest.py @@ -1,4 +1,4 @@ -from src.d_sorting.partition import partition3 +from src.sorting.partition import partition3 # O(n) в среднем, O(n^2) в худшем diff --git a/src/g_dnc/median_salary.py b/src/dnc/median_salary.py similarity index 92% rename from src/g_dnc/median_salary.py rename to src/dnc/median_salary.py index dbbaf64..ae1bf8e 100644 --- a/src/g_dnc/median_salary.py +++ b/src/dnc/median_salary.py @@ -1,4 +1,4 @@ -from src.g_dnc.kth_largest import quick_select +from src.dnc.kth_largest import quick_select # O(N) в среднем, O(N^2) в худшем diff --git a/src/g_dnc/multiply.py b/src/dnc/multiply.py similarity index 100% rename from src/g_dnc/multiply.py rename to src/dnc/multiply.py diff --git a/src/g_dnc/power.py b/src/dnc/power.py similarity index 100% rename from src/g_dnc/power.py rename to src/dnc/power.py diff --git a/src/h_dp/ABSTRACT.md b/src/dp/ABSTRACT.md similarity index 100% rename from src/h_dp/ABSTRACT.md rename to src/dp/ABSTRACT.md diff --git a/src/h_dp/README.md b/src/dp/README.md similarity index 100% rename from src/h_dp/README.md rename to src/dp/README.md diff --git a/src/d_sorting/__init__.py b/src/dp/__init__.py similarity index 100% rename from src/d_sorting/__init__.py rename to src/dp/__init__.py diff --git a/src/h_dp/calculator.py b/src/dp/calculator.py similarity index 100% rename from src/h_dp/calculator.py rename to src/dp/calculator.py diff --git a/src/h_dp/climbing_stairs.py b/src/dp/climbing_stairs.py similarity index 100% rename from src/h_dp/climbing_stairs.py rename to src/dp/climbing_stairs.py diff --git a/src/h_dp/coin_change.py b/src/dp/coin_change.py similarity index 100% rename from src/h_dp/coin_change.py rename to src/dp/coin_change.py diff --git a/src/h_dp/gold_storage_robbery.py b/src/dp/gold_storage_robbery.py similarity index 100% rename from src/h_dp/gold_storage_robbery.py rename to src/dp/gold_storage_robbery.py diff --git a/src/h_dp/length_of_lis.py b/src/dp/length_of_lis.py similarity index 100% rename from src/h_dp/length_of_lis.py rename to src/dp/length_of_lis.py diff --git a/src/h_dp/length_of_lms.py b/src/dp/length_of_lms.py similarity index 100% rename from src/h_dp/length_of_lms.py rename to src/dp/length_of_lms.py diff --git a/src/h_dp/lnis.py b/src/dp/lnis.py similarity index 100% rename from src/h_dp/lnis.py rename to src/dp/lnis.py diff --git a/src/h_dp/min_cost_climbing_stairs.py b/src/dp/min_cost_climbing_stairs.py similarity index 100% rename from src/h_dp/min_cost_climbing_stairs.py rename to src/dp/min_cost_climbing_stairs.py diff --git a/src/l_dp2/ABSTRACT.md b/src/dp2/ABSTRACT.md similarity index 100% rename from src/l_dp2/ABSTRACT.md rename to src/dp2/ABSTRACT.md diff --git a/src/l_dp2/README.md b/src/dp2/README.md similarity index 100% rename from src/l_dp2/README.md rename to src/dp2/README.md diff --git a/src/e_two_pointers/__init__.py b/src/dp2/__init__.py similarity index 100% rename from src/e_two_pointers/__init__.py rename to src/dp2/__init__.py diff --git a/src/l_dp2/edit_candidates.py b/src/dp2/edit_candidates.py similarity index 88% rename from src/l_dp2/edit_candidates.py rename to src/dp2/edit_candidates.py index 5370262..cec007e 100644 --- a/src/l_dp2/edit_candidates.py +++ b/src/dp2/edit_candidates.py @@ -1,4 +1,4 @@ -from src.l_dp2.edit_distance import edit_distance_dp +from src.dp2.edit_distance import edit_distance_dp # O(q * n * m), где q - количество слов, n - длина строки a, m - длина строки b diff --git a/src/l_dp2/edit_distance.py b/src/dp2/edit_distance.py similarity index 100% rename from src/l_dp2/edit_distance.py rename to src/dp2/edit_distance.py diff --git a/src/l_dp2/edit_path.py b/src/dp2/edit_path.py similarity index 97% rename from src/l_dp2/edit_path.py rename to src/dp2/edit_path.py index 05dfa52..2eea2c7 100644 --- a/src/l_dp2/edit_path.py +++ b/src/dp2/edit_path.py @@ -3,7 +3,7 @@ from enum import StrEnum, auto from typing import Any -from src.l_dp2.edit_distance import get_dp_table +from src.dp2.edit_distance import get_dp_table class Operation(StrEnum): diff --git a/src/l_dp2/lcs.py b/src/dp2/lcs.py similarity index 100% rename from src/l_dp2/lcs.py rename to src/dp2/lcs.py diff --git a/src/l_dp2/max_robot_path.py b/src/dp2/max_robot_path.py similarity index 100% rename from src/l_dp2/max_robot_path.py rename to src/dp2/max_robot_path.py diff --git a/src/l_dp2/max_robot_sum.py b/src/dp2/max_robot_sum.py similarity index 100% rename from src/l_dp2/max_robot_sum.py rename to src/dp2/max_robot_sum.py diff --git a/src/dsu/README.md b/src/dsu/README.md new file mode 100644 index 0000000..5fe7b59 --- /dev/null +++ b/src/dsu/README.md @@ -0,0 +1,141 @@ +# Задачи на непересекающиеся множества + +## A. Объединение таблиц + +| Поле | Значение | +|-----------|---------------------------------------------------| +| Сложность | Средняя | +| Источник | https://stepik.org/lesson/41560/step/3?unit=20013 | + +В базе данных есть n таблиц, каждая содержит некоторое количество строк. +Вам нужно обрабатывать операции объединения таблиц. + +Каждая таблица либо: + +* содержит реальные данные (строки), +* либо является ссылкой на другую таблицу. + +Изначально все таблицы содержат реальные данные. + +**Операция объединения** + +Для запроса (destination, source): + +Найти реальную таблицу для destination (переходя по ссылкам). +Найти реальную таблицу для source. +Если это разные таблицы: + +* перенести все строки из source в destination, +* сделать source ссылкой на destination, +* размер source становится 0. + +Вывести максимальный размер таблицы среди всех. + +**Формат входа.** + +* Первая строка: n m — число таблиц и запросов + (1 ≤ n, m ≤ 100000) +* Вторая строка: r1 ... rn — размеры таблиц + (0 ≤ ri ≤ 10000) +* Далее m строк: destination source + +**Формат выхода.** + +Для каждого запроса выведите максимальный размер таблицы после объединения. + +**Пример** + +Ввод: + +```text +5 5 +1 1 1 1 1 +3 5 +2 4 +1 4 +5 4 +5 3 +``` + +Вывод: + +```text +2 +2 +3 +5 +5 +``` + +## B. Автоматический анализ программ + +| Поле | Значение | +|-----------|---------------------------------------------------| +| Сложность | Средняя | +| Источник | https://stepik.org/lesson/41560/step/4?unit=20013 | + +Дано n переменных: x1, x2, ..., xn. + +Есть два типа ограничений: + +* равенства: xi = xj +* неравенства: xp ≠ xq + +Нужно определить, можно ли присвоить переменным целые значения так, чтобы все ограничения выполнялись. + +**Формат входа** + +* Первая строка: n e d +* * n — число переменных (1 ≤ n ≤ 10^5) +* * e — число равенств +* * d — число неравенств +* * (0 ≤ e, d, e + d ≤ 2⋅10^5) +* Далее e строк: i j — равенство xi = xj +* Далее d строк: i j — неравенство xi ≠ xj + +**Формат выхода** + +* 1 — если система выполнима +* 0 — если есть противоречие + +**Пример 1** + +Ввод: + +```text +4 6 0 +1 2 +1 3 +1 4 +2 3 +2 4 +3 4 +``` + +Вывод: + +```text +1 +``` + +**Пример 2** + +Ввод: + +```text +6 5 3 +2 3 +1 5 +2 5 +3 4 +4 2 +6 1 +4 6 +4 5 +``` + +Вывод: + +```text +0 +``` diff --git a/src/g_dnc/__init__.py b/src/dsu/__init__.py similarity index 100% rename from src/g_dnc/__init__.py rename to src/dsu/__init__.py diff --git a/src/dsu/auto_analysis.py b/src/dsu/auto_analysis.py new file mode 100644 index 0000000..2933c6a --- /dev/null +++ b/src/dsu/auto_analysis.py @@ -0,0 +1,10 @@ +from src.dsu.dsu import CompressedForestDSU + + +def auto_analysis(n: int, e: int, d: int, equals: list[tuple[int, int]], not_equals: list[tuple[int, int]]) -> bool: + s = CompressedForestDSU(n) + for i in range(1, n + 1): + s.make_set(i) + for i in range(e): + s.union(equals[i][0], equals[i][1]) + return all(s.find(not_equals[i][0]) != s.find(not_equals[i][1]) for i in range(d)) diff --git a/src/dsu/dsu.py b/src/dsu/dsu.py new file mode 100644 index 0000000..bc0290c --- /dev/null +++ b/src/dsu/dsu.py @@ -0,0 +1,153 @@ +from abc import ABC, abstractmethod + + +class DSU(ABC): + def __init__(self, n: int) -> None: + self.n = n + + @abstractmethod + def make_set(self, x: int) -> None: + """Создать одноэлементное множество {x}""" + ... + + @abstractmethod + def find(self, x: int) -> int: + """Выдать ID множества, содержащего {x}""" + ... + + @abstractmethod + def union(self, x: int, y: int) -> None: + """Объединить множества, содержащие {x} и {y}""" + ... + + +class ArrayDSU(DSU): + """ + Система непересекающихся множеств на массиве. + + ID множества - минимальный элемент в нем. + + s1 = {9, 3, 2, 4, 7}, s2 = {5}, s3 = {6, 1, 8} + + smallest[i] - ID множества, которому принадлежит элемент i: + smallest[9] = 2, smallest[3] = 2, smallest[2] = 2, smallest[4] = 2, smallest[7] = 2, smallest[5] = 5, + smallest[6] = 1, smallest[1] = 1, smallest[8] = 1. + + smallest = [0, 1, 2, 2, 2, 5, 1, 2, 1, 2] + """ + + def __init__(self, n: int) -> None: + super().__init__(n) + self.smallest = [0] * (self.n + 1) + + # O(1) + def make_set(self, x: int) -> None: + self.smallest[x] = x + + # O(1) + def find(self, x: int) -> int: + return self.smallest[x] + + # O(N) + def union(self, x: int, y: int) -> None: + x_id = self.find(x) + y_id = self.find(y) + if x_id == y_id: + return + new_id = min(x_id, y_id) + for i in range(1, self.n + 1): + if self.smallest[i] in {x_id, y_id}: + self.smallest[i] = new_id + + +class ForestDSU(DSU): + """ + Система непересекающихся множеств на лесе корневых деревьев. + + ID множества - корень дерева. + + s1 = {9, 3, 2, 4, 7}, s2 = {5}, s3 = {6, 1, 8} + + parent[i] - родитель элемента i в дереве. + + union(9, 3) : ранги равны => подвешиваем 9 к 3 + union(3, 2) : rank[3] > rank[2] => подвешиваем 2 к 3 + union(2, 4) : rank[2] = rank[3] > rank[4] => подвешиваем 4 к 3 + union(4, 7) : rank[4] = rank[3] > rank[7] => подвешиваем 7 к 3 + union(6, 1) : ранги равны => подвешиваем 6 к 1 + union(1, 8) : rank[1] > rank[8] => подвешиваем 8 к 1 + + Множество s1 (корень 3): + 3 + / | | \ + 9 2 4 7 + + Множество s2 (корень 5): + 5 + + Множество s3 (корень 1): + 1 + / \ + 6 8 + + parent = [0, 1, 3, 3, 3, 5, 1, 3, 1, 3] + + rank[i] - ранг элемента i в дереве, который используется при объединении. + В текущей реализации ранг равен высоте дерева в элементе. + + rank = [0, 1, 0, 1, 0, 0, 0, 0, 0, 0] + """ + + def __init__(self, n: int) -> None: + super().__init__(n) + self.parent = [0] * (self.n + 1) + self.rank = [0] * (self.n + 1) + + # O(1) + def make_set(self, x: int) -> None: + self.parent[x] = x + self.rank[x] = 0 + + # O(log N) + def find(self, x: int) -> int: + while x != self.parent[x]: + x = self.parent[x] + return self.parent[x] + + # O(log N) + def union(self, x: int, y: int) -> None: + x_root = self.find(x) + y_root = self.find(y) + if x_root == y_root: + return + # Более низкое подвешиваем к более высокому, чтобы не увеличивать глубину дерева + if self.rank[x_root] > self.rank[y_root]: + self.parent[y_root] = x_root + else: + self.parent[x_root] = y_root + + # При одинаковой высоте деревьев подвешиваем к одному из них, а его высоту увеличиваем на единицу + if self.rank[x_root] == self.rank[y_root]: + self.rank[y_root] += 1 + + +class CompressedForestDSU(ForestDSU): + """ + Система непересекающихся множеств на лесе корневых деревьев с использованием сжатия путей. + ID множества - корень дерева. + + Отличия от ForestDSU: + - При поиске корня дерева для элемента i, мы не только находим корень, но и "подвешиваем" все элементы на пути от i + до корня непосредственно к корню. + - Это позволяет значительно ускорить последующие операции find для этих элементов, так как они будут находиться на + уровне 1 от корня. + + Побочный эффект: + - rank[i] перестает хранить точную высоту элемента i в дереве, а ставится верхней оценкой все еще актуальной при + объединении. + """ + + def find(self, x: int) -> int: + if x != self.parent[x]: + self.parent[x] = self.find(self.parent[x]) + return self.parent[x] diff --git a/src/dsu/max_dsu.py b/src/dsu/max_dsu.py new file mode 100644 index 0000000..20cc8c5 --- /dev/null +++ b/src/dsu/max_dsu.py @@ -0,0 +1,29 @@ +class MaxDSU: + def __init__(self, sizes: list[int]) -> None: + self.parent = list(range(len(sizes))) + self.size = sizes.copy() + self.curr_max = max(self.size) + + def find(self, x: int) -> int: + if x != self.parent[x]: + self.parent[x] = self.find(self.parent[x]) + return self.parent[x] + + def union(self, x: int, y: int) -> None: + x_root = self.find(x) + y_root = self.find(y) + + if x_root == y_root: + return + + # всегда присоединяем меньшее к большему + if self.size[x_root] < self.size[y_root]: + x_root, y_root = y_root, x_root + + # теперь x_root - корень большей компоненты + self.parent[y_root] = x_root + self.size[x_root] += self.size[y_root] + + # обновляем максимум только по новому корню + if self.size[x_root] > self.curr_max: + self.curr_max = self.size[x_root] diff --git a/src/dsu/table_union.py b/src/dsu/table_union.py new file mode 100644 index 0000000..005f5db --- /dev/null +++ b/src/dsu/table_union.py @@ -0,0 +1,10 @@ +from src.dsu.max_dsu import MaxDSU + + +def table_union(sizes: list[int], queries: list[tuple[int, int]]) -> list[int]: + result: list[int] = [] + s = MaxDSU(sizes) + for i in range(len(queries)): + s.union(queries[i][0] - 1, queries[i][1] - 1) + result.append(s.curr_max) + return result diff --git a/src/o_graphs/ABSTRACT.md b/src/graphs/ABSTRACT.md similarity index 100% rename from src/o_graphs/ABSTRACT.md rename to src/graphs/ABSTRACT.md diff --git a/src/o_graphs/README.md b/src/graphs/README.md similarity index 100% rename from src/o_graphs/README.md rename to src/graphs/README.md diff --git a/src/h_dp/__init__.py b/src/graphs/__init__.py similarity index 100% rename from src/h_dp/__init__.py rename to src/graphs/__init__.py diff --git a/src/o_graphs/greed_stone.py b/src/graphs/greed_stone.py similarity index 100% rename from src/o_graphs/greed_stone.py rename to src/graphs/greed_stone.py diff --git a/src/o_graphs/journey_path.py b/src/graphs/journey_path.py similarity index 100% rename from src/o_graphs/journey_path.py rename to src/graphs/journey_path.py diff --git a/src/j_greedy/ABSTRACT.md b/src/greedy/ABSTRACT.md similarity index 100% rename from src/j_greedy/ABSTRACT.md rename to src/greedy/ABSTRACT.md diff --git a/src/j_greedy/README.md b/src/greedy/README.md similarity index 100% rename from src/j_greedy/README.md rename to src/greedy/README.md diff --git a/src/i_prefix_sums/__init__.py b/src/greedy/__init__.py similarity index 100% rename from src/i_prefix_sums/__init__.py rename to src/greedy/__init__.py diff --git a/src/j_greedy/convex_hull.py b/src/greedy/convex_hull.py similarity index 100% rename from src/j_greedy/convex_hull.py rename to src/greedy/convex_hull.py diff --git a/src/j_greedy/huffman.py b/src/greedy/huffman.py similarity index 100% rename from src/j_greedy/huffman.py rename to src/greedy/huffman.py diff --git a/src/j_greedy/knapsack.py b/src/greedy/knapsack.py similarity index 100% rename from src/j_greedy/knapsack.py rename to src/greedy/knapsack.py diff --git a/src/j_greedy/max_terms.py b/src/greedy/max_terms.py similarity index 100% rename from src/j_greedy/max_terms.py rename to src/greedy/max_terms.py diff --git a/src/n_heaps/README.md b/src/heaps/README.md similarity index 100% rename from src/n_heaps/README.md rename to src/heaps/README.md diff --git a/src/j_greedy/__init__.py b/src/heaps/__init__.py similarity index 100% rename from src/j_greedy/__init__.py rename to src/heaps/__init__.py diff --git a/src/n_heaps/heap_sort.py b/src/heaps/heap_sort.py similarity index 100% rename from src/n_heaps/heap_sort.py rename to src/heaps/heap_sort.py diff --git a/src/n_heaps/heapify.py b/src/heaps/heapify.py similarity index 100% rename from src/n_heaps/heapify.py rename to src/heaps/heapify.py diff --git a/src/n_heaps/huffman.py b/src/heaps/huffman.py similarity index 100% rename from src/n_heaps/huffman.py rename to src/heaps/huffman.py diff --git a/src/n_heaps/parallel.py b/src/heaps/parallel.py similarity index 100% rename from src/n_heaps/parallel.py rename to src/heaps/parallel.py diff --git a/src/n_heaps/priority_queue.py b/src/heaps/priority_queue.py similarity index 100% rename from src/n_heaps/priority_queue.py rename to src/heaps/priority_queue.py diff --git a/src/a_intro/ABSTRACT.md b/src/intro/ABSTRACT.md similarity index 100% rename from src/a_intro/ABSTRACT.md rename to src/intro/ABSTRACT.md diff --git a/src/a_intro/README.md b/src/intro/README.md similarity index 100% rename from src/a_intro/README.md rename to src/intro/README.md diff --git a/src/a_intro/__init__.py b/src/intro/__init__.py similarity index 71% rename from src/a_intro/__init__.py rename to src/intro/__init__.py index 22aedf3..ecf4ef8 100644 --- a/src/a_intro/__init__.py +++ b/src/intro/__init__.py @@ -1,4 +1,4 @@ -from src.k_number_theory.fib_mod import fib_mod_pisano, fib_mod_two_last +from src.number_theory.fib_mod import fib_mod_pisano, fib_mod_two_last from .fib import ( fib_bine, diff --git a/src/a_intro/fib.py b/src/intro/fib.py similarity index 100% rename from src/a_intro/fib.py rename to src/intro/fib.py diff --git a/src/a_intro/line_reflection.py b/src/intro/line_reflection.py similarity index 100% rename from src/a_intro/line_reflection.py rename to src/intro/line_reflection.py diff --git a/src/a_intro/max_power.py b/src/intro/max_power.py similarity index 100% rename from src/a_intro/max_power.py rename to src/intro/max_power.py diff --git a/src/a_intro/summary_ranges.py b/src/intro/summary_ranges.py similarity index 100% rename from src/a_intro/summary_ranges.py rename to src/intro/summary_ranges.py diff --git a/src/a_intro/third_max.py b/src/intro/third_max.py similarity index 100% rename from src/a_intro/third_max.py rename to src/intro/third_max.py diff --git a/src/k_number_theory/ABSTRACT.md b/src/number_theory/ABSTRACT.md similarity index 100% rename from src/k_number_theory/ABSTRACT.md rename to src/number_theory/ABSTRACT.md diff --git a/src/k_number_theory/README.md b/src/number_theory/README.md similarity index 100% rename from src/k_number_theory/README.md rename to src/number_theory/README.md diff --git a/src/k_number_theory/__init__.py b/src/number_theory/__init__.py similarity index 100% rename from src/k_number_theory/__init__.py rename to src/number_theory/__init__.py diff --git a/src/k_number_theory/array_gcd.py b/src/number_theory/array_gcd.py similarity index 100% rename from src/k_number_theory/array_gcd.py rename to src/number_theory/array_gcd.py diff --git a/src/k_number_theory/count_primes.py b/src/number_theory/count_primes.py similarity index 100% rename from src/k_number_theory/count_primes.py rename to src/number_theory/count_primes.py diff --git a/src/k_number_theory/divisors.py b/src/number_theory/divisors.py similarity index 100% rename from src/k_number_theory/divisors.py rename to src/number_theory/divisors.py diff --git a/src/k_number_theory/fib_mod.py b/src/number_theory/fib_mod.py similarity index 100% rename from src/k_number_theory/fib_mod.py rename to src/number_theory/fib_mod.py diff --git a/src/k_number_theory/primality_tests.py b/src/number_theory/primality_tests.py similarity index 100% rename from src/k_number_theory/primality_tests.py rename to src/number_theory/primality_tests.py diff --git a/src/k_number_theory/rsa.py b/src/number_theory/rsa.py similarity index 100% rename from src/k_number_theory/rsa.py rename to src/number_theory/rsa.py diff --git a/src/i_prefix_sums/ABSTRACT.md b/src/prefix_sums/ABSTRACT.md similarity index 100% rename from src/i_prefix_sums/ABSTRACT.md rename to src/prefix_sums/ABSTRACT.md diff --git a/src/i_prefix_sums/README.md b/src/prefix_sums/README.md similarity index 100% rename from src/i_prefix_sums/README.md rename to src/prefix_sums/README.md diff --git a/src/l_dp2/__init__.py b/src/prefix_sums/__init__.py similarity index 100% rename from src/l_dp2/__init__.py rename to src/prefix_sums/__init__.py diff --git a/src/i_prefix_sums/blur_image.py b/src/prefix_sums/blur_image.py similarity index 100% rename from src/i_prefix_sums/blur_image.py rename to src/prefix_sums/blur_image.py diff --git a/src/i_prefix_sums/count_subsequences.py b/src/prefix_sums/count_subsequences.py similarity index 100% rename from src/i_prefix_sums/count_subsequences.py rename to src/prefix_sums/count_subsequences.py diff --git a/src/i_prefix_sums/null_exchange.py b/src/prefix_sums/null_exchange.py similarity index 100% rename from src/i_prefix_sums/null_exchange.py rename to src/prefix_sums/null_exchange.py diff --git a/src/i_prefix_sums/product_except_self.py b/src/prefix_sums/product_except_self.py similarity index 100% rename from src/i_prefix_sums/product_except_self.py rename to src/prefix_sums/product_except_self.py diff --git a/src/i_prefix_sums/sales_sum.py b/src/prefix_sums/sales_sum.py similarity index 100% rename from src/i_prefix_sums/sales_sum.py rename to src/prefix_sums/sales_sum.py diff --git a/src/f_scanline/ABSTRACT.md b/src/scanline/ABSTRACT.md similarity index 100% rename from src/f_scanline/ABSTRACT.md rename to src/scanline/ABSTRACT.md diff --git a/src/f_scanline/README.md b/src/scanline/README.md similarity index 100% rename from src/f_scanline/README.md rename to src/scanline/README.md diff --git a/src/f_scanline/__init__.py b/src/scanline/__init__.py similarity index 70% rename from src/f_scanline/__init__.py rename to src/scanline/__init__.py index b00054e..749133b 100644 --- a/src/f_scanline/__init__.py +++ b/src/scanline/__init__.py @@ -1,4 +1,4 @@ -from src.f_scanline.count_segments import ( +from src.scanline.count_segments import ( count_segments, count_segments_bisect, ) diff --git a/src/f_scanline/act_sel.py b/src/scanline/act_sel.py similarity index 100% rename from src/f_scanline/act_sel.py rename to src/scanline/act_sel.py diff --git a/src/f_scanline/count_segments.py b/src/scanline/count_segments.py similarity index 100% rename from src/f_scanline/count_segments.py rename to src/scanline/count_segments.py diff --git a/src/f_scanline/max_profit.py b/src/scanline/max_profit.py similarity index 100% rename from src/f_scanline/max_profit.py rename to src/scanline/max_profit.py diff --git a/src/f_scanline/min_set_of_points.py b/src/scanline/min_set_of_points.py similarity index 100% rename from src/f_scanline/min_set_of_points.py rename to src/scanline/min_set_of_points.py diff --git a/src/f_scanline/points_cover.py b/src/scanline/points_cover.py similarity index 100% rename from src/f_scanline/points_cover.py rename to src/scanline/points_cover.py diff --git a/src/c_search/ABSTRACT.md b/src/search/ABSTRACT.md similarity index 100% rename from src/c_search/ABSTRACT.md rename to src/search/ABSTRACT.md diff --git a/src/c_search/README.md b/src/search/README.md similarity index 100% rename from src/c_search/README.md rename to src/search/README.md diff --git a/src/m_trees/__init__.py b/src/search/__init__.py similarity index 100% rename from src/m_trees/__init__.py rename to src/search/__init__.py diff --git a/src/c_search/binary_search.py b/src/search/binary_search.py similarity index 100% rename from src/c_search/binary_search.py rename to src/search/binary_search.py diff --git a/src/c_search/matrix_search.py b/src/search/matrix_search.py similarity index 100% rename from src/c_search/matrix_search.py rename to src/search/matrix_search.py diff --git a/src/c_search/search_range.py b/src/search/search_range.py similarity index 100% rename from src/c_search/search_range.py rename to src/search/search_range.py diff --git a/src/c_search/sqrt.py b/src/search/sqrt.py similarity index 100% rename from src/c_search/sqrt.py rename to src/search/sqrt.py diff --git a/src/d_sorting/ABSTRACT.md b/src/sorting/ABSTRACT.md similarity index 100% rename from src/d_sorting/ABSTRACT.md rename to src/sorting/ABSTRACT.md diff --git a/src/d_sorting/README.md b/src/sorting/README.md similarity index 100% rename from src/d_sorting/README.md rename to src/sorting/README.md diff --git a/src/n_heaps/__init__.py b/src/sorting/__init__.py similarity index 100% rename from src/n_heaps/__init__.py rename to src/sorting/__init__.py diff --git a/src/d_sorting/merge.py b/src/sorting/merge.py similarity index 100% rename from src/d_sorting/merge.py rename to src/sorting/merge.py diff --git a/src/d_sorting/partition.py b/src/sorting/partition.py similarity index 100% rename from src/d_sorting/partition.py rename to src/sorting/partition.py diff --git a/src/d_sorting/sort_array.py b/src/sorting/sort_array.py similarity index 96% rename from src/d_sorting/sort_array.py rename to src/sorting/sort_array.py index b6cd921..ebc04f1 100644 --- a/src/d_sorting/sort_array.py +++ b/src/sorting/sort_array.py @@ -1,8 +1,8 @@ from collections import deque from collections.abc import Callable -from src.d_sorting.merge import merge -from src.d_sorting.partition import partition2, partition3 +from src.sorting.merge import merge +from src.sorting.partition import partition2, partition3 # O(n^2), O(n log n) в среднем, TLE на больших входах diff --git a/src/d_sorting/sort_colors.py b/src/sorting/sort_colors.py similarity index 100% rename from src/d_sorting/sort_colors.py rename to src/sorting/sort_colors.py diff --git a/src/m_trees/ABSTRACT.md b/src/trees/ABSTRACT.md similarity index 100% rename from src/m_trees/ABSTRACT.md rename to src/trees/ABSTRACT.md diff --git a/src/m_trees/README.md b/src/trees/README.md similarity index 100% rename from src/m_trees/README.md rename to src/trees/README.md diff --git a/src/o_graphs/__init__.py b/src/trees/__init__.py similarity index 100% rename from src/o_graphs/__init__.py rename to src/trees/__init__.py diff --git a/src/m_trees/dfs.py b/src/trees/dfs.py similarity index 100% rename from src/m_trees/dfs.py rename to src/trees/dfs.py diff --git a/src/m_trees/dfs_iterative.py b/src/trees/dfs_iterative.py similarity index 98% rename from src/m_trees/dfs_iterative.py rename to src/trees/dfs_iterative.py index d5894f5..ad091ea 100644 --- a/src/m_trees/dfs_iterative.py +++ b/src/trees/dfs_iterative.py @@ -1,6 +1,6 @@ from typing import Literal -from src.m_trees.dfs import BNode, build_tree +from src.trees.dfs import BNode, build_tree # O(n) diff --git a/src/m_trees/is_bst.py b/src/trees/is_bst.py similarity index 97% rename from src/m_trees/is_bst.py rename to src/trees/is_bst.py index 18ae134..03f5318 100644 --- a/src/m_trees/is_bst.py +++ b/src/trees/is_bst.py @@ -1,7 +1,7 @@ from typing import Literal -from src.m_trees.dfs import BNode, build_tree -from src.m_trees.dfs_iterative import dfs_iterative +from src.trees.dfs import BNode, build_tree +from src.trees.dfs_iterative import dfs_iterative INF = 10**20 diff --git a/src/m_trees/is_general_bst.py b/src/trees/is_general_bst.py similarity index 91% rename from src/m_trees/is_general_bst.py rename to src/trees/is_general_bst.py index 99daf7d..0072e4a 100644 --- a/src/m_trees/is_general_bst.py +++ b/src/trees/is_general_bst.py @@ -1,5 +1,5 @@ -from src.m_trees.dfs import BNode, build_tree -from src.m_trees.dfs_iterative import dfs_iterative +from src.trees.dfs import BNode, build_tree +from src.trees.dfs_iterative import dfs_iterative INF = 10**20 diff --git a/src/m_trees/tree_height.py b/src/trees/tree_height.py similarity index 100% rename from src/m_trees/tree_height.py rename to src/trees/tree_height.py diff --git a/src/e_two_pointers/ABSTRACT.md b/src/two_pointers/ABSTRACT.md similarity index 100% rename from src/e_two_pointers/ABSTRACT.md rename to src/two_pointers/ABSTRACT.md diff --git a/src/e_two_pointers/README.md b/src/two_pointers/README.md similarity index 100% rename from src/e_two_pointers/README.md rename to src/two_pointers/README.md diff --git a/src/two_pointers/__init__.py b/src/two_pointers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/e_two_pointers/can_trasform.py b/src/two_pointers/can_trasform.py similarity index 100% rename from src/e_two_pointers/can_trasform.py rename to src/two_pointers/can_trasform.py diff --git a/src/e_two_pointers/max_professionalism.py b/src/two_pointers/max_professionalism.py similarity index 100% rename from src/e_two_pointers/max_professionalism.py rename to src/two_pointers/max_professionalism.py diff --git a/src/e_two_pointers/prizes.py b/src/two_pointers/prizes.py similarity index 100% rename from src/e_two_pointers/prizes.py rename to src/two_pointers/prizes.py diff --git a/src/e_two_pointers/prizes_2s.py b/src/two_pointers/prizes_2s.py similarity index 100% rename from src/e_two_pointers/prizes_2s.py rename to src/two_pointers/prizes_2s.py diff --git a/src/e_two_pointers/shortest_palindrome.py b/src/two_pointers/shortest_palindrome.py similarity index 100% rename from src/e_two_pointers/shortest_palindrome.py rename to src/two_pointers/shortest_palindrome.py diff --git a/src/e_two_pointers/two_sum.py b/src/two_pointers/two_sum.py similarity index 100% rename from src/e_two_pointers/two_sum.py rename to src/two_pointers/two_sum.py diff --git a/src/e_two_pointers/water.py b/src/two_pointers/water.py similarity index 100% rename from src/e_two_pointers/water.py rename to src/two_pointers/water.py diff --git a/tests/test_base_ds/test_bank_queue.py b/tests/test_base_ds/test_bank_queue.py index 95c4c0c..af14280 100644 --- a/tests/test_base_ds/test_bank_queue.py +++ b/tests/test_base_ds/test_bank_queue.py @@ -1,6 +1,6 @@ import pytest -from src.b_base_ds.bank_queue import average_waiting_time +from src.base_ds.bank_queue import average_waiting_time @pytest.mark.parametrize( diff --git a/tests/test_base_ds/test_brackets.py b/tests/test_base_ds/test_brackets.py index d523767..2ec5c61 100644 --- a/tests/test_base_ds/test_brackets.py +++ b/tests/test_base_ds/test_brackets.py @@ -1,6 +1,6 @@ import pytest -from src.b_base_ds.brackets import brackets +from src.base_ds.brackets import brackets @pytest.mark.parametrize( diff --git a/tests/test_base_ds/test_calculator.py b/tests/test_base_ds/test_calculator.py index 58ce3ce..413948a 100644 --- a/tests/test_base_ds/test_calculator.py +++ b/tests/test_base_ds/test_calculator.py @@ -1,6 +1,6 @@ import pytest -from src.b_base_ds.calculator import ( +from src.base_ds.calculator import ( calculator, evaluate_postfix, get_postfix_notation, diff --git a/tests/test_base_ds/test_max_stack.py b/tests/test_base_ds/test_max_stack.py index a0c486c..9183843 100644 --- a/tests/test_base_ds/test_max_stack.py +++ b/tests/test_base_ds/test_max_stack.py @@ -1,6 +1,6 @@ import pytest -from src.b_base_ds.max_stack import MaxStack +from src.base_ds.max_stack import MaxStack @pytest.mark.parametrize( diff --git a/tests/test_base_ds/test_net_packets.py b/tests/test_base_ds/test_net_packets.py index d62cdaa..4e1a290 100644 --- a/tests/test_base_ds/test_net_packets.py +++ b/tests/test_base_ds/test_net_packets.py @@ -1,6 +1,6 @@ import pytest -from src.b_base_ds.net_packets import net_packets +from src.base_ds.net_packets import net_packets @pytest.mark.parametrize( diff --git a/tests/test_base_ds/test_sliding_window.py b/tests/test_base_ds/test_sliding_window.py index 3436b82..663894e 100644 --- a/tests/test_base_ds/test_sliding_window.py +++ b/tests/test_base_ds/test_sliding_window.py @@ -2,7 +2,7 @@ import pytest -from src.b_base_ds.sliding_window import sliding_window_deque, sliding_window_naive +from src.base_ds.sliding_window import sliding_window_deque, sliding_window_naive @pytest.mark.parametrize("func", [sliding_window_naive, sliding_window_deque]) diff --git a/tests/test_dnc/test_count_smaller.py b/tests/test_dnc/test_count_smaller.py index 5bf0013..66e5028 100644 --- a/tests/test_dnc/test_count_smaller.py +++ b/tests/test_dnc/test_count_smaller.py @@ -2,7 +2,7 @@ import pytest -from src.g_dnc.count_smaller import count_smaller_bisect, count_smaller_merge +from src.dnc.count_smaller import count_smaller_bisect, count_smaller_merge @pytest.mark.parametrize("func", [count_smaller_bisect, count_smaller_merge]) diff --git a/tests/test_dnc/test_median_salary.py b/tests/test_dnc/test_median_salary.py index ca663fa..374a282 100644 --- a/tests/test_dnc/test_median_salary.py +++ b/tests/test_dnc/test_median_salary.py @@ -1,6 +1,6 @@ import pytest -from src.g_dnc.median_salary import median_salary +from src.dnc.median_salary import median_salary @pytest.mark.parametrize( diff --git a/tests/test_dnc/test_multiply.py b/tests/test_dnc/test_multiply.py index f65ccf3..d93d6b2 100644 --- a/tests/test_dnc/test_multiply.py +++ b/tests/test_dnc/test_multiply.py @@ -2,7 +2,7 @@ import pytest -from src.g_dnc.multiply import mul_dnc, mul_karatsuba, mul_naive +from src.dnc.multiply import mul_dnc, mul_karatsuba, mul_naive @pytest.mark.parametrize( diff --git a/tests/test_dnc/test_power.py b/tests/test_dnc/test_power.py index 99c1f8d..b12d28c 100644 --- a/tests/test_dnc/test_power.py +++ b/tests/test_dnc/test_power.py @@ -2,7 +2,7 @@ import pytest -from src.g_dnc.power import fast_power +from src.dnc.power import fast_power @pytest.mark.parametrize( diff --git a/tests/test_dnc/test_quick_select.py b/tests/test_dnc/test_quick_select.py index 23f440c..9df537b 100644 --- a/tests/test_dnc/test_quick_select.py +++ b/tests/test_dnc/test_quick_select.py @@ -1,6 +1,6 @@ import pytest -from src.g_dnc.kth_largest import quick_select +from src.dnc.kth_largest import quick_select @pytest.mark.parametrize( diff --git a/tests/test_dp/test_calculator.py b/tests/test_dp/test_calculator.py index aafc9d7..9c092f2 100644 --- a/tests/test_dp/test_calculator.py +++ b/tests/test_dp/test_calculator.py @@ -1,6 +1,6 @@ import pytest -from src.h_dp.calculator import calculator +from src.dp.calculator import calculator @pytest.mark.parametrize( diff --git a/tests/test_dp/test_coin_change.py b/tests/test_dp/test_coin_change.py index ba41d00..f891b94 100644 --- a/tests/test_dp/test_coin_change.py +++ b/tests/test_dp/test_coin_change.py @@ -1,6 +1,6 @@ import pytest -from src.h_dp.coin_change import coin_change +from src.dp.coin_change import coin_change @pytest.mark.parametrize( diff --git a/tests/test_dp/test_gold_storage.py b/tests/test_dp/test_gold_storage.py index a476411..3aaf99b 100644 --- a/tests/test_dp/test_gold_storage.py +++ b/tests/test_dp/test_gold_storage.py @@ -2,7 +2,7 @@ import pytest -from src.h_dp.gold_storage_robbery import rob_gold_storage_dp, rob_gold_storage_dp2 +from src.dp.gold_storage_robbery import rob_gold_storage_dp, rob_gold_storage_dp2 @pytest.mark.parametrize( diff --git a/tests/test_dp/test_length_of_lis.py b/tests/test_dp/test_length_of_lis.py index ce3a1da..4ffe01a 100644 --- a/tests/test_dp/test_length_of_lis.py +++ b/tests/test_dp/test_length_of_lis.py @@ -2,7 +2,7 @@ import pytest -from src.h_dp.length_of_lis import lis_bisect, lis_naive +from src.dp.length_of_lis import lis_bisect, lis_naive @pytest.mark.parametrize("func", [lis_naive, lis_bisect]) diff --git a/tests/test_dp/test_length_of_lms.py b/tests/test_dp/test_length_of_lms.py index 8dce5ab..931da29 100644 --- a/tests/test_dp/test_length_of_lms.py +++ b/tests/test_dp/test_length_of_lms.py @@ -1,6 +1,6 @@ import pytest -from src.h_dp.length_of_lms import lms +from src.dp.length_of_lms import lms @pytest.mark.parametrize( diff --git a/tests/test_dp/test_lnis.py b/tests/test_dp/test_lnis.py index 38f421d..81542b1 100644 --- a/tests/test_dp/test_lnis.py +++ b/tests/test_dp/test_lnis.py @@ -1,6 +1,6 @@ import pytest -from src.h_dp.lnis import lnis +from src.dp.lnis import lnis @pytest.mark.parametrize( diff --git a/tests/test_dp2/test_editing.py b/tests/test_dp2/test_editing.py index e08e11e..5e555d8 100644 --- a/tests/test_dp2/test_editing.py +++ b/tests/test_dp2/test_editing.py @@ -2,12 +2,12 @@ import pytest -from src.l_dp2.edit_candidates import edit_candidates -from src.l_dp2.edit_distance import ( +from src.dp2.edit_candidates import edit_candidates +from src.dp2.edit_distance import ( edit_distance_dp, edit_distance_rec, ) -from src.l_dp2.edit_path import Operation, PathItem, edit_path +from src.dp2.edit_path import Operation, PathItem, edit_path @pytest.mark.parametrize("func", [edit_distance_rec, edit_distance_dp]) diff --git a/tests/test_dp2/test_lcs.py b/tests/test_dp2/test_lcs.py index 9246034..879ab36 100644 --- a/tests/test_dp2/test_lcs.py +++ b/tests/test_dp2/test_lcs.py @@ -2,7 +2,7 @@ import pytest -from src.l_dp2.lcs import lcs_dp, lcs_rec +from src.dp2.lcs import lcs_dp, lcs_rec @pytest.mark.parametrize( diff --git a/tests/test_dp2/test_money_robot.py b/tests/test_dp2/test_money_robot.py index 14578b1..35aae92 100644 --- a/tests/test_dp2/test_money_robot.py +++ b/tests/test_dp2/test_money_robot.py @@ -1,6 +1,6 @@ import pytest -from src.l_dp2.max_robot_path import max_robot_path +from src.dp2.max_robot_path import max_robot_path # def generate_field() -> tuple[int, int, list[list[int]]]: # n, m = random.randint(1, 10), random.randint(1, 10) diff --git a/tests/test_dsu/__init__.py b/tests/test_dsu/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_dsu/test_auto_analysis.py b/tests/test_dsu/test_auto_analysis.py new file mode 100644 index 0000000..d79ce3c --- /dev/null +++ b/tests/test_dsu/test_auto_analysis.py @@ -0,0 +1,151 @@ +from src.dsu.auto_analysis import auto_analysis + +# -------------------- +# БАЗОВЫЕ СЛУЧАИ +# -------------------- + + +def test_no_constraints() -> None: + assert auto_analysis(5, 0, 0, [], []) is True + + +def test_only_equals() -> None: + n = 4 + equals = [(1, 2), (2, 3), (3, 4)] + assert auto_analysis(n, len(equals), 0, equals, []) is True + + +def test_only_not_equals() -> None: + n = 4 + not_equals = [(1, 2), (2, 3), (3, 4)] + assert auto_analysis(n, 0, len(not_equals), [], not_equals) is True + + +# -------------------- +# ПРОТИВОРЕЧИЯ +# -------------------- + + +def test_simple_conflict() -> None: + n = 2 + equals = [(1, 2)] + not_equals = [(1, 2)] + assert auto_analysis(n, 1, 1, equals, not_equals) is False + + +def test_indirect_conflict() -> None: + n = 3 + equals = [(1, 2), (2, 3)] + not_equals = [(1, 3)] + assert auto_analysis(n, 2, 1, equals, not_equals) is False + + +def test_large_conflict_chain() -> None: + n = 5 + equals = [(1, 2), (2, 3), (3, 4), (4, 5)] + not_equals = [(1, 5)] + assert auto_analysis(n, 4, 1, equals, not_equals) is False + + +# -------------------- +# КОРРЕКТНЫЕ СЛУЧАИ +# -------------------- + + +def test_separate_components() -> None: + n = 4 + equals = [(1, 2), (3, 4)] + not_equals = [(1, 3)] + assert auto_analysis(n, 2, 1, equals, not_equals) is True + + +def test_multiple_components() -> None: + n = 6 + equals = [(1, 2), (3, 4), (5, 6)] + not_equals = [(1, 3), (2, 5), (4, 6)] + assert auto_analysis(n, 3, 3, equals, not_equals) is True + + +# -------------------- +# САМОССЫЛКИ +# -------------------- + + +def test_self_equality() -> None: + n = 3 + equals = [(1, 1), (2, 2)] + assert auto_analysis(n, 2, 0, equals, []) is True + + +def test_self_inequality() -> None: + n = 3 + not_equals = [(1, 1)] + assert auto_analysis(n, 0, 1, [], not_equals) is False + + +# -------------------- +# ДУБЛИРУЮЩИЕ ОГРАНИЧЕНИЯ +# -------------------- + + +def test_duplicate_equals() -> None: + n = 3 + equals = [(1, 2), (1, 2), (2, 1)] + assert auto_analysis(n, 3, 0, equals, []) is True + + +def test_duplicate_not_equals() -> None: + n = 3 + not_equals = [(1, 2), (1, 2), (2, 1)] + assert auto_analysis(n, 0, 3, [], not_equals) is True + + +# -------------------- +# СМЕШАННЫЕ СЛОЖНЫЕ СЛУЧАИ +# -------------------- + + +def test_complex_valid() -> None: + n = 6 + equals = [(1, 2), (2, 3), (4, 5)] + not_equals = [(1, 4), (3, 6), (5, 6)] + assert auto_analysis(n, 3, 3, equals, not_equals) is True + + +def test_complex_invalid() -> None: + n = 6 + equals = [(1, 2), (2, 3), (3, 4)] + not_equals = [(1, 4), (2, 5)] + assert auto_analysis(n, 3, 2, equals, not_equals) is False + + +# -------------------- +# ГРАНИЧНЫЕ СЛУЧАИ +# -------------------- + + +def test_single_variable() -> None: + assert auto_analysis(1, 0, 0, [], []) is True + + +def test_single_variable_conflict() -> None: + assert auto_analysis(1, 0, 1, [], [(1, 1)]) is False + + +# -------------------- +# СТРЕСС (логический) +# -------------------- + + +def test_long_chain_no_conflict() -> None: + n = 1000 + equals = [(i, i + 1) for i in range(1, n)] + not_equals = [(1, n + 1)] if n + 1 <= n else [] + assert auto_analysis(n, len(equals), len(not_equals), equals, not_equals) is True + + +def test_long_chain_with_conflict() -> None: + n = 1000 + equals = [(i, i + 1) for i in range(1, n)] + not_equals = [(1, n)] + assert auto_analysis(n, len(equals), 1, equals, not_equals) is False diff --git a/tests/test_dsu/test_dsu.py b/tests/test_dsu/test_dsu.py new file mode 100644 index 0000000..6d84b97 --- /dev/null +++ b/tests/test_dsu/test_dsu.py @@ -0,0 +1,215 @@ +import pytest + +from src.dsu.dsu import DSU, ArrayDSU, CompressedForestDSU, ForestDSU + +DSU_CLASSES: list[type[DSU]] = [ArrayDSU, ForestDSU, CompressedForestDSU] + + +@pytest.mark.parametrize("cls", DSU_CLASSES) +def test_make_set_and_find_singletons(cls: type[DSU]) -> None: + dsu = cls(5) + + for i in range(1, 6): + dsu.make_set(i) + + for i in range(1, 6): + assert dsu.find(i) == i + + +@pytest.mark.parametrize("cls", DSU_CLASSES) +def test_union_two_elements(cls: type[DSU]) -> None: + dsu = cls(5) + for i in range(1, 6): + dsu.make_set(i) + + dsu.union(1, 2) + + assert dsu.find(1) == dsu.find(2) + assert dsu.find(3) == 3 + assert dsu.find(4) == 4 + assert dsu.find(5) == 5 + + +@pytest.mark.parametrize("cls", DSU_CLASSES) +def test_union_chain(cls: type[DSU]) -> None: + dsu = cls(5) + for i in range(1, 6): + dsu.make_set(i) + + dsu.union(1, 2) + dsu.union(2, 3) + dsu.union(3, 4) + + root = dsu.find(1) + assert dsu.find(2) == root + assert dsu.find(3) == root + assert dsu.find(4) == root + assert dsu.find(5) != root + + +@pytest.mark.parametrize("cls", DSU_CLASSES) +def test_union_two_sets(cls: type[DSU]) -> None: + dsu = cls(6) + for i in range(1, 7): + dsu.make_set(i) + + dsu.union(1, 2) + dsu.union(3, 4) + dsu.union(2, 3) + + root = dsu.find(1) + assert dsu.find(2) == root + assert dsu.find(3) == root + assert dsu.find(4) == root + + assert dsu.find(5) == 5 + assert dsu.find(6) == 6 + + +@pytest.mark.parametrize("cls", DSU_CLASSES) +def test_repeated_union_does_not_break_structure(cls: type[DSU]) -> None: + dsu = cls(4) + for i in range(1, 5): + dsu.make_set(i) + + dsu.union(1, 2) + root = dsu.find(1) + + dsu.union(1, 2) + dsu.union(2, 1) + dsu.union(1, 1) + + assert dsu.find(1) == root + assert dsu.find(2) == root + assert dsu.find(3) == 3 + assert dsu.find(4) == 4 + + +def test_array_dsu_set_id_is_minimum_element() -> None: + dsu = ArrayDSU(9) + for i in range(1, 10): + dsu.make_set(i) + + dsu.union(9, 3) + dsu.union(3, 2) + dsu.union(2, 4) + dsu.union(4, 7) + dsu.union(6, 1) + dsu.union(1, 8) + + assert dsu.smallest == [0, 1, 2, 2, 2, 5, 1, 2, 1, 2] + + for i in [9, 3, 2, 4, 7]: + assert dsu.find(i) == 2 + + assert dsu.find(5) == 5 + + for i in [6, 1, 8]: + assert dsu.find(i) == 1 + + +def test_forest_dsu_parent_and_rank_after_known_unions() -> None: + dsu = ForestDSU(9) + for i in range(1, 10): + dsu.make_set(i) + + dsu.union(9, 3) + dsu.union(3, 2) + dsu.union(2, 4) + dsu.union(4, 7) + dsu.union(6, 1) + dsu.union(1, 8) + + assert dsu.parent == [0, 1, 3, 3, 3, 5, 1, 3, 1, 3] + assert dsu.rank == [0, 1, 0, 1, 0, 0, 0, 0, 0, 0] + + +def test_forest_dsu_union_by_rank_when_left_rank_greater() -> None: + dsu = ForestDSU(4) + for i in range(1, 5): + dsu.make_set(i) + + dsu.union(1, 2) + dsu.union(3, 2) + + root = dsu.find(1) + + assert dsu.find(2) == root + assert dsu.find(3) == root + assert dsu.rank[root] == 1 + + +def test_forest_dsu_rank_increases_only_for_equal_ranks() -> None: + dsu = ForestDSU(4) + for i in range(1, 5): + dsu.make_set(i) + + dsu.union(1, 2) + root = dsu.find(1) + + assert dsu.rank[root] == 1 + + dsu.union(3, 1) + + assert dsu.find(3) == root + assert dsu.rank[root] == 1 + + +def test_compressed_forest_find_compresses_path() -> None: + dsu = CompressedForestDSU(5) + for i in range(1, 6): + dsu.make_set(i) + + dsu.parent[1] = 2 + dsu.parent[2] = 3 + dsu.parent[3] = 4 + dsu.parent[4] = 5 + dsu.parent[5] = 5 + + assert dsu.find(1) == 5 + + assert dsu.parent[1] == 5 + assert dsu.parent[2] == 5 + assert dsu.parent[3] == 5 + assert dsu.parent[4] == 5 + assert dsu.parent[5] == 5 + + +def test_compressed_forest_find_on_root_keeps_root() -> None: + dsu = CompressedForestDSU(3) + for i in range(1, 4): + dsu.make_set(i) + + assert dsu.find(2) == 2 + assert dsu.parent[2] == 2 + + +@pytest.mark.parametrize("cls", DSU_CLASSES) +def test_all_elements_can_be_merged_into_one_set(cls: type[DSU]) -> None: + dsu = cls(10) + for i in range(1, 11): + dsu.make_set(i) + + for i in range(1, 10): + dsu.union(i, i + 1) + + root = dsu.find(1) + + for i in range(1, 11): + assert dsu.find(i) == root + + +def test_array_dsu_union_uses_minimum_id_after_merging_sets() -> None: + dsu = ArrayDSU(6) + for i in range(1, 7): + dsu.make_set(i) + + dsu.union(4, 6) + dsu.union(2, 3) + dsu.union(6, 3) + + for i in [2, 3, 4, 6]: + assert dsu.find(i) == 2 + + assert dsu.find(1) == 1 + assert dsu.find(5) == 5 diff --git a/tests/test_dsu/test_table_union.py b/tests/test_dsu/test_table_union.py new file mode 100644 index 0000000..bba173e --- /dev/null +++ b/tests/test_dsu/test_table_union.py @@ -0,0 +1,155 @@ +from src.dsu.max_dsu import MaxDSU +from src.dsu.table_union import table_union + +# -------------------- +# БАЗОВЫЕ СЛУЧАИ +# -------------------- + + +def test_single_element() -> None: + assert table_union([5], [(1, 1)]) == [5] + + +def test_two_elements_merge() -> None: + assert table_union([1, 2], [(1, 2)]) == [3] + + +def test_self_union() -> None: + assert table_union([10, 20], [(1, 1), (2, 2)]) == [20, 20] + + +# -------------------- +# ПРИМЕРЫ ИЗ УСЛОВИЯ +# -------------------- + + +def test_example_1() -> None: + sizes = [1, 1, 1, 1, 1] + queries = [(3, 5), (2, 4), (1, 4), (5, 4), (5, 3)] + assert table_union(sizes, queries) == [2, 2, 3, 5, 5] + + +def test_example_2() -> None: + sizes = [10, 0, 5, 0, 3, 3] + queries = [(6, 6), (6, 5), (5, 4), (4, 3)] + assert table_union(sizes, queries) == [10, 10, 10, 11] + + +# -------------------- +# ЦЕПОЧКИ +# -------------------- + + +def test_linear_chain() -> None: + sizes = [1, 2, 3, 4] + queries = [(1, 2), (2, 3), (3, 4)] + assert table_union(sizes, queries) == [4, 6, 10] + + +def test_reverse_chain() -> None: + sizes = [1, 2, 3, 4] + queries = [(4, 3), (3, 2), (2, 1)] + assert table_union(sizes, queries) == [7, 9, 10] + + +# -------------------- +# ЗВЕЗДА +# -------------------- + + +def test_star() -> None: + sizes = [1, 1, 1, 1, 1] + queries = [(1, 2), (1, 3), (1, 4), (1, 5)] + assert table_union(sizes, queries) == [2, 3, 4, 5] + + +# -------------------- +# ПОВТОРНЫЕ ОБЪЕДИНЕНИЯ +# -------------------- + + +def test_repeated_unions() -> None: + sizes = [1, 2, 3] + queries = [(1, 2), (1, 2), (2, 1), (2, 3)] + assert table_union(sizes, queries) == [3, 3, 3, 6] + + +# -------------------- +# КОСВЕННЫЕ СВЯЗИ +# -------------------- + + +def test_indirect_connections() -> None: + sizes = [1, 2, 3] + queries = [(1, 2), (2, 3), (1, 3)] + assert table_union(sizes, queries) == [3, 6, 6] + + +# -------------------- +# НУЛЕВЫЕ ЗНАЧЕНИЯ +# -------------------- + + +def test_all_zero() -> None: + sizes = [0, 0, 0] + queries = [(1, 2), (2, 3)] + assert table_union(sizes, queries) == [0, 0] + + +def test_mixed_zero() -> None: + sizes = [0, 5, 0, 3] + queries = [(1, 2), (3, 4), (1, 3)] + assert table_union(sizes, queries) == [5, 5, 8] + + +# -------------------- +# ПРОВЕРКА curr_max +# -------------------- + + +def test_curr_max_updates() -> None: + dsu = MaxDSU([1, 2, 3]) + assert dsu.curr_max == 3 + + dsu.union(0, 1) + assert dsu.curr_max == 3 + + dsu.union(1, 2) + assert dsu.curr_max == 6 + + +# -------------------- +# БОЛЬШИЕ ТЕСТЫ +# -------------------- + + +def test_large_chain() -> None: + n = 1000 + sizes = [1] * n + queries = [(i, i + 1) for i in range(1, n)] + result = table_union(sizes, queries) + assert result[-1] == n + + +def test_large_star() -> None: + n = 1000 + sizes = [1] * n + queries = [(1, i) for i in range(2, n + 1)] + result = table_union(sizes, queries) + assert result[-1] == n + + +# -------------------- +# СЛОЖНЫЙ СЦЕНАРИЙ +# -------------------- + + +def test_complex_case() -> None: + sizes = [5, 1, 1, 1, 10] + queries = [ + (2, 3), # 2 + (3, 4), # 3 + (1, 2), # 8 + (5, 1), # 18 + ] + assert table_union(sizes, queries) == [10, 10, 10, 18] diff --git a/tests/test_graphs/test_greed_stone.py b/tests/test_graphs/test_greed_stone.py index e69a43a..c08ea55 100644 --- a/tests/test_graphs/test_greed_stone.py +++ b/tests/test_graphs/test_greed_stone.py @@ -1,6 +1,6 @@ import pytest -from src.o_graphs.greed_stone import greed_stone +from src.graphs.greed_stone import greed_stone @pytest.mark.parametrize( diff --git a/tests/test_graphs/test_journey_path.py b/tests/test_graphs/test_journey_path.py index b325e15..eb9d4e3 100644 --- a/tests/test_graphs/test_journey_path.py +++ b/tests/test_graphs/test_journey_path.py @@ -3,7 +3,7 @@ import pytest -from src.o_graphs.journey_path import Flight, get_route, get_route_enhanced +from src.graphs.journey_path import Flight, get_route, get_route_enhanced @pytest.mark.parametrize("func", [get_route, get_route_enhanced]) diff --git a/tests/test_greedy/test_cargo_delivery.py b/tests/test_greedy/test_cargo_delivery.py index dbd5f84..9a44994 100644 --- a/tests/test_greedy/test_cargo_delivery.py +++ b/tests/test_greedy/test_cargo_delivery.py @@ -1,6 +1,6 @@ import pytest -from src.j_greedy.knapsack import greedy_knapsack +from src.greedy.knapsack import greedy_knapsack @pytest.mark.parametrize( diff --git a/tests/test_greedy/test_convex_hull.py b/tests/test_greedy/test_convex_hull.py index 56d78ef..5f32155 100644 --- a/tests/test_greedy/test_convex_hull.py +++ b/tests/test_greedy/test_convex_hull.py @@ -1,6 +1,6 @@ import pytest -from src.j_greedy.convex_hull import convex_hull +from src.greedy.convex_hull import convex_hull @pytest.mark.parametrize( diff --git a/tests/test_greedy/test_huffman.py b/tests/test_greedy/test_huffman.py index c435a2a..1616644 100644 --- a/tests/test_greedy/test_huffman.py +++ b/tests/test_greedy/test_huffman.py @@ -1,6 +1,6 @@ import pytest -from src.j_greedy.huffman import ( +from src.greedy.huffman import ( huffman_decode, huffman_encode, huffman_tree, diff --git a/tests/test_greedy/test_max_terms.py b/tests/test_greedy/test_max_terms.py index 3345910..2f3c36e 100644 --- a/tests/test_greedy/test_max_terms.py +++ b/tests/test_greedy/test_max_terms.py @@ -1,6 +1,6 @@ import pytest -from src.j_greedy.max_terms import max_terms +from src.greedy.max_terms import max_terms @pytest.mark.parametrize( diff --git a/tests/test_heaps/test_heap_sort.py b/tests/test_heaps/test_heap_sort.py index b0fee6f..5fda1d2 100644 --- a/tests/test_heaps/test_heap_sort.py +++ b/tests/test_heaps/test_heap_sort.py @@ -2,7 +2,7 @@ import pytest -from src.n_heaps.heap_sort import heap_sort, heap_sort_inplace +from src.heaps.heap_sort import heap_sort, heap_sort_inplace @pytest.mark.parametrize( diff --git a/tests/test_heaps/test_heapify.py b/tests/test_heaps/test_heapify.py index 855ab10..24c97f4 100644 --- a/tests/test_heaps/test_heapify.py +++ b/tests/test_heaps/test_heapify.py @@ -1,6 +1,6 @@ import pytest -from src.n_heaps.heapify import heapify +from src.heaps.heapify import heapify def is_min_heap(a: list[int]) -> bool: diff --git a/tests/test_heaps/test_huffman.py b/tests/test_heaps/test_huffman.py index 0db8380..fe654c9 100644 --- a/tests/test_heaps/test_huffman.py +++ b/tests/test_heaps/test_huffman.py @@ -1,6 +1,6 @@ import pytest -from src.n_heaps.huffman import huffman_decode, huffman_encode, huffman_tree +from src.heaps.huffman import huffman_decode, huffman_encode, huffman_tree # O(n) diff --git a/tests/test_heaps/test_parallel.py b/tests/test_heaps/test_parallel.py index 39f1476..15fd975 100644 --- a/tests/test_heaps/test_parallel.py +++ b/tests/test_heaps/test_parallel.py @@ -1,6 +1,6 @@ import pytest -from src.n_heaps.parallel import parallel +from src.heaps.parallel import parallel def test_parallel_sample_1() -> None: diff --git a/tests/test_heaps/test_priority_queue.py b/tests/test_heaps/test_priority_queue.py index a59b65d..08dbb06 100644 --- a/tests/test_heaps/test_priority_queue.py +++ b/tests/test_heaps/test_priority_queue.py @@ -1,6 +1,6 @@ import pytest -from src.n_heaps.priority_queue import PriorityQueue +from src.heaps.priority_queue import PriorityQueue def is_max_heap(a: list[int]) -> bool: diff --git a/tests/test_intro/test_fib.py b/tests/test_intro/test_fib.py index 5bf566e..4700d1f 100644 --- a/tests/test_intro/test_fib.py +++ b/tests/test_intro/test_fib.py @@ -2,7 +2,7 @@ import pytest -from src.a_intro import ( +from src.intro import ( fib_bine, fib_mod_pisano, fib_mod_two_last, diff --git a/tests/test_intro/test_line_reflection.py b/tests/test_intro/test_line_reflection.py index 75072e5..4725434 100644 --- a/tests/test_intro/test_line_reflection.py +++ b/tests/test_intro/test_line_reflection.py @@ -1,6 +1,6 @@ import pytest -from src.a_intro.line_reflection import is_reflected +from src.intro.line_reflection import is_reflected @pytest.mark.parametrize( diff --git a/tests/test_intro/test_max_power.py b/tests/test_intro/test_max_power.py index 1242e7d..8904abe 100644 --- a/tests/test_intro/test_max_power.py +++ b/tests/test_intro/test_max_power.py @@ -1,6 +1,6 @@ import pytest -from src.a_intro.max_power import max_power +from src.intro.max_power import max_power @pytest.mark.parametrize( diff --git a/tests/test_intro/test_summary_ranges.py b/tests/test_intro/test_summary_ranges.py index bb79214..ccd3fac 100644 --- a/tests/test_intro/test_summary_ranges.py +++ b/tests/test_intro/test_summary_ranges.py @@ -1,6 +1,6 @@ import pytest -from src.a_intro.summary_ranges import summary_ranges +from src.intro.summary_ranges import summary_ranges @pytest.mark.parametrize( diff --git a/tests/test_intro/test_third_max.py b/tests/test_intro/test_third_max.py index 69827f1..3001169 100644 --- a/tests/test_intro/test_third_max.py +++ b/tests/test_intro/test_third_max.py @@ -1,6 +1,6 @@ import pytest -from src.a_intro.third_max import third_max +from src.intro.third_max import third_max @pytest.mark.parametrize( diff --git a/tests/test_number_theory/test_count_primes.py b/tests/test_number_theory/test_count_primes.py index 92cccd5..484ae81 100644 --- a/tests/test_number_theory/test_count_primes.py +++ b/tests/test_number_theory/test_count_primes.py @@ -2,7 +2,7 @@ import pytest -from src.k_number_theory.count_primes import count_primes_sieve, count_primes_sqrt +from src.number_theory.count_primes import count_primes_sieve, count_primes_sqrt @pytest.mark.parametrize("func", [count_primes_sqrt, count_primes_sieve]) diff --git a/tests/test_number_theory/test_divisors.py b/tests/test_number_theory/test_divisors.py index 75f4ad7..f3eba21 100644 --- a/tests/test_number_theory/test_divisors.py +++ b/tests/test_number_theory/test_divisors.py @@ -2,7 +2,7 @@ import pytest -from src.k_number_theory.divisors import closest_divisors, divisors_naive, divisors_sqrt +from src.number_theory.divisors import closest_divisors, divisors_naive, divisors_sqrt @pytest.mark.parametrize("func", [divisors_naive, divisors_sqrt]) diff --git a/tests/test_number_theory/test_gcd.py b/tests/test_number_theory/test_gcd.py index 41f21bb..f79aab0 100644 --- a/tests/test_number_theory/test_gcd.py +++ b/tests/test_number_theory/test_gcd.py @@ -2,7 +2,7 @@ import pytest -from src.k_number_theory.array_gcd import gcd_euclid, gcd_euclid_rec, gcd_naive +from src.number_theory.array_gcd import gcd_euclid, gcd_euclid_rec, gcd_naive @pytest.mark.parametrize( diff --git a/tests/test_number_theory/test_primality_tests.py b/tests/test_number_theory/test_primality_tests.py index af39755..0a30037 100644 --- a/tests/test_number_theory/test_primality_tests.py +++ b/tests/test_number_theory/test_primality_tests.py @@ -1,6 +1,6 @@ import pytest -from src.k_number_theory.primality_tests import primality_tests +from src.number_theory.primality_tests import primality_tests @pytest.mark.parametrize( diff --git a/tests/test_number_theory/test_rsa.py b/tests/test_number_theory/test_rsa.py index d48cacc..ea055e2 100644 --- a/tests/test_number_theory/test_rsa.py +++ b/tests/test_number_theory/test_rsa.py @@ -1,6 +1,6 @@ import pytest -from src.k_number_theory.rsa import encrypt, generate_keypair +from src.number_theory.rsa import encrypt, generate_keypair @pytest.mark.parametrize( diff --git a/tests/test_prefix_sums/test_blur_image.py b/tests/test_prefix_sums/test_blur_image.py index df825a6..58a6d99 100644 --- a/tests/test_prefix_sums/test_blur_image.py +++ b/tests/test_prefix_sums/test_blur_image.py @@ -2,7 +2,7 @@ import pytest -from src.i_prefix_sums.blur_image import box_filter_naive, box_filter_ps +from src.prefix_sums.blur_image import box_filter_naive, box_filter_ps @pytest.mark.parametrize( diff --git a/tests/test_prefix_sums/test_count_subsequences.py b/tests/test_prefix_sums/test_count_subsequences.py index f420a77..9d11537 100644 --- a/tests/test_prefix_sums/test_count_subsequences.py +++ b/tests/test_prefix_sums/test_count_subsequences.py @@ -3,7 +3,7 @@ import pytest -from src.i_prefix_sums.count_subsequences import count_subsequences_naive, count_subsequences_ps +from src.prefix_sums.count_subsequences import count_subsequences_naive, count_subsequences_ps @pytest.mark.parametrize( diff --git a/tests/test_prefix_sums/test_null_exchange.py b/tests/test_prefix_sums/test_null_exchange.py index ed37984..8885805 100644 --- a/tests/test_prefix_sums/test_null_exchange.py +++ b/tests/test_prefix_sums/test_null_exchange.py @@ -1,6 +1,6 @@ import pytest -from src.i_prefix_sums.null_exchange import null_exchange +from src.prefix_sums.null_exchange import null_exchange @pytest.mark.parametrize( diff --git a/tests/test_prefix_sums/test_product_except_self.py b/tests/test_prefix_sums/test_product_except_self.py index 6f846d4..9eaac7a 100644 --- a/tests/test_prefix_sums/test_product_except_self.py +++ b/tests/test_prefix_sums/test_product_except_self.py @@ -1,6 +1,6 @@ import pytest -from src.i_prefix_sums.product_except_self import product_except_self +from src.prefix_sums.product_except_self import product_except_self @pytest.mark.parametrize( diff --git a/tests/test_prefix_sums/test_sales_sum.py b/tests/test_prefix_sums/test_sales_sum.py index 039d8e6..fa8cf82 100644 --- a/tests/test_prefix_sums/test_sales_sum.py +++ b/tests/test_prefix_sums/test_sales_sum.py @@ -1,6 +1,6 @@ import pytest -from src.i_prefix_sums.sales_sum import sales_sum +from src.prefix_sums.sales_sum import sales_sum @pytest.mark.parametrize( diff --git a/tests/test_scanline/test_act_sel.py b/tests/test_scanline/test_act_sel.py index 71ad0c1..3e28319 100644 --- a/tests/test_scanline/test_act_sel.py +++ b/tests/test_scanline/test_act_sel.py @@ -2,7 +2,7 @@ import pytest -from src.f_scanline.act_sel import act_sel +from src.scanline.act_sel import act_sel @pytest.mark.parametrize("func", [act_sel]) diff --git a/tests/test_scanline/test_max_profit.py b/tests/test_scanline/test_max_profit.py index 91d83c1..7b03a0c 100644 --- a/tests/test_scanline/test_max_profit.py +++ b/tests/test_scanline/test_max_profit.py @@ -1,6 +1,6 @@ import pytest -from src.f_scanline.max_profit import job_scheduling +from src.scanline.max_profit import job_scheduling @pytest.mark.parametrize( diff --git a/tests/test_scanline/test_min_set_of_points.py b/tests/test_scanline/test_min_set_of_points.py index 42ecb04..fb99681 100644 --- a/tests/test_scanline/test_min_set_of_points.py +++ b/tests/test_scanline/test_min_set_of_points.py @@ -1,6 +1,6 @@ import pytest -from src.f_scanline.min_set_of_points import min_set_of_points +from src.scanline.min_set_of_points import min_set_of_points @pytest.mark.parametrize( diff --git a/tests/test_scanline/test_point_cover.py b/tests/test_scanline/test_point_cover.py index 2144ef3..7f0788b 100644 --- a/tests/test_scanline/test_point_cover.py +++ b/tests/test_scanline/test_point_cover.py @@ -2,7 +2,7 @@ import pytest -from src.f_scanline.points_cover import points_cover_naive, points_cover_scanline +from src.scanline.points_cover import points_cover_naive, points_cover_scanline @pytest.mark.parametrize("func", [points_cover_naive, points_cover_scanline]) diff --git a/tests/test_scanline/test_points_and_segments.py b/tests/test_scanline/test_points_and_segments.py index 7a1e513..d398f40 100644 --- a/tests/test_scanline/test_points_and_segments.py +++ b/tests/test_scanline/test_points_and_segments.py @@ -2,7 +2,7 @@ import pytest -from src.f_scanline import ( +from src.scanline import ( count_segments, count_segments_bisect, ) diff --git a/tests/test_search/test_binary_search.py b/tests/test_search/test_binary_search.py index 94a305e..35551ad 100644 --- a/tests/test_search/test_binary_search.py +++ b/tests/test_search/test_binary_search.py @@ -2,7 +2,7 @@ import pytest -from src.c_search.binary_search import binary_search, exp_search +from src.search.binary_search import binary_search, exp_search @pytest.mark.parametrize("func", [binary_search, exp_search]) diff --git a/tests/test_search/test_matrix_search.py b/tests/test_search/test_matrix_search.py index 920bb54..f3dcc7f 100644 --- a/tests/test_search/test_matrix_search.py +++ b/tests/test_search/test_matrix_search.py @@ -1,6 +1,6 @@ import pytest -from src.c_search.matrix_search import ladder_search +from src.search.matrix_search import ladder_search @pytest.mark.parametrize( diff --git a/tests/test_search/test_search_range.py b/tests/test_search/test_search_range.py index 15bd776..cfb9e96 100644 --- a/tests/test_search/test_search_range.py +++ b/tests/test_search/test_search_range.py @@ -1,6 +1,6 @@ import pytest -from src.c_search.search_range import lower_bound, search_range, upper_bound +from src.search.search_range import lower_bound, search_range, upper_bound @pytest.mark.parametrize( diff --git a/tests/test_search/test_sqrt.py b/tests/test_search/test_sqrt.py index e7fbd06..6fd6cd0 100644 --- a/tests/test_search/test_sqrt.py +++ b/tests/test_search/test_sqrt.py @@ -1,6 +1,6 @@ import pytest -from src.c_search.sqrt import sqrt +from src.search.sqrt import sqrt @pytest.mark.parametrize( diff --git a/tests/test_sorting/test_merge.py b/tests/test_sorting/test_merge.py index 6fa3919..1e0a361 100644 --- a/tests/test_sorting/test_merge.py +++ b/tests/test_sorting/test_merge.py @@ -1,6 +1,6 @@ import pytest -from src.d_sorting.merge import merge, merge_inplace +from src.sorting.merge import merge, merge_inplace @pytest.mark.parametrize( diff --git a/tests/test_sorting/test_partition.py b/tests/test_sorting/test_partition.py index 1e09927..fdc4063 100644 --- a/tests/test_sorting/test_partition.py +++ b/tests/test_sorting/test_partition.py @@ -1,6 +1,6 @@ import pytest -from src.d_sorting.partition import partition2, partition3 +from src.sorting.partition import partition2, partition3 @pytest.mark.parametrize( diff --git a/tests/test_sorting/test_sortings.py b/tests/test_sorting/test_sortings.py index 409478c..99c9a16 100644 --- a/tests/test_sorting/test_sortings.py +++ b/tests/test_sorting/test_sortings.py @@ -2,7 +2,7 @@ import pytest -from src.d_sorting.sort_array import ( +from src.sorting.sort_array import ( counting_sort, iterative_merge_sort, merge_sort, @@ -10,7 +10,7 @@ quick_sort3, radix_sort, ) -from src.d_sorting.sort_colors import bubble_sort, insertion_sort, selection_sort +from src.sorting.sort_colors import bubble_sort, insertion_sort, selection_sort @pytest.mark.parametrize( diff --git a/tests/test_trees/test_dfs.py b/tests/test_trees/test_dfs.py index d467f9e..597750e 100644 --- a/tests/test_trees/test_dfs.py +++ b/tests/test_trees/test_dfs.py @@ -2,8 +2,8 @@ import pytest -from src.m_trees.dfs import dfs_all -from src.m_trees.dfs_iterative import dfs_all_iterative +from src.trees.dfs import dfs_all +from src.trees.dfs_iterative import dfs_all_iterative r""" Tree 1: diff --git a/tests/test_trees/test_is_bst.py b/tests/test_trees/test_is_bst.py index e58fe15..e8b62cc 100644 --- a/tests/test_trees/test_is_bst.py +++ b/tests/test_trees/test_is_bst.py @@ -3,8 +3,8 @@ import pytest -from src.m_trees.is_bst import is_bst, is_bst_naive -from src.m_trees.is_general_bst import is_general_bst_dfs, is_general_bst_fake +from src.trees.is_bst import is_bst, is_bst_naive +from src.trees.is_general_bst import is_general_bst_dfs, is_general_bst_fake r""" Tree 1: diff --git a/tests/test_trees/test_tree_height.py b/tests/test_trees/test_tree_height.py index 4d7c3db..229ed47 100644 --- a/tests/test_trees/test_tree_height.py +++ b/tests/test_trees/test_tree_height.py @@ -2,7 +2,7 @@ import pytest -from src.m_trees.tree_height import tree_height_bfs, tree_height_dfs, tree_height_naive +from src.trees.tree_height import tree_height_bfs, tree_height_dfs, tree_height_naive @pytest.mark.parametrize("func", [tree_height_naive, tree_height_dfs, tree_height_bfs]) diff --git a/tests/test_two_pointers/test_can_transform.py b/tests/test_two_pointers/test_can_transform.py index dedc160..1a5a4c3 100644 --- a/tests/test_two_pointers/test_can_transform.py +++ b/tests/test_two_pointers/test_can_transform.py @@ -1,6 +1,6 @@ import pytest -from src.e_two_pointers.can_trasform import can_transform +from src.two_pointers.can_trasform import can_transform @pytest.mark.parametrize( diff --git a/tests/test_two_pointers/test_max_professionalism.py b/tests/test_two_pointers/test_max_professionalism.py index 8c8c13c..012a647 100644 --- a/tests/test_two_pointers/test_max_professionalism.py +++ b/tests/test_two_pointers/test_max_professionalism.py @@ -1,6 +1,6 @@ import pytest -from src.e_two_pointers.max_professionalism import max_professionalism +from src.two_pointers.max_professionalism import max_professionalism @pytest.mark.parametrize( diff --git a/tests/test_two_pointers/test_prizes.py b/tests/test_two_pointers/test_prizes.py index 1cf943d..715d7ae 100644 --- a/tests/test_two_pointers/test_prizes.py +++ b/tests/test_two_pointers/test_prizes.py @@ -1,6 +1,6 @@ import pytest -from src.e_two_pointers.prizes import prizes +from src.two_pointers.prizes import prizes @pytest.mark.parametrize( diff --git a/tests/test_two_pointers/test_prizes_2s.py b/tests/test_two_pointers/test_prizes_2s.py index d151de5..9df9a10 100644 --- a/tests/test_two_pointers/test_prizes_2s.py +++ b/tests/test_two_pointers/test_prizes_2s.py @@ -1,6 +1,6 @@ import pytest -from src.e_two_pointers.prizes_2s import prizes_hard +from src.two_pointers.prizes_2s import prizes_hard @pytest.mark.parametrize( diff --git a/tests/test_two_pointers/test_shortest_palindrome.py b/tests/test_two_pointers/test_shortest_palindrome.py index 67856a2..ce48481 100644 --- a/tests/test_two_pointers/test_shortest_palindrome.py +++ b/tests/test_two_pointers/test_shortest_palindrome.py @@ -2,7 +2,7 @@ import pytest -from src.e_two_pointers.shortest_palindrome import shortest_kmp, shortest_naive +from src.two_pointers.shortest_palindrome import shortest_kmp, shortest_naive @pytest.mark.parametrize("func", [shortest_naive, shortest_kmp]) diff --git a/tests/test_two_pointers/test_sum_of_two_numbers.py b/tests/test_two_pointers/test_sum_of_two_numbers.py index f37a10c..9f6371b 100644 --- a/tests/test_two_pointers/test_sum_of_two_numbers.py +++ b/tests/test_two_pointers/test_sum_of_two_numbers.py @@ -2,7 +2,7 @@ import pytest -from src.e_two_pointers.two_sum import ( +from src.two_pointers.two_sum import ( two_sum_naive, two_sum_tp, ) diff --git a/tests/test_two_pointers/test_water.py b/tests/test_two_pointers/test_water.py index 15da16c..1932bec 100644 --- a/tests/test_two_pointers/test_water.py +++ b/tests/test_two_pointers/test_water.py @@ -1,6 +1,6 @@ import pytest -from src.e_two_pointers.water import max_area +from src.two_pointers.water import max_area @pytest.mark.parametrize(("height", "expected"), [([1, 8, 6, 2, 5, 4, 8, 3, 7], 49), ([1, 1], 1)])