|
| 1 | +🧩**Usage Example** |
| 2 | + |
| 3 | +This repository contains implementations of many popular algorithms and data structures in Python. |
| 4 | +You can clone the repository, explore, run tests, and even add your own algorithms easily. |
| 5 | + |
| 6 | +🛠️**Clone the Repository** |
| 7 | +# Clone the repo |
| 8 | +git clone https://github.com/TheAlgorithms/Python.git |
| 9 | + |
| 10 | +# Move into the folder |
| 11 | +cd Python |
| 12 | + |
| 13 | +🧪**Run Tests** |
| 14 | +You can use the built-in Python test framework to verify that all algorithms work correctly. |
| 15 | +# Run all tests |
| 16 | +python -m unittest discover |
| 17 | + |
| 18 | +# Or run a specific test file |
| 19 | +python -m unittest tests/test_sorting.py |
| 20 | + |
| 21 | +💡 Tip: Always make sure your Python version matches the one mentioned in the repository’s requirements (usually Python 3.10+). |
| 22 | + |
| 23 | +🧠**Try Out an Algorithm** |
| 24 | +You can run any algorithm file directly to understand how it works. |
| 25 | +For example, let’s run the Bubble Sort algorithm: |
| 26 | + |
| 27 | +# Navigate to the sorting folder |
| 28 | +cd sorting |
| 29 | + |
| 30 | +# Run bubble_sort.py |
| 31 | +python bubble_sort.py |
| 32 | + |
| 33 | +Output Example: |
| 34 | +Unsorted array: [5, 1, 4, 2, 8] |
| 35 | +Sorted array: [1, 2, 4, 5, 8] |
| 36 | + |
| 37 | +✍️ Add Your Own Algorithm |
| 38 | +You can contribute by adding new algorithms or improving existing ones. |
| 39 | +1.Fork the repository |
| 40 | +2.Create a new branch for your feature(#most important thing to do) |
| 41 | + |
| 42 | +# ----> git checkout -b add-new-algorithm <---- |
| 43 | + |
| 44 | +3.Add your code inside the appropriate directory (e.g. graphs/, sorting/, etc.) |
| 45 | +4.Include: |
| 46 | +Proper function docstrings |
| 47 | + |
| 48 | +5.Example usage |
| 49 | +1.Time and space complexity comments |
| 50 | +2.Test your code and submit a Pull Request 🚀 |
| 51 | + |
| 52 | +🧹**Example Folder Structure** |
| 53 | + |
| 54 | +Python/ |
| 55 | +│ |
| 56 | +├── data_structures/ |
| 57 | +│ └── stacks/ |
| 58 | +│ └── stack_using_list.py |
| 59 | +│ |
| 60 | +├── graphs/ |
| 61 | +│ └── dijkstra.py |
| 62 | +│ |
| 63 | +├── sorting/ |
| 64 | +│ └── bubble_sort.py |
| 65 | +│ |
| 66 | +└── tests/ |
| 67 | + └── test_sorting.py |
| 68 | + |
| 69 | +📦**Example Output (from Dijkstra’s Algorithm)** |
| 70 | +# python graphs/dijkstra.py |
| 71 | +Sample Output |
| 72 | +# Shortest distances from source: |
| 73 | +A: 0 |
| 74 | +B: 4 |
| 75 | +C: 2 |
| 76 | +D: 7 |
| 77 | + |
| 78 | +🧾 **Commit and Create a Pull Request** |
| 79 | +Once you’ve verified everything works: |
| 80 | + |
| 81 | +# git add . |
| 82 | +# git commit -m "Added new algorithm: My Algorithm" |
| 83 | +# git push origin add-new-algorithm |
| 84 | + |
| 85 | +# Then, open your fork on GitHub and click “**Compare & pull request**”. |
| 86 | +Be sure to: |
| 87 | +1.Write a clear PR title and description |
| 88 | +2.Explain what your code does and where it fits |
| 89 | +3.Add example input/output and complexity if possible |
| 90 | + |
| 91 | + |
0 commit comments