Skip to content

๐Ÿง  Data Structures & Algorithms in Python โ€” interview prep with tests and complexity analysis

License

Notifications You must be signed in to change notification settings

kelsonbrito50/python-dsa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  Python DSA โ€” Data Structures & Algorithms

Tests Algorithms Tests

Interview prep implementations with tests and complexity analysis.

Implementations

Category Algorithm Complexity File
๐Ÿ“ฆ Arrays Two Sum (hash map + two-pointer) O(n) arrays/two_sum.py
๐Ÿ“ฆ Arrays Sliding Window (max sum, unique substr) O(n) arrays/sliding_window.py
๐Ÿ“ฆ Arrays Kadane's Algorithm (max subarray) O(n) arrays/kadane.py
๐Ÿ“ฆ Arrays Two Pointers (sorted sum, dedup, palindrome) O(n) arrays/two_pointers.py
๐Ÿ”ค Strings Anagram, Reverse Words, First Unique, LCP O(n) strings/manipulation.py
๐Ÿ”— Linked Lists Singly (push, pop, find, reverse) O(1)/O(n) linked_lists/singly.py
๐Ÿ“š Stacks Stack + Valid Parentheses O(1) stacks/stack.py
๐Ÿ“ฌ Queues Queue (deque-based) O(1) queues/queue.py
#๏ธโƒฃ Hash Maps Custom HashMap (open addressing) O(1) avg hashmaps/hashmap.py
๐ŸŒณ Trees BST (insert, search, in-order) O(log n) trees/bst.py
โ›ฐ๏ธ Heaps Kth Largest, Top K Frequent, Merge K Sorted O(n log k) heaps/priority_queue.py
๐ŸŒ Graphs BFS, DFS iterative + recursive O(V+E) graphs/traversals.py
๐Ÿ“Š Sorting Quick Sort (in-place + functional) O(n log n) sorting/quick_sort.py
๐Ÿ“Š Sorting Merge Sort (divide & conquer) O(n log n) sorting/merge_sort.py
๐Ÿ“Š Sorting Heap Sort (in-place) O(n log n) sorting/heap_sort.py
๐Ÿ” Searching Binary Search (iterative + recursive) O(log n) searching/binary_search.py
๐Ÿงฎ Matrix Rotate 90ยฐ, Spiral Order O(nยฒ) matrix/operations.py
๐Ÿ”„ Dynamic Programming Fibonacci (memo + bottom-up), Climbing Stairs O(n) dynamic_programming/fibonacci.py
๐Ÿ”™ Backtracking Permutations, Subsets (power set) O(n!/2^n) backtracking/permutations.py

Running

python -m pytest tests/ -v

What I Learned

  • Two pointers eliminates O(nยฒ) brute force on sorted arrays โ€” always ask "is it sorted?"
  • Sliding window replaces nested loops for subarray/substring problems
  • Kadane's is just a clever rolling max โ€” once you see it, you can't unsee it
  • BFS = shortest path in unweighted graphs, DFS = explore everything
  • Dynamic programming = recursion + memoization โ€” start top-down, optimize bottom-up
  • Backtracking = DFS on a decision tree โ€” add, recurse, undo
  • Heaps solve any "top K" problem efficiently โ€” heapq in Python is a min-heap
  • Valid parentheses is the canonical stack problem โ€” learn the pattern, solve 10 variants

License

MIT

About

๐Ÿง  Data Structures & Algorithms in Python โ€” interview prep with tests and complexity analysis

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages