โญ Star this repository if you find it helpful for your DSA learning journey!
This repository contains a comprehensive collection of Data Structures and Algorithms implemented in Python with detailed explanations, step-by-step visualizations, and educational comments. Perfect for interview preparation, academic learning, and competitive programming.
- ๐ Educational Focus: Every algorithm has detailed comments explaining how it works
- ๐ Visual Learning: Step-by-step execution with print statements
- ๐งช Comprehensive Testing: Each implementation includes multiple test cases
- โก Performance Analysis: Time and space complexity explanations
- ๐ฏ Interview Ready: LeetCode-style problems with optimal solutions
- ๐๏ธ Production Quality: Clean, readable, and well-documented code
- 200+ Functions and Classes implemented across all topics
- 50+ Python files with comprehensive implementations
- 15+ Core DSA Topics covered in depth
| Category | Files | Functions | Problems |
|---|---|---|---|
| Sorting Algorithms | 8 | 30+ | All major sorts |
| Searching Algorithms | 8 | 40+ | From linear to advanced |
| Data Structures | 13 | 60+ | Fundamental to advanced |
| LeetCode Problems | 17 | 50+ | Interview favorites |
| Practice Problems | 11 | 20+ | Skill builders |
๐ DSA-Python/
โโโ ๐ basics/ # Fundamental data structures
โโโ ๐ sorting/ # Complete sorting algorithms collection
โโโ ๐ searching/ # Advanced searching techniques
โโโ ๐ practice/ # Skill-building exercises
โโโ ๐ leetcode_problems/ # Interview-style problems
โโโ ๐ README.md # This comprehensive guide
Location: /searching/
Master all essential searching techniques with detailed implementations:
| Algorithm | File | Time Complexity | Best For |
|---|---|---|---|
| Linear Search | 01_linear_search.py |
O(n) | Small/unsorted arrays |
| Binary Search | 02_binary_search.py |
O(log n) | Sorted arrays (general) |
| Jump Search | 03_jump_search.py |
O(โn) | Large arrays with expensive access |
| Interpolation Search | 04_interpolation_search.py |
O(log log n) | Uniformly distributed data |
| Exponential Search | 05_exponential_search.py |
O(log n) | Unbounded/infinite arrays |
| Ternary Search | 06_ternary_search.py |
O(logโ n) | Finding extrema |
| Fibonacci Search | 07_fibonacci_search.py |
O(log n) | Division-expensive systems |
๐ฏ Key Features:
- Step-by-step execution visualization
- Performance comparisons between algorithms
- Edge case handling (empty arrays, duplicates)
- Real-world use case examples
Location: /sorting/
Complete collection of sorting algorithms with performance analysis:
| Algorithm | File | Time Complexity | Space | Stable |
|---|---|---|---|---|
| Bubble Sort | 01_bubble_sort.py |
O(nยฒ) | O(1) | โ |
| Selection Sort | 02_selection_sort.py |
O(nยฒ) | O(1) | โ |
| Insertion Sort | 03_insertion_sort.py |
O(nยฒ) | O(1) | โ |
| Merge Sort | 04_merge_sort.py |
O(n log n) | O(n) | โ |
| Quick Sort | 05_quick_sort.py |
O(n log n) | O(log n) | โ |
| Heap Sort | 06_heap_sort.py |
O(n log n) | O(1) | โ |
| Counting Sort | 07_counting_sort.py |
O(n + k) | O(k) | โ |
| Radix Sort | 08_radix_sort.py |
O(d ร n) | O(n + k) | โ |
๐ฏ Key Features:
- Multiple implementation variants (iterative, recursive, optimized)
- Detailed complexity analysis
- Visual step-by-step execution
- Best/worst case scenario examples
Location: /basics/
Essential data structures with comprehensive problem collections:
File: array_problems.py
- 15 Classic Problems including Two Sum, Maximum Subarray, Product of Array
- Sliding window techniques
- Two-pointer algorithms
- Dynamic programming on arrays
Files: linked_list.py | linked_list_problems.py
- 10 Essential Problems including cycle detection, reversal, merging
- Singly and doubly linked list implementations
- Fast/slow pointer techniques
- Advanced manipulations
Files: stack.py | stack_problems.py
- 12 Stack Problems including balanced parentheses, next greater element
- Stack-based algorithms
- Expression evaluation
- Monotonic stack patterns
Files: queue.py | queue_problems.py
- 12 Queue Problems including sliding window maximum, level order traversal
- Circular queue implementation
- Deque applications
- Priority queue patterns
File: map_problems.py
- 14 HashMap Problems including frequency counting, grouping algorithms
- Hash table collision handling
- Optimization techniques
- Real-world applications
Location: /basics/
File: binary_tree_problems.py
- 16 Binary Tree Problems including traversals, diameter, path sum
- All traversal methods (inorder, preorder, postorder, level-order)
- Tree construction algorithms
- Advanced tree algorithms
File: tree_problems.py
- 12 Tree Problems including N-ary trees, trie operations
- Tree serialization/deserialization
- Tree comparison algorithms
- Advanced tree manipulations
Location: /practice/
Skill-building exercises progressing from basic to advanced:
| Problem | File | Concept |
|---|---|---|
| Sum of Evens | 01_sum_of_evens.py |
Basic iteration |
| Count Occurrences | 02_count_occurences.py |
Hash maps |
| Find Second Largest | 03_find_second_largest.py |
Array traversal |
| Merge Sorted Arrays | 04_merge_sorted_arrays.py |
Two pointers |
| Valid Parentheses | 05_valid_paranthesis.py |
Stack operations |
| Reverse String (Stack) | 06_reverse_string_stack.py |
Stack manipulation |
| MinStack | 07_min_element_stack.py |
Stack design |
| Linked List Length | 08_length_linked_list.py |
List traversal |
| Insert at Beginning | 09_insert_node_at_beginning.py |
List insertion |
| Delete Nodes | 10_delete_all_nodes_with_given_value.py |
List deletion |
| Remove Spaces | 11_remove_space_func.py |
String manipulation |
Location: /leetcode_problems/
Interview-ready solutions to popular LeetCode problems:
valid_paranthesis_multi_bracket.py- Valid Parenthesesmedian_of_two_sorted_arrays.py- Median of Two Sorted Arraysdelete_nodes_from_linked_list_by_arr_nums.py- Delete Nodes from Linked Listrotate_arr_start_to_end.py- Rotate Arraysecond_largest_digit_in_a_string.py- Second Largest Digitzigzag_conversion.py- ZigZag Conversion
tic_tac_toe.py- Tic Tac Toe Winnerfizz_buzz.py- FizzBuzz Implementation
string_to_integer.py- String to Integer (atoi)valid_parentheses_string_star.py- Valid Parentheses with Wildcardsnumeric_finder.py- Numeric Pattern Finding
- Detailed Comments: Every line explained for learning
- Step-by-Step Execution: Visual algorithm progression
- Multiple Approaches: Different solutions for same problem
- Complexity Analysis: Time and space complexity for each solution
- Edge Cases: Empty inputs, single elements, large datasets
- Performance Testing: Benchmark comparisons
- Visual Demonstrations: Print-based algorithm visualization
- Real Data Examples: Practical use case scenarios
- Clean Code: PEP 8 compliant, readable structure
- Type Hints: Modern Python with type annotations
- Error Handling: Robust input validation
- Documentation: Comprehensive docstrings
- Algorithm Comparison: Side-by-side performance analysis
- Optimization Techniques: Multiple implementation variants
- Memory Efficiency: Space-optimized solutions
- Scalability: Solutions tested with large datasets
Python 3.13+ (recommended)
No external dependencies required!# Clone the repository
git clone https://github.com/Idrisvohra9/DSA-Python.git
# Navigate to the project
cd DSA-Python
# Run any algorithm (example: binary search)
python searching/02_binary_search.py
# Run practice problems
python practice/01_sum_of_evens.py
# Test sorting algorithms
python sorting/04_merge_sort.pyEach file is self-contained with comprehensive examples:
# Example: Running binary search with detailed steps
python searching/02_binary_search.py
# Output:
# === BINARY SEARCH DEMONSTRATIONS ===
# 1. BASIC BINARY SEARCH
# Array: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
# Searching for: 7
# Found at index: 3
# ...- Start with Practice Problems
/practice/ - Learn basic Data Structures
/basics/ - Master Sorting Algorithms
/sorting/
- Focus on LeetCode Problems
/leetcode_problems/ - Master Searching Algorithms
/searching/ - Practice Advanced Tree Problems
/basics/binary_tree_problems.py
- Study all Algorithm Optimizations
- Master Advanced Data Structures
- Focus on Time/Space Complexity analysis
| Algorithm | Best | Average | Worst | Space |
|---|---|---|---|---|
| Linear | O(1) | O(n) | O(n) | O(1) |
| Binary | O(1) | O(log n) | O(log n) | O(1) |
| Jump | O(1) | O(โn) | O(โn) | O(1) |
| Interpolation | O(1) | O(log log n) | O(n) | O(1) |
| Algorithm | Best | Average | Worst | Space | Stable |
|---|---|---|---|---|---|
| Bubble | O(n) | O(nยฒ) | O(nยฒ) | O(1) | โ |
| Quick | O(n log n) | O(n log n) | O(nยฒ) | O(log n) | โ |
| Merge | O(n log n) | O(n log n) | O(n log n) | O(n) | โ |
| Heap | O(n log n) | O(n log n) | O(n log n) | O(1) | โ |
We welcome contributions! Here's how you can help:
- ๐ Bug Reports: Found an issue? Create an issue with details
- โจ New Algorithms: Add more algorithms with proper documentation
- ๐ Documentation: Improve comments and explanations
- ๐งช Test Cases: Add more comprehensive test scenarios
- ๐จ Code Style: Enhance code readability and structure
- Follow existing code style and documentation patterns
- Include comprehensive test cases
- Add detailed comments explaining the algorithm
- Update this README if adding new sections
This project is licensed under the MIT License - see the LICENSE file for details.
- Python Community for excellent language design
- LeetCode for inspiring problem-solving approaches
- Computer Science Education for algorithm foundations
- Open Source Community for collaborative learning
If this repository helped you in your DSA learning journey, please consider:
- โญ Starring this repository
- ๐ด Forking it for your own use
- ๐ค Sharing it with fellow developers
- ๐ Contributing improvements back
Your support motivates continued development and helps others discover this resource!
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ง Contact: Feel free to reach out for questions or suggestions