Skip to content

Conversation

ShristiC7
Copy link

Describe your change:

  • Add an algorithm — Prim’s Minimum Spanning Tree (MST) algorithm in Python.

This implementation demonstrates how to construct a MST for a connected, undirected, weighted graph using Prim’s algorithm. The code is accompanied by doctests to verify correctness and includes type hints for all functions and parameters.

Reference: Prim’s algorithm - Wikipedia


Checklist:

  • I have read CONTRIBUTING.md
  • This pull request is all my own work — I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Example Doctest:

>>> graph = {
...     'A': {'B': 2, 'C': 3},
...     'B': {'A': 2, 'C': 1},
...     'C': {'A': 3, 'B': 1}
... }
>>> prim_mst(graph)
{'B': 'C', 'C': 'B', 'A': 'B'}
Solves issue #13401 

### Prim’s Algorithm
- **Language:** C++
- **Description:** Constructs a Minimum Spanning Tree (MST) by starting with one vertex and repeatedly adding the smallest possible edge connecting a vertex inside the MST to one outside it.
- **Complexity:** O(E log V)
- **Use Case:** Network design, cost minimization
@algorithms-keeper
Copy link

Closing this pull request as invalid

@ShristiC7, this pull request is being closed as the files submitted contains an invalid extension. This repository only accepts Python algorithms. Please read the Contributing guidelines first.

Invalid files in this pull request: greedy_methods/Prim's_algorithm.cpp

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Oct 16, 2025
@ShristiC7 ShristiC7 mentioned this pull request Oct 16, 2025
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed invalid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant