Skip to content

swiftsoftwaregroup/algo-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

115 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

algo-py

CI Docs

Algorithms and Data Structures in Python

Setup

Create virtual env and install Python packages:

source configure.sh

Lint

pylint src

Test

pytest

Docs

# build 
mkdocs build

# serve
mkdocs serve

# open docs in browser
open http://127.0.0.1:8000

Data Structures and Algorithms

Data Structures

  • Arrays & Lists
    • Dynamic arrays
    • Linked lists (singly, doubly, circular)
    • Stacks and Queuess (stack, queue, deque)
  • Trees
    • Binary tree
    • Binary search tree
    • Heap (min, max)
    • TODO: AVL tree
    • TODO: Red-black tree
  • Hash Tables
    • Hash map
    • Hash set
  • Graphs
    • Adjacency list representation
    • Adjacency matrix representation
    • Undirected graph
    • Directed graph
  • Strings
    • Trie / PrefixTree
    • SuffixTree
    • SuffixArray

Algorithms

  • Sorting

    • Bubble sort, Selection sort, Insertion sort
    • Merge sort, Quick sort
    • Radix sort, Counting sort
    • Heap sort
  • Searching

    • Linear search, Binary search
  • Hashing

    • Polynomial Rolling Hash (for strings)
    • FNV-1a Hash
    • Simple Multiplicative Hash
    • Jenkins One-at-a-Time Hash
    • DJB2 Hash
    • SDBM Hash
    • MurmurHash3 (simplified version)
  • Graph Algorithms

    • Depth-first search (DFS)
    • Breadth-first search (BFS)
    • Floyd-Warshall shortest path
    • Dijkstra shortest path
    • TODO: Bellman-Ford shortest path
    • TODO: Minimum spanning tree (Kruskal's)
    • TODO: Minimum spanning tree (Prim's)
  • Dynamic Programming

    • Fibonacci sequence
    • TODO: Knapsack problem
  • Strings

    • Palindrome Detection
    • Edit distance
    • Autocomplete
    • Substring Search / Find all occurrences of a substring
    • Longest Common Substring
    • Longest Repeated Substring
    • TODO: Longest Common Subsequence
    • TODO: Pattern Matching
    • TODO: Compression
    • TODO: Regex

String Algorithms

Palindrome Detection

graph TD
    %% Pattern Detection
    subgraph "Pattern Detection"
        Palindrome[Palindrome Detection]
    end
    Palindrome --> Array
    Palindrome --> DynamicProgramming

    %% Data Structures
    subgraph "Data Structures"
        Array
    end

    %% Algorithms
    subgraph Algorithms
        DynamicProgramming
    end
Loading

Edit distance

graph TD
    %% Transformation
    subgraph Transformation
        EditDist[Edit Distance]
    end
    EditDist --> DynamicProgramming
    EditDist --> Arrays

    %% Data Structures
    subgraph "Data Structures"
        Arrays
    end

    %% Algorithms
    subgraph Algorithms
        DynamicProgramming
    end
Loading

Indexing / Searching

  • Autocomplete
  • Substring Search
graph TD
    %% Indexing
    subgraph "Indexing / Searching"
        Autocomplete
        SubstringSearch[Substring Search]
    end
    Autocomplete --> Trie
    SubstringSearch --> SuffixTree
    SubstringSearch --> SuffixArray

    %% Data Structures
    subgraph "Data Structures (Advanced)"
        SuffixTree
        SuffixArray
    end
    SuffixTree --> Array
    SuffixArray --> Array
    SuffixArray --> Sorting
    SuffixArray --> BinarySearch
    
    %% Data Structures
    subgraph "Data Structures"
        Array
        Trie[Trie / PrefixTree]
    end

    %% Algorithms
    subgraph Algorithms
        Sorting
        BinarySearch
    end
Loading

Substring / Subsequence Analysis

  • Longest Common Substring

  • Longest Repeated Substring

  • TODO: Longest Common Subsequence

graph TD
  %% Substring and Subsequence Analysis
  subgraph "Substring Analysis"
      LCS[Longest Common Substring]
      LCSeq[Longest Common Subsequence]
      LRS[Longest Repeated Substring]
  end
  LCS --> DynamicProgramming
  LCS --> SuffixTree
  LCS --> SuffixArray
  LCSeq --> DynamicProgramming
  LRS --> SuffixTree
  LRS --> SuffixArray
  
  %% Data Structures
  subgraph "Data Structures (Advanced)"
      SuffixTree
      SuffixArray
  end
  SuffixTree --> Array
  SuffixArray --> Array
  SuffixArray --> Sorting
  SuffixArray --> BinarySearch

  %% Data Structures
  subgraph "Data Structures"
      Array
  end

  %% Algorithms
  subgraph Algorithms
      DynamicProgramming
      Sorting
      BinarySearch  
  end
Loading

Pattern Matching

graph TD
    %% Pattern Matching and Searching
    subgraph "Pattern Matching"
        KMP["Knuth-Morris-Pratt (KMP)"]
        RabinKarp[Rabin-Karp]
        BoyerMoore[Boyer-Moore]
        Naive[Naive]
        AhoCorasick[Aho-Corasick]
    end
    KMP --> Arrays
    RabinKarp --> Arrays
    RabinKarp --> Hashing
    BoyerMoore --> Arrays
    Naive --> Arrays
    AhoCorasick --> Trie
    AhoCorasick --> FiniteAutomata

    %% Data Structures
    subgraph "Data Structures"
        Arrays
        Trie[Trie / PrefixTree]
    end

    %% Algorithms
    subgraph Algorithms
        Hashing
        FiniteAutomata
    end
Loading

Compression

graph TD
    %% Compression
    subgraph Compression
        RLE[Run-Length Encoding]
        Huffman[Huffman Coding]
    end
    RLE --> Array
    Huffman --> PriorityQueue
    Huffman --> BinaryTree
    Huffman --> Greedy

    %% Data Structures
    subgraph "Data Structures"
        Array
        PriorityQueue
        BinaryTree
    end

    %% Algorithms
    subgraph Algorithms
        Greedy["Greedy Huffman Tree Construction"]
    end
Loading

Regex

graph TD
    %% Regex
    subgraph Regex
        RegexAlg[Regex Matching]
    end
    Regex --> Array
    Regex --> FiniteAutomata
    Regex --> DynamicProgramming

    %% Data Structures
    subgraph "Data Structures"
        Array
    end

    %% Algorithms
    subgraph Algorithms
        DynamicProgramming
        FiniteAutomata
    end
Loading

How to create a new project

Install uv

# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh

echo 'PATH="$HOME/.local/bin":$PATH' >> $HOME/bash_profile

Initialize project

# install python
uv python list
uv python install 3.14

# init project
uv init
uv venv .venv
source .venv/bin/activate

Add dependencies

# app
uv add <package>

# test and lint
uv add --dev pytest pylint

About

Algorithms and Data Structures in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published