Skip to content

viniqrz/data-structures-algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Data Structures & Algorithms

A personal collection of classic algorithms and data structure problems β€” with clear implementations and quick-reference docs for interview prep.

Each problem lives in its own folder with:

  • βœ… A Python implementation
  • πŸ“– A README.md with the core idea, visual diagram, history, interview tips, and use cases

πŸ—ΊοΈ Quick Navigation

πŸ” Searching & Graph Traversal

Problem Time Space Key Pattern
BFS O(V+E) O(V) Queue, level-by-level
DFS O(V+E) O(V) Recursion / stack
Binary Search O(log n) O(1) Divide sorted range
Grid Traversal O(mΒ·n) O(mΒ·n) BFS/DFS on 2D matrix
Shortest Path O(V+E) O(V) BFS (unweighted)

πŸ”€ Sorting

Problem Time Space Key Pattern
Bucket Sort / Top-K Frequent O(n) O(n) Frequency buckets
Cyclic Sort O(n) O(1) Place num at index num-1
Dutch National Flag O(n) O(1) 3-pointer partition
Sort Colors O(n) O(1) Counting sort
Merge Sorted Arrays O(n+m) O(n+m) Two pointers
Merge K Sorted Lists O(n log k) O(k) Divide & conquer / heap
Topological Sort O(V+E) O(V) DFS post-order + reverse

πŸ”— Linked Lists

Problem Time Space Key Pattern
Reverse Linked List O(n) O(1) 3-pointer iteration
Detect Cycle (Linked List) O(n) O(1) Floyd's tortoise & hare
Rotate Linked List O(n) O(1) Make circular, find new tail

🌳 Trees & Graphs

Problem Time Space Key Pattern
Detect Cycle (Graph) O(V+E) O(V) DFS with visited set
N Provinces O(nΒ²) O(n) Connected components DFS
Recursive Deps O(V+E) O(V) Post-order DFS
Longest Leaf (Tree Height) O(n) O(h) Post-order DFS
N-th Level Leafs O(n) O(h) DFS with depth
House Robber III O(n) O(h) Tree DP (skip/take pair)

πŸ“ˆ Dynamic Programming

Problem Time Space Key Pattern
Knapsack 0/1 O(nΒ·W) O(nΒ·W) Include/exclude DP
Longest Consecutive Sequence O(n) O(n) Set + sequence root
Longest Increasing Subsequence O(nΒ²) O(n) DP / patience sort
Longest Common Subsequence O(mΒ·n) O(mΒ·n) 2D DP
Max Subarray (Kadane's) O(n) O(1) Extend or restart

πŸͺŸ Sliding Window

Problem Time Space Key Pattern
Longest Substring (No Repeat) O(n) O(m) Set + shrink left
Character Replacement O(n) O(1) max_freq window trick

πŸ”€ Strings

Problem Time Space Key Pattern
Is Anagram O(n) O(1) Counter comparison
Is Palindrome O(n) O(1) Two pointers

🎲 Backtracking

Problem Time Space Key Pattern
Combination Sum O(n^(t/m)) O(t/m) DFS include/skip (reuse OK)
Combination Sum II O(2^n) O(n) Sort + skip duplicates
Permutations O(n!Β·n) O(n) All orderings backtrack
Subsets O(nΒ·2^n) O(n) Include/exclude each element

πŸ“¦ Data Structures

Problem Time Space Key Pattern
Heap / Priority Queue O(log n) push/pop O(n) Min-heap, heapq

πŸ—ΊοΈ Arrays & Matrices

Problem Time Space Key Pattern
Rotate 90Β° O(nΒ²) O(1) Reverse rows + transpose

πŸš€ How to Use This Repo

  1. Browse by category using the table above
  2. Open any folder β€” the README.md has the theory, the .py file has the code
  3. For interview prep: read the README first for the key insight, then try to implement from memory
πŸ“ problem-name/
   β”œβ”€β”€ problem.py     ← implementation
   └── README.md      ← explanation + interview tips

πŸ“š Patterns to Master

Pattern Problems
Two Pointers Palindrome, Merge Sorted, Dutch National Flag
Sliding Window Longest Substring, Character Replacement
BFS/DFS Graph traversal, Grid, Shortest Path, Connected Components
Backtracking Subsets, Permutations, Combination Sum
Dynamic Programming Knapsack, LCS, LIS, Max Subarray, House Robber
Divide & Conquer Merge K Lists, Binary Search
Topological Sort Topo Sort, Recursive Deps, Detect Cycle

Happy grinding! 🎯

About

πŸ‘¨β€πŸ’» Classic data structures & algorithms in Python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages