Skip to content

liofval/my_python_library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

my_python_library

A Python library of common algorithms and data structures for competitive programming.

Features

This library provides modular, tested implementations of frequently used components.

Tier File Name Description Key Complexity
🥇 Tier 1 union_find.py Disjoint Set Union (DSU) $O(\alpha(N))$
mod_pow.py Modular Exponentiation (a^b % m) $O(\log b)$
mod_inverse.py Modular Multiplicative Inverse (a^-1 % m) $O(\log m)$
prime_factorization.py Prime factorization of an integer $O(\sqrt{N})$
🥈 Tier 2 dijkstra.py Single-Source Shortest Path (SSSP) $O((E+V)\log V)$
sieve_of_eratosthenes.py Sieve for primes and minimum prime factor table $O(N \log \log N)$
combination.py nCk % M using precomputed factorials $O(1)$ per query
🥉 Tier 3 binary_indexed_tree.py Point updates, range sum queries (BIT/Fenwick) $O(\log N)$
segment_tree.py Point updates, range queries (e.g., min, max, sum) $O(\log N)$

How to Use

This library is structured as a Python package. To use it in your own scripts, make sure your script is in a directory that can see the my_python_library package.

For example, if your script is in the project root (/Users/mei/my_python_library/), you can import modules like this:

import sys
# It may be necessary to increase Python's recursion limit for graph problems
sys.setrecursionlimit(2000000) 

from my_python_library.union_find import UnionFind
from my_python_library.dijkstra import dijkstra

def solve():
    # ... your solution code using the imported modules ...
    uf = UnionFind(10)
    uf.unite(0, 1)
    # ...

Testing

The library includes a suite of unit tests to ensure correctness. To run the tests, execute the following command from the project root directory:

python3 -m unittest discover tests

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages