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.