Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions maths/modular_division.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions searches/linear_search.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down