Thank you for your interest in contributing! This repository is meant to be a clear, beginner-friendly collection of Data Structures and Algorithms (DSA) in Python. Contributions that improve clarity, coverage, or quality are very welcome.
- New algorithms (e.g., new sorting methods, search techniques, recursion patterns, DP, graph algorithms, etc.).
- New data structures (e.g., stacks, queues, trees, heaps, graphs).
- Improved examples (clearer inputs, better variable names, more comments).
- Documentation (explanations, per-topic READMEs, complexity notes).
- Refactoring for clarity (without changing the underlying algorithmic logic).
Please keep contributions educational and beginner-friendly.
0 Python/– Python basics and simple DSA practice.1 Basic_Maths/– Number theory and basic math problems.2 Sorting/– Sorting algorithms.3 Arrays/– Array ADT and array-based algorithms.4 Binary Search/– Binary search implementations.5 Hashing/– Introductory hashing.6 Recursion/– Recursion examples and patterns.7 Strings/– String algorithms and problems.8 Linked List/– Linked list implementations.
When adding new code, try to place it in the most appropriate existing folder. If you feel a new topic folder is needed, briefly explain your reasoning in the pull request.
To keep the repository consistent and easy to learn from:
-
One concept per file
- Prefer
binary_search_recursive.py+binary_search_iterative.pyover one large file with many unrelated algorithms. - If a file must contain multiple functions, keep them closely related and clearly separated with comments.
- Prefer
-
Clear, descriptive naming
- Use lowercase with underscores for file and function names (e.g.,
reverse_string.py,linear_search.py). - Variable names should be meaningful (e.g.,
arr,left,right,key,head,node, nota,b,c).
- Use lowercase with underscores for file and function names (e.g.,
-
Comments and explanation
- At the top of each file, briefly state:
- What the algorithm/data structure does.
- Any assumptions (sorted input, constraints, etc.).
- Add inline comments for tricky parts of the logic.
- Include time and space complexity (Big-O) in a short comment near the function or at the top of the file.
Example:
# Binary Search (Iterative) # Time Complexity: O(log n) # Space Complexity: O(1)
- At the top of each file, briefly state:
-
Input/output style
- Prefer self-contained examples:
- Define sample input inside the file.
- Print the result clearly.
- If you need user input, validate and document the expected format in comments.
- Prefer self-contained examples:
-
Dependencies
- Prefer the Python standard library.
- External libraries should only be used when they make the concept clearer (e.g.,
numpyin one or two educational examples). - Do not add heavy dependencies or frameworks.
-
Formatting
- Stick to standard Python conventions (PEP 8 as a soft guideline).
- Use 4 spaces for indentation.
- Keep lines reasonably short and readable.
Most scripts are simple, standalone Python files.
Prerequisites
- Python 3.x installed.
Running a script
From the repository root:
cd "3 Arrays/Python"
python3 "00 arrayADT.py"Adjust the path and filename for the script you want to run. For example:
cd "2 Sorting/Python"
python3 bubblesort.pyIf a script requires an extra library (for example, numpy in some array examples), install it with:
pip install numpyIf you add a script that needs external libraries, clearly mention them in comments at the top of the file and in your pull request description.
-
Choose the right folder
- Example: A new recursion example →
6 Recursion/Python(if that substructure exists) or the closest matching folder. - If unsure, pick the closest topic and explain your choice in the PR.
- Example: A new recursion example →
-
Create a new file
- Use a descriptive name, e.g.,
merge_sort.py,two_sum.py,reverse_linked_list.py.
- Use a descriptive name, e.g.,
-
Document the file
- At the top, include:
- Short description.
- Time and space complexity.
- Any constraints or assumptions.
- At the top, include:
-
Add example usage
- At the bottom of the file, show how the function is used with a small example.
- Print the output clearly so learners can see what happens.
-
Test your code
- Run the script locally:
python3 your_script.py
- Make sure it runs without errors and behaves as expected.
- Run the script locally:
- Fork the repository on GitHub.
- Create a new branch in your fork:
git checkout -b feature/new-algorithm-name
- Make your changes (add files, update documentation, etc.).
- Run your scripts to ensure they work.
- Commit with a clear message:
git commit -m "Add merge sort example in Python" - Push your branch:
git push origin feature/new-algorithm-name
- Open a Pull Request:
- Describe:
- What you added or changed.
- Where the new file lives.
- Any dependencies or assumptions.
- If the change relates to an existing issue, mention it.
- Describe:
- The maintainer (or other contributors) will review your PR.
- You may be asked to:
- Adjust file names or folder placement.
- Improve comments or complexity explanations.
- Tidy up formatting.
- Once everything looks good, your PR will be merged.
Thank you again for helping make this DSA-Python repository more useful for learners and interview prep!