diff --git a/maths/modular_division.py b/maths/modular_division.py index 94f12b3e096e..ed4ae6ae8ce3 100644 --- a/maths/modular_division.py +++ b/maths/modular_division.py @@ -28,9 +28,13 @@ def modular_division(a: int, b: int, n: int) -> int: 4 """ - assert n > 1 - assert a > 0 - assert greatest_common_divisor(a, n) == 1 + if n <= 1: + raise ValueError("Modulus n must be greater than 1") + if a <= 0: + raise ValueError("Divisor a must be a positive integer") + if greatest_common_divisor(a, n) != 1: + raise ValueError("a and n must be coprime (gcd(a, n) = 1)") + (_d, _t, s) = extended_gcd(n, a) # Implemented below x = (b * s) % n return x diff --git a/searches/linear_search.py b/searches/linear_search.py index ba6e81d6bae4..10813652fcdb 100644 --- a/searches/linear_search.py +++ b/searches/linear_search.py @@ -1,4 +1,19 @@ """ +Linear Search Algorithm + +Linear search is a simple searching technique that checks each element in the collection +sequentially until the target element is found or the collection is exhausted. +It is also known as sequential search. + +Characteristics: +- Works on both sorted and unsorted collections +- Time complexity: O(n) +- Space complexity: O(1) +- Simple and reliable for small datasets + +For large datasets or sorted collections, binary search or other logarithmic search +algorithms are usually more efficient. + This is pure Python implementation of linear search algorithm For doctests run following command: