Welcome to the DSA Learning Repository! This is a beginner-friendly collection of fundamental data structures and algorithms implemented in Python, designed to help you understand and master core computer science concepts, and then practise them with exercises that grade themselves as you go.
New to this? You do not need to install anything. Jump to Try it now and you will be running real code in your browser in under a minute.
- Try it now (no install needed)
- Overview
- Repository Structure
- Topics Covered
- Getting Started
- Interactive practice with instant feedback
- How to Use
- Learning Path
- Resources
- Contributing
- License
Click the green button below. GitHub builds a full Python workspace for you in the cloud (this is called a Codespace) with everything already set up. Nothing to download, nothing to configure.
Once it opens:
- Wait a few seconds for the setup to finish. A small progress scoreboard prints in the terminal.
- Run any example, for example:
python "Sorting Algorithms/merge_sort.py" - Open
exercises/practice.pyand start solving. Check your progress any time withpython check.py.
Prefer to work on your own machine instead? See Getting Started below.
This repository contains clean, well-documented Python implementations of essential data structures and algorithms. Each implementation includes:
- Comprehensive docstrings explaining purpose, parameters, and complexity
- Error handling for robust code
- Time and space complexity analysis
- Test cases and examples demonstrating usage
- Detailed inline comments explaining the logic
DSA/
├── Computational Complexity and Big-O Notation/
│ ├── Intro.md Introduction to Big-O notation
│ ├── Notes.md Complexity analysis of algorithms
│ ├── Time Complexity/
│ │ ├── constant_time.py O(1) examples
│ │ ├── linear_time.py O(n) examples
│ │ └── quadratic_time.py O(n^2) examples
│ └── Space Complexity/
│ ├── O(1).py Constant space examples
│ └── O(n).py Linear space examples
│
├── Data Structures/
│ ├── arrays.py Array operations
│ ├── linked_lists.py Singly linked list
│ ├── stacks.py Stack (LIFO)
│ ├── queue.py Queue (FIFO) with deque
│ ├── hash.py Hash functions
│ └── dictionary.py Dictionary/HashMap operations
│
├── Sorting Algorithms/
│ ├── bubble_sort.py O(n^2) sorting
│ └── merge_sort.py O(n log n) sorting
│
├── Searching Algorithms/
│ └── binary_search.py O(log n) search
│
├── Recursion/
│ └── factorial.py Recursive and iterative factorial
│
├── exercises/
│ ├── practice.py Self-grading exercises (start here after the lessons)
│ └── test_practice.py The autograder that checks your solutions
│
└── check.py Prints your exercise progress as a scoreboard
| Data Structure | File | Time Complexity | Space |
|---|---|---|---|
| Arrays | arrays.py |
Access: O(1), Search: O(n) | O(n) |
| Linked Lists | linked_lists.py |
Append: O(n), Search: O(n) | O(n) |
| Stacks | stacks.py |
Push/Pop: O(1) | O(n) |
| Queues | queue.py |
Enqueue/Dequeue: O(1) | O(n) |
| Hash Functions | hash.py |
Hash: O(k) where k = key length | O(1) |
| Dictionaries | dictionary.py |
Insert/Lookup/Delete: O(1) avg | O(n) |
| Algorithm | Best Case | Average Case | Worst Case | Space |
|---|---|---|---|---|
| Bubble Sort | O(n) | O(n^2) | O(n^2) | O(1) |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) |
| Algorithm | Best Case | Average Case | Worst Case | Space |
|---|---|---|---|---|
| Binary Search | O(1) | O(log n) | O(log n) | O(1) |
- Big-O Notation for understanding algorithm efficiency
- Time Complexity: O(1), O(n), O(n^2) examples
- Space Complexity: O(1), O(n) examples
If you use the Try it now button above, you can skip this section entirely.
- Python 3.7 or higher
- Basic understanding of programming concepts
-
Clone the repository:
git clone https://github.com/Kubomu/DSA.git cd DSA -
Install the one tool used by the exercises (pytest):
pip install -r requirements.txt
The lesson files use only the Python standard library, so they run without this step. You only need pytest to grade the practice exercises.
Each file can be run independently:
python "Data Structures/linked_lists.py"
python "Sorting Algorithms/merge_sort.py"
python "Searching Algorithms/binary_search.py"Reading an algorithm is one thing. Writing it yourself, and getting told immediately whether you got it right, is how it sticks. That is what the exercises/ folder is for.
How it works:
- Open
exercises/practice.py. There is one small exercise for each core topic: factorial, binary search, bubble sort, merge sort, a Stack, and a Queue. Each one has a# TODOwhere your code goes. - Fill in a
# TODOwith your own solution. - Ask for a friendly progress report:
You will see a scoreboard, one line per topic:
python check.py
[x] 1. Recursion (factorial) done [ ] 2. Binary search todo [ ] 3. Bubble sort todo ... Solved 1 of 6 - Want the full detail on a result? Run the grader directly:
pytest
- Keep going until all six read
done.
If you get stuck on a topic, open its matching lesson file (named in the exercise) for a worked example, then come back and try again. You cannot break anything, so experiment freely.
Working in a fork? When you push your solved exercises/practice.py to your own fork, GitHub automatically runs the same grader and shows a green check next to your commit once every exercise passes.
Start with the complexity documentation in Computational Complexity and Big-O Notation/ (Intro.md and Notes.md).
Each file contains class or function definitions with docstrings, inline comments, and test cases at the bottom in an if __name__ == "__main__" block.
python "Data Structures/stacks.py"Solve the exercises in exercises/practice.py, change input values, add your own test cases, and compare performance with different input sizes.
- Computational Complexity: read
Intro.mdandNotes.md, studyconstant_time.pyandlinear_time.py - Basic Data Structures:
arrays.py,stacks.py,queue.py - Simple Algorithms:
bubble_sort.py,factorial.py - Practise: solve exercises 1, 3, 5, and 6 in
exercises/practice.py
- Advanced Data Structures:
linked_lists.py,hash.py,dictionary.py - Efficient Algorithms:
merge_sort.py,binary_search.py - Space Complexity: study
O(1).pyandO(n).py - Practise: solve exercises 2 and 4 in
exercises/practice.py
- Big-O Cheat Sheet: bigocheatsheet.com
- Visualizations: visualgo.net
- Practice Problems: leetcode.com, hackerrank.com
- Books: "Introduction to Algorithms" by CLRS, "Grokking Algorithms" by Aditya Bhargava, "Data Structures and Algorithms in Python" by Goodrich et al.
- Python docs: Python Official Docs, collections module, time complexity
Contributions are welcome:
- Report bugs by opening a GitHub issue
- Suggest improvements to implementations
- Add new algorithms and data structures
- Improve documentation
Areas for expansion: Trees, Graphs, Heaps, Tries, Union-Find; Quick Sort, Heap Sort, DFS, BFS, Dijkstra; Dynamic Programming; and more exercises in exercises/practice.py.
This project is open source and available for educational purposes.
Happy learning! Understanding these fundamentals is key to becoming a better programmer. Take your time, experiment with the code, and enjoy the process.