A comprehensive repository for mastering Data Structures & Algorithms through clean, well-documented Python implementations.
Perfect for: Coding Interviews • Competitive Programming • Learning DSA • Interview Preparation
- 🎯 Overview
- ✨ Key Features
- 📂 Repository Structure
- 🔥 Topics Covered
- 🚀 Getting Started
- 💻 Usage Examples
- 📊 Complexity Analysis
- 🤝 Contributing
- 📖 Learning Resources
- ⭐ Support
Welcome to the ultimate Python DSA repository! Whether you're preparing for technical interviews at top tech companies or simply want to strengthen your algorithmic thinking, this collection has everything you need.
| ✅ | Clean, Production-Ready Code Well-commented and easy to understand |
| 🎓 | Multiple Solution Approaches From brute force to optimal solutions |
| ⚡ | Complexity Analysis Time and space complexity for each solution |
| 🧪 | Test Cases Included Comprehensive test coverage |
| 📝 | Real Interview Problems From LeetCode, HackerRank, and more |
| 🔄 | Regular Updates Continuously adding new problems and solutions |
Click to expand/collapse directory tree
📦 DSA Python
┣━━ 📁 Arrays
┃ ┣━━ 📁 Binary_search # Binary search variations & problems
┃ ┣━━ 📁 Problems # Array manipulation & algorithms
┃ ┗━━ 📁 Subarrays Problems # Kadane's, Sliding Window, etc.
┃
┣━━ 📁 Binary Trees # Tree traversals & operations
┃
┣━━ 📁 Bitwise # Bit manipulation techniques
┃
┣━━ 📁 Builtin data_structures # Python's native data structures
┃
┣━━ 📁 Dynamic Programming
┃ ┣━━ 📁 Starting # DP Basics (Fibonacci, Stairs, etc.)
┃ ┣━━ 📁 Dp On Grids # 2D Grid Problems
┃ ┣━━ 📁 Dp on strings # LCS, LPS, Edit Distance
┃ ┗━━ 📁 Subsets and Subsequences # Knapsack, Coin Change
┃
┣━━ 📁 Graphs
┃ ┣━━ 📁 Graphs Cycles and making # Graph creation & cycle detection
┃ ┣━━ 📁 MST s # Prim's & Kruskal's algorithms
┃ ┣━━ 📁 Path Algos # Dijkstra, Bellman-Ford, Floyd-Warshall
┃ ┗━━ 📁 Problems # Graph problem solutions
┃
┣━━ 📁 Linked_List # LL implementations & problems
┃
┣━━ 📁 Main Notes for syntax # Python syntax cheat sheets
┃
┣━━ 📁 Recursions and Backtracking
┃ ┣━━ 📁 2D Arrays problems # Matrix recursion
┃ ┣━━ 📁 Merge sort # Divide & conquer
┃ ┣━━ 📁 Permutations # Permutation generation
┃ ┗━━ 📁 Subsequences # Subsequence generation
┃
┣━━ 📁 Stack & Queues # Stack/Queue implementations
┃
┣━━ 📁 String Problems # String algorithms
┃
┗━━ 📁 Trie # Trie data structure
📊 Arrays & Searching
- ✨ Binary Search (iterative & recursive)
- 🎯 Lower/Upper Bound
- 🔄 Search in Rotated Array
- ⛰️ Peak Element
- 🧮 Array manipulation problems
- 📐 Subarray problems (Kadane's, Sliding Window)
💎 Dynamic Programming
Fundamentals
- 🌟 Fibonacci Numbers
- 🪜 Climbing Stairs
- 🏠 House Robber
Grid Problems
- 🗺️ Unique Paths
- 🛤️ Minimum Path Sum
- 🔺 Triangle Problems
String Problems
- 📝 Longest Common Subsequence (LCS)
- 🔄 Longest Palindrome Substring
- ✏️ Edit Distance
Knapsack Problems
- 🎒 0/1 Knapsack
- ♾️ Unbounded Knapsack
- 🪙 Coin Change (Min coins & Number of ways)
🕸️ Graphs
- 🗂️ Graph Representations (Adjacency List/Matrix)
- 🔍 BFS & DFS Traversals
- 🔄 Cycle Detection
- 📍 Shortest Path: Dijkstra, Bellman-Ford, Floyd-Warshall
- 🌲 Minimum Spanning Tree: Prim's, Kruskal's
- 📊 Topological Sort
🌳 Trees
- 🌿 Binary Tree Traversals (Preorder, Inorder, Postorder)
- 📊 Level Order Traversal
- 🔨 Tree Construction & Manipulation
🔗 Linked Lists
- ⛓️ Singly Linked List
- ➕ Insert, ➖ Delete, 🔄 Reverse
- 🎯 Common Patterns & Problems
📚 Stack & Queues
- 📦 Stack Implementation (arrays, linked list, queues)
- 🎫 Queue Implementation (arrays, linked list, stacks)
- 📉 Min Stack / Min Queue
- 🧩 Common Problems
🔁 Recursion & Backtracking
- 🔀 Permutations
- 📋 Subsequences
- 🔄 Merge Sort
- 👑 N-Queens
- 🎲 Sudoku Solver
🔤 String Algorithms
- ✂️ String Manipulation Methods
- 🔎 Pattern Matching
- 🧵 Common String Algorithms
💻 Bitwise Operations
- ⚡ Bit Manipulation Techniques
- ⊕ XOR Problems
- 🔢 Power of 2 Checks
🌲 Trie
- 📖 Trie Implementation
- 🔍 Prefix-based Searching
✓ Python 3.7 or higher
✓ Basic understanding of Python syntax
✓ Familiarity with data structures conceptsStep 1: Clone the repository
git clone <repository-url>
cd "DSA Python"Step 2: Create a virtual environment (recommended)
python -m venv .venvStep 3: Activate the virtual environment
# Windows (PowerShell)
.venv\Scripts\Activate.ps1
# Windows (CMD)
.venv\Scripts\activate.bat
# macOS/Linux
source .venv/bin/activateStep 4: You're ready to code! 🎉
from Arrays.Binary_search.binary_search import binary_search
# Search in a sorted array
arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
target = 7
result = binary_search(arr, target)
print(f"✓ Element {target} found at index: {result}")
# Output: ✓ Element 7 found at index: 3from Dynamic_Programming.Starting.fibonacci_number import (
fibonacci_with_tabulation,
fibonacci_most_optimized
)
# Calculate 10th Fibonacci number
n = 10
# Method 1: Tabulation (Bottom-up DP)
result1 = fibonacci_with_tabulation(n)
print(f"📊 10th Fibonacci (Tabulation): {result1}")
# Method 2: Space Optimized
result2 = fibonacci_most_optimized(n)
print(f"⚡ 10th Fibonacci (Optimized): {result2}")from Binary_Trees.binary_tree import BinaryTree
# Create a binary tree
tree = BinaryTree(1)
tree.root.left = Node(2)
tree.root.right = Node(3)
tree.root.left.left = Node(4)
tree.root.left.right = Node(5)
# Perform different traversals
print("Preorder:", tree.print_tree("preorder"))
print("Inorder:", tree.print_tree("inorder"))
print("Postorder:", tree.print_tree("postorder"))from Graphs.graph_traversals import bfs, dfs
# Create an adjacency list
graph = {
0: [1, 2],
1: [0, 3, 4],
2: [0, 4],
3: [1],
4: [1, 2]
}
# Breadth-First Search
print("BFS:", bfs(graph, 0))
# Depth-First Search
print("DFS:", dfs(graph, 0))Each implementation includes detailed complexity analysis:
| Algorithm | Time Complexity | Space Complexity |
|---|---|---|
| Binary Search | O(log n) | O(1) |
| Merge Sort | O(n log n) | O(n) |
| Quick Sort | O(n log n) avg | O(log n) |
| DFS/BFS | O(V + E) | O(V) |
| Dijkstra | O((V + E) log V) | O(V) |
| Dynamic Programming | Varies | O(n) to O(n²) |
We love contributions! 💕 Help us make this repository even better!
How to Contribute
- 🍴 Fork the repository
- 🌿 Create a new branch
git checkout -b feature/amazing-algorithm
- ✨ Make your changes
- 💾 Commit your changes
git commit -m '✨ Add amazing algorithm' - 🚀 Push to the branch
git push origin feature/amazing-algorithm
- 🎉 Open a Pull Request
- 🆕 New algorithm implementations
- 🐛 Bug fixes
- 📚 Documentation improvements
- ✅ More test cases
- 🎨 Code optimization
- 💡 Better explanations
|
Practice Problems |
Tutorials & Theory |
Interview Prep |
Curated Problems |
- 📕 "Introduction to Algorithms" by CLRS
- 📗 "Cracking the Coding Interview" by Gayle Laakmann McDowell
- 📘 "Elements of Programming Interviews in Python"
- 📙 "Algorithm Design Manual" by Steven Skiena
This project is open source and available under the MIT License.