Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ We are on [Discord](https://the-algorithms.com/discord) and [Gitter](https://git
## 📜 List of Algorithms

See our [directory](DIRECTORY.md) for easier navigation and a better overview of the project.

For understanding the whole process of contribution refer to [usage-example](Usage-example.md).
Highly useful for beginners.
91 changes: 91 additions & 0 deletions Usage-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
🧩**Usage Example**

This repository contains implementations of many popular algorithms and data structures in Python.
You can clone the repository, explore, run tests, and even add your own algorithms easily.

🛠️**Clone the Repository**
# Clone the repo
git clone https://github.com/TheAlgorithms/Python.git

# Move into the folder
cd Python

🧪**Run Tests**
You can use the built-in Python test framework to verify that all algorithms work correctly.
# Run all tests
python -m unittest discover

# Or run a specific test file
python -m unittest tests/test_sorting.py

💡 Tip: Always make sure your Python version matches the one mentioned in the repository’s requirements (usually Python 3.10+).

🧠**Try Out an Algorithm**
You can run any algorithm file directly to understand how it works.
For example, let’s run the Bubble Sort algorithm:

# Navigate to the sorting folder
cd sorting

# Run bubble_sort.py
python bubble_sort.py

Output Example:
Unsorted array: [5, 1, 4, 2, 8]
Sorted array: [1, 2, 4, 5, 8]

✍️ Add Your Own Algorithm
You can contribute by adding new algorithms or improving existing ones.
1.Fork the repository
2.Create a new branch for your feature(#most important thing to do)

# ----> git checkout -b add-new-algorithm <----

3.Add your code inside the appropriate directory (e.g. graphs/, sorting/, etc.)
4.Include:
Proper function docstrings

5.Example usage
1.Time and space complexity comments
2.Test your code and submit a Pull Request 🚀

🧹**Example Folder Structure**

Python/
├── data_structures/
│ └── stacks/
│ └── stack_using_list.py
├── graphs/
│ └── dijkstra.py
├── sorting/
│ └── bubble_sort.py
└── tests/
└── test_sorting.py

📦**Example Output (from Dijkstra’s Algorithm)**
# python graphs/dijkstra.py
Sample Output
# Shortest distances from source:
A: 0
B: 4
C: 2
D: 7

🧾 **Commit and Create a Pull Request**
Once you’ve verified everything works:

# git add .
# git commit -m "Added new algorithm: My Algorithm"
# git push origin add-new-algorithm

# Then, open your fork on GitHub and click “**Compare & pull request**”.
Be sure to:
1.Write a clear PR title and description
2.Explain what your code does and where it fits
3.Add example input/output and complexity if possible