Skip to content

mrlibelula/python-algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Data Structures & Algorithms in Python

A Comprehensive Interview Preparation Repository

Python Jupyter License Portfolio


From-scratch implementations of essential data structures and algorithms, designed for technical interview mastery and deep understanding of computer science fundamentals.


πŸ“– Explore Notebooks Β· πŸ§ͺ Run Exercises Β· πŸ“Š Complexity Analysis Β· πŸ’Ό Technical Overview


🎯 About This Repository

This repository demonstrates hands-on mastery of fundamental computer science concepts through clean, well-documented Python implementations. Unlike library-dependent code, every data structure and algorithm here is built from scratch to showcase deep understanding of how things work under the hood.

πŸ“ˆ Repository Stats

Category Count
Data Structures 10+
Algorithms 9+
Interactive Notebooks 15+
Practice Exercises 20+
Lines of Code 2,500+

πŸ’‘ Key Highlights

  • βœ… No External Dependencies β€” Pure Python implementations
  • βœ… Interview-Ready β€” Covers FAANG-style questions
  • βœ… Well-Documented β€” Clear explanations & comments
  • βœ… Interactive β€” Jupyter notebooks for step-by-step learning
  • βœ… Practical Examples β€” Real-world use cases

🧱 Data Structures

πŸ“¦ Linear Structures
Structure Implementation Key Operations Notebook
Singly Linked List LinkedList.py Insert, Delete, Traverse, Search β€”
Doubly Linked List DoublyLinkedList.py Bidirectional traversal, Insert at any position β€”
Stack Stack.ipynb Push, Pop, Peek, IsEmpty πŸ““
Queue Queue.ipynb Enqueue, Dequeue, Producer-Consumer pattern πŸ““
πŸ—‚οΈ Hash-Based Structures
Structure Implementation Collision Strategy Notebook
Hash Table (Chaining) HashTableChaining.py Separate Chaining with Linked Lists πŸ““
Hash Table (Probing) HashTableProbing.py Linear Probing (Open Addressing) πŸ““
🌳 Tree Structures
Structure Implementation Key Operations Notebook
General Tree Tree.py Add child, Get level, Print hierarchy πŸ““
Binary Search Tree BinarySearchTree.py Insert, Delete, Search, Min/Max, Traversals πŸ““
πŸ”— Graph Structures
Structure Implementation Key Operations Notebook
Directed Graph Graph.py Adjacency List, Find all paths, Shortest path πŸ““

⚑ Algorithms

πŸ” Search Algorithms

Algorithm Time Complexity Implementation Description
Binary Search O(log n) BinarySearch.py Iterative & Recursive implementations
Binary Search (Find All) O(log n + k) BinarySearch-excercise.py Find all occurrences of duplicates

πŸ“Š Sorting Algorithms

Algorithm Best Average Worst Space Stable
Bubble Sort O(n) O(nΒ²) O(nΒ²) O(1) βœ…
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) βœ…
Insertion Sort O(n) O(nΒ²) O(nΒ²) O(1) βœ…
Selection Sort O(n²) O(n²) O(n²) O(1) ❌
Shell Sort O(n log n) O(n^1.25) O(n²) O(1) ❌

πŸ—ΊοΈ Graph Algorithms

Algorithm Implementation Use Case
Depth-First Search (DFS) dfs.py Path finding, Cycle detection, Topological sort
Breadth-First Search (BFS) bfs.py Shortest path (unweighted), Level-order traversal

πŸ“Š Complexity Analysis Cheat Sheet

Data Structure Access Search Insert Delete Space
Array O(1) O(n) O(n) O(n) O(n)
Linked List O(n) O(n) O(1)* O(1)* O(n)
Stack O(n) O(n) O(1) O(1) O(n)
Queue O(n) O(n) O(1) O(1) O(n)
Hash Table β€” O(1)† O(1)† O(1)† O(n)
Binary Search Tree O(log n)† O(log n)† O(log n)† O(log n)† O(n)
Graph (Adj. List) O(V) O(V) O(1) O(E) O(V+E)

*At known position Β Β  †Average case


πŸ§ͺ Practice Exercises

Each topic includes hands-on exercises with solutions:

πŸ”· Arrays β€” Manipulation, searching, sorting
  • Finding max/min elements
  • Marvel heroes data processing
  • Odd/even number separation
  • Expense tracking system
πŸ”· Linked Lists β€” Pointer manipulation mastery
  • Implement singly linked list from scratch
  • Add doubly linked list functionality
  • Insert/delete at any position
  • Reverse a linked list
πŸ”· Hash Tables β€” Collision handling strategies
  • Weather data analysis with hash tables
  • Word occurrence counter (poem analysis)
  • Stock price lookup system
  • Custom hash function design
πŸ”· Stacks β€” LIFO applications
  • String reversal
  • Balanced parentheses checker ()[]{}
  • Expression evaluation
πŸ”· Queues β€” FIFO applications
  • Binary number generator
  • Food ordering system (with threading!)
  • Producer-consumer pattern
πŸ”· Trees β€” Hierarchical data mastery
  • Management hierarchy visualization
  • Location hierarchy system
  • BST operations (CRUD)
  • Tree traversals (Inorder, Preorder, Postorder)
πŸ”· Graphs β€” Network algorithms
  • Flight route planning system
  • Find all paths between nodes
  • Shortest path (by hops)
  • DFS/BFS implementations

πŸš€ Getting Started

Prerequisites

  • Python 3.10+
  • Jupyter Notebook (optional, for interactive notebooks)

Installation

# Clone the repository
git clone https://github.com/mrlibelula/python-algorithms.git
cd python-algorithms

# (Optional) Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install Jupyter for interactive notebooks
pip install jupyter

# Launch Jupyter
jupyter notebook

Quick Start

# Run standalone Python implementations
python data_structures/BinarySearchTree.py
python data_structures/Graph.py
python data_structures/HashTableChaining.py

# Or explore interactively
jupyter notebook data_structures/

πŸ“ Project Structure

python-algorithms/
β”‚
β”œβ”€β”€ πŸ“‚ data_structures/           # Main implementations
β”‚   β”œβ”€β”€ πŸ“„ LinkedList.py          # Singly linked list
β”‚   β”œβ”€β”€ πŸ“„ DoublyLinkedList.py    # Doubly linked list
β”‚   β”œβ”€β”€ πŸ“„ HashTableChaining.py   # Hash table (chaining)
β”‚   β”œβ”€β”€ πŸ“„ HashTableProbing.py    # Hash table (linear probing)
β”‚   β”œβ”€β”€ πŸ“„ BinarySearchTree.py    # BST with traversals
β”‚   β”œβ”€β”€ πŸ“„ Tree.py                # General tree
β”‚   β”œβ”€β”€ πŸ“„ Graph.py               # Directed graph
β”‚   └── πŸ““ *.ipynb                # Interactive notebooks
β”‚
β”œβ”€β”€ πŸ“‚ search_algorithms/         # Search & sort algorithms
β”‚   β”œβ”€β”€ πŸ“„ BinarySearch.py        # Iterative binary search
β”‚   β”œβ”€β”€ πŸ““ BubbleSort.ipynb       # Sorting notebook
β”‚   └── πŸ““ *.ipynb                # More notebooks
β”‚
β”œβ”€β”€ πŸ“‚ _resources/                # Learning materials
β”‚   β”œβ”€β”€ πŸ“‚ algorithms/            # Algorithm exercises & solutions
β”‚   β”‚   β”œβ”€β”€ BinarySearch/
β”‚   β”‚   β”œβ”€β”€ BubbleSort/
β”‚   β”‚   β”œβ”€β”€ QuickSort/
β”‚   β”‚   β”œβ”€β”€ MergeSort/
β”‚   β”‚   β”œβ”€β”€ InsertionSort/
β”‚   β”‚   β”œβ”€β”€ SelectionSort/
β”‚   β”‚   β”œβ”€β”€ ShellSort/
β”‚   β”‚   β”œβ”€β”€ DepthFirstSearch/
β”‚   β”‚   └── BreadthFirstSearch/
β”‚   β”‚
β”‚   └── πŸ“‚ data_structures/       # Data structure exercises
β”‚       β”œβ”€β”€ Arrays/
β”‚       β”œβ”€β”€ LinkedList/
β”‚       β”œβ”€β”€ HashTable/
β”‚       β”œβ”€β”€ Stack/
β”‚       β”œβ”€β”€ Queue/
β”‚       β”œβ”€β”€ Tree/
β”‚       └── Graph/
β”‚
β”œβ”€β”€ πŸ“„ TECHNICAL_OVERVIEW.md      # Detailed technical documentation
└── πŸ“„ README.md                  # You are here!

πŸ’Ό Technical Skills Demonstrated

Python Proficiency

  • Type hints & annotations
  • Magic methods (__setitem__, __getitem__)
  • Collections module (deque)
  • Multi-threading

CS Fundamentals

  • Big O complexity analysis
  • Recursion & iteration
  • Pointer manipulation
  • Algorithm design patterns

Software Engineering

  • Clean, readable code
  • Modular architecture
  • Interactive documentation
  • Test-driven exercises

πŸŽ“ Learning Path

πŸ“š Recommended order for studying this repository:

1. Arrays           β†’ Foundation of sequential data
         ↓
2. Linked Lists     β†’ Understanding pointers/references
         ↓
3. Hash Tables      β†’ Key-value storage & collision handling
         ↓
4. Stacks & Queues  β†’ LIFO/FIFO abstract data types
         ↓
5. Trees & BST      β†’ Hierarchical data organization
         ↓
6. Graphs           β†’ Network modeling with DFS/BFS
         ↓
7. Sorting          β†’ Comparison-based algorithms
         ↓
8. Searching        β†’ Efficient data retrieval

🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.


πŸ“¬ Contact

Built with πŸ’™ by libe.dev

Portfolio GitHub LinkedIn


⭐ Star this repository if you found it helpful!

About

From-scratch Python implementations of data structures & algorithms with interactive Jupyter notebooks, built for technical interview prep and CS fundamentals.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors