Skip to content

saaim12/DSA-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

72 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Data Structures & Algorithms in Python

Your Complete DSA Journey Starts Here

Python License Contributions Welcome PRs Welcome

A comprehensive repository for mastering Data Structures & Algorithms through clean, well-documented Python implementations.

Perfect for: Coding Interviews โ€ข Competitive Programming โ€ข Learning DSA โ€ข Interview Preparation


๐Ÿ“š Table of Contents

๐ŸŽฏ Overview

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.

โœจ Key Features

โœ… 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

๐Ÿ“‚ Repository Structure

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

๐Ÿ”ฅ Topics Covered

๐Ÿ“Š 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

๐Ÿš€ Getting Started

๐Ÿ“‹ Prerequisites

โœ“ Python 3.7 or higher
โœ“ Basic understanding of Python syntax
โœ“ Familiarity with data structures concepts

โš™๏ธ Installation

Step 1: Clone the repository

git clone <repository-url>
cd "DSA Python"

Step 2: Create a virtual environment (recommended)

python -m venv .venv

Step 3: Activate the virtual environment

# Windows (PowerShell)
.venv\Scripts\Activate.ps1

# Windows (CMD)
.venv\Scripts\activate.bat

# macOS/Linux
source .venv/bin/activate

Step 4: You're ready to code! ๐ŸŽ‰

๐Ÿ’ป Usage Examples

๐Ÿ” Example 1: Binary Search

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: 3

๐Ÿงฎ Example 2: Dynamic Programming - Fibonacci

from 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}")

๐ŸŒฒ Example 3: Binary Tree Traversal

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"))

๐Ÿ•ธ๏ธ Example 4: Graph Traversal

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))

๐Ÿ“Š Complexity Analysis

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ยฒ)

๐Ÿค Contributing

We love contributions! ๐Ÿ’• Help us make this repository even better!

How to Contribute
  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create a new branch
    git checkout -b feature/amazing-algorithm
  3. โœจ Make your changes
  4. ๐Ÿ’พ Commit your changes
    git commit -m 'โœจ Add amazing algorithm'
  5. ๐Ÿš€ Push to the branch
    git push origin feature/amazing-algorithm
  6. ๐ŸŽ‰ Open a Pull Request

๐ŸŒŸ What Can You Contribute?

  • ๐Ÿ†• New algorithm implementations
  • ๐Ÿ› Bug fixes
  • ๐Ÿ“š Documentation improvements
  • โœ… More test cases
  • ๐ŸŽจ Code optimization
  • ๐Ÿ’ก Better explanations

๐Ÿ“– Learning Resources

LeetCode
Practice Problems
GFG
Tutorials & Theory
Striver
Interview Prep
NeetCode
Curated Problems

๐Ÿ“š Recommended Books

  • ๐Ÿ“• "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

๐Ÿ“„ License

This project is open source and available under the MIT License.


โญ Support This Project

If you find this repository helpful, please give it a star! โญ
It helps others discover this resource and motivates us to keep improving!

GitHub stars


๐ŸŒˆ Made with โค๏ธ for the coding community

Happy Coding! Keep Learning! Stay Awesome! ๐Ÿš€

Built with Love Made with Python

About

A comprehensive repository for prepration of Data Structures & Algorithms through clean, well-documented Python implementations of mine with notes

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages