🚀 AlgoZen - Comprehensive Data Structures & Algorithms Package

AlgoZen is a comprehensive Python package providing efficient implementations of data structures, algorithms, design patterns, and common programming problems. Perfect for learning, coding interviews, competitive programming, and production use.
✨ Features
🏗️ Data Structures (12 implementations)
- Heaps: MinHeap, MaxHeap with O(log n) operations
- Linear: Stack, Queue, LinkedList with full functionality
- Trees: BinaryTree, BinarySearchTree, AVLTree, Trie
- Advanced: SegmentTree, FenwickTree, UnionFind
- Graphs: Comprehensive graph representation with algorithms
🔧 Algorithms (11 categories)
- Sorting: Bubble, Selection, Insertion, Merge, Quick, Heap, Counting, Radix
- Searching: Linear, Binary, Interpolation, Exponential, Jump
- String: KMP, Rabin-Karp, Z-Algorithm, Edit Distance
- Graph: DFS, BFS, Dijkstra, Bellman-Ford, Floyd-Warshall
- Tree: Traversals, LCA, Path algorithms
- Mathematical: GCD, LCM, Prime algorithms, Number theory
🎯 Patterns (14 problem-solving patterns)
- Bit Manipulation: Count bits, XOR operations, bit tricks
- Sliding Window: Maximum sum, substring problems
- Two Pointers: Pair finding, array manipulation
- Fast/Slow Pointers: Cycle detection, middle finding
- Merge Intervals: Overlapping intervals, scheduling
- Dynamic Programming: Advanced DP patterns and optimizations
🏛️ Design Patterns (9 classic patterns)
- Creational: Factory, Builder patterns
- Behavioral: Observer, Strategy, Command, State
- Structural: Decorator, Adapter patterns
💡 Problems (9 categories, 200+ solutions)
- Arrays: Two sum, maximum subarray, product problems
- Strings: Palindromes, anagrams, pattern matching
- Trees: Traversals, path problems, validation
- Graphs: Shortest paths, connectivity, topological sort
- Dynamic Programming: Classic DP problems and variations
🚀 Installation
pip install algozen
pip install --upgrade algozen
🏃 Quick Start
import algozen
from algozen.data_structures import MinHeap, BinarySearchTree, Graph
heap = MinHeap()
heap.insert(5)
heap.insert(3)
heap.insert(8)
print(heap.extract_min())
from algozen.algorithms import quick_sort, binary_search
arr = [64, 34, 25, 12, 22, 11, 90]
sorted_arr = quick_sort(arr)
print(sorted_arr)
index = binary_search(sorted_arr, 25)
print(index)
from algozen.patterns.sliding_window import max_sum_subarray_of_size_k
from algozen.patterns.two_pointers import pair_with_target_sum
max_sum = max_sum_subarray_of_size_k([2, 1, 5, 1, 3, 2], 3)
print(max_sum)
indices = pair_with_target_sum([1, 2, 3, 4, 6], 6)
print(indices)
from algozen.design_patterns.factory import AnimalFactory, AnimalType
factory = AnimalFactory()
dog = factory.create_animal(AnimalType.DOG, "Buddy")
print(dog.make_sound())
from algozen.problems.arrays import two_sum, max_subarray_sum
result = two_sum([2, 7, 11, 15], 9)
print(result)
max_sum = max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4])
print(max_sum)
📚 Documentation
Data Structures
MinHeap / MaxHeap
from algozen.data_structures import MinHeap, MaxHeap
heap = MinHeap()
heap.insert(10)
heap.insert(5)
min_val = heap.extract_min()
top = heap.peek()
size = heap.size()
empty = heap.is_empty()
Binary Search Tree
from algozen.data_structures import BinarySearchTree
bst = BinarySearchTree()
bst.insert(50)
bst.insert(30)
bst.insert(70)
found = bst.search(30)
bst.delete(30)
min_key = bst.min()
max_key = bst.max()
Graph
from algozen.data_structures import Graph
graph = Graph()
graph.add_vertex("A")
graph.add_vertex("B")
graph.add_edge("A", "B", 5)
neighbors = graph.get_neighbors("A")
Algorithms
Sorting Algorithms
from algozen.algorithms.sorting import quick_sort, merge_sort, heap_sort
arr = [64, 34, 25, 12, 22, 11, 90]
sorted_arr = quick_sort(arr.copy())
sorted_arr = merge_sort(arr.copy())
sorted_arr = heap_sort(arr.copy())
String Algorithms
from algozen.algorithms.string_algorithms import kmp_search, rabin_karp_search
text = "ababcababa"
pattern = "aba"
matches = kmp_search(text, pattern)
matches = rabin_karp_search(text, pattern)
Patterns
Sliding Window
from algozen.patterns.sliding_window import (
max_sum_subarray_of_size_k,
longest_substring_with_k_distinct,
longest_substring_without_repeating_chars
)
max_sum = max_sum_subarray_of_size_k([2, 1, 5, 1, 3, 2], 3)
length = longest_substring_with_k_distinct("araaci", 2)
length = longest_substring_without_repeating_chars("abcabcbb")
Two Pointers
from algozen.patterns.two_pointers import (
pair_with_target_sum,
remove_duplicates,
search_triplets
)
indices = pair_with_target_sum([1, 2, 3, 4, 6], 6)
arr = [2, 3, 3, 3, 6, 9, 9]
new_length = remove_duplicates(arr)
triplets = search_triplets([-3, 0, 1, 2, -1, 1, -2], 0)
Design Patterns
Factory Pattern
from algozen.design_patterns.factory import AnimalFactory, AnimalType
factory = AnimalFactory()
dog = factory.create_animal(AnimalType.DOG, "Buddy")
cat = factory.create_animal(AnimalType.CAT, "Whiskers")
print(dog.make_sound())
print(cat.make_sound())
Observer Pattern
from algozen.design_patterns.observer import Subject, Observer
subject = Subject()
observer1 = Observer("Observer1")
observer2 = Observer("Observer2")
subject.attach(observer1)
subject.attach(observer2)
subject.notify("data_changed", {"new_value": 42})
🧪 Testing
AlgoZen comes with comprehensive test coverage ensuring all functionality works correctly:
import algozen
from algozen.data_structures import MinHeap
heap = MinHeap()
heap.insert(5)
assert heap.extract_min() is not None
from algozen.algorithms.sorting import quick_sort
result = quick_sort([3, 1, 4, 1, 5])
assert result == [1, 1, 3, 4, 5]
📊 Performance Characteristics
MinHeap/MaxHeap | O(log n) | O(log n) | O(n) | O(n) |
Stack | O(1) | O(1) | O(n) | O(n) |
Queue | O(1) | O(1) | O(n) | O(n) |
BST | O(log n)* | O(log n)* | O(log n)* | O(n) |
Graph | O(1) | O(V) | O(V) | O(V+E) |
*Average case. Worst case is O(n) for unbalanced trees.
Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) |
Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) |
Binary Search | O(1) | O(log n) | O(log n) | O(1) |
KMP Search | O(n+m) | O(n+m) | O(n+m) | O(m) |
🏗️ Project Structure
algozen/
├── data_structures/ # Core data structure implementations
│ ├── heap.py # MinHeap, MaxHeap
│ ├── stack.py # Stack implementation
│ ├── queue.py # Queue implementation
│ ├── linked_list.py # LinkedList with Node
│ ├── binary_search_tree.py # BST implementation
│ ├── graph.py # Graph with Edge
│ ├── trie.py # Trie with TrieNode
│ └── ... # Other data structures
├── algorithms/ # Algorithm implementations
│ ├── sorting.py # All sorting algorithms
│ ├── searching.py # All searching algorithms
│ ├── string_algorithms.py # String processing
│ └── ... # Other algorithm categories
├── patterns/ # DSA patterns and techniques
│ ├── bit_manipulation.py # Bit manipulation patterns
│ ├── sliding_window.py # Sliding window technique
│ ├── two_pointers.py # Two pointers technique
│ └── ... # Other patterns
├── design_patterns/ # Software design patterns
│ ├── factory.py # Factory pattern
│ ├── observer.py # Observer pattern
│ ├── strategy.py # Strategy pattern
│ └── ... # Other design patterns
├── problems/ # Common DSA problems
│ ├── arrays.py # Array problems
│ ├── strings.py # String problems
│ ├── trees.py # Tree problems
│ └── ... # Other problem categories
└── test_comprehensive.py # Complete test suite
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Guidelines
- Follow PEP 8 style guidelines
- Add comprehensive docstrings with time/space complexity
- Include examples in docstrings
- Ensure backward compatibility
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Inspired by classic algorithms and data structures textbooks
- Built with modern Python best practices
- Designed for both learning and production use
📈 Stats
- 55 Python modules with comprehensive implementations
- 900+ functions and classes covering all major CS concepts
- Zero dependencies for core functionality
- Production-ready code with proper error handling
- Extensive documentation with examples and complexity analysis
- MIT Licensed - free for commercial and personal use
🔄 Changelog
Version 1.2.2
- Complete reorganization with perfect module structure
- Added comprehensive design patterns module
- Enhanced all data structures with full functionality
- Improved algorithm implementations with better performance
- Added 200+ problem solutions across 9 categories
- Zero duplicate code - clean, maintainable codebase
- Full test coverage ensuring reliability
Made with ❤️ by moah0911
AlgoZen - Where algorithms meet zen-like simplicity 🧘♂️