Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PrimsAlgorithm #274

Closed
wants to merge 1 commit into from
Closed

Conversation

shantanu020
Copy link

Pull Request Description: Add Prim's Algorithm in Java (DSA Folder) #268

Overview

This pull request introduces the implementation of Prim's Algorithm in Java, added to the DSA/Java folder. Prim's Algorithm is a fundamental algorithm in graph theory used to find the Minimum Spanning Tree (MST) of a connected, undirected graph with weighted edges.

Key Features

  • Greedy Approach: The algorithm employs a greedy strategy to ensure that the minimum weight edges are chosen to construct the MST incrementally.
  • Priority Queue: It utilizes a priority queue to efficiently select the edge with the smallest weight that connects a vertex in the MST to a vertex outside the MST.
  • Example Implementation: An example adjacency matrix is provided to demonstrate the algorithm's functionality.

Code Implementation

The implementation includes:

  • An Edge class to represent edges with source, destination, and weight.
  • A primsAlgorithm method that takes an adjacency matrix as input and prints the edges included in the Minimum Spanning Tree along with their weights.
  • A main method showcasing a sample graph for demonstration purposes.

Why This Addition is Valuable

  • Educational Resource: This implementation enhances the existing graph algorithm resources in the repository, making it easier for learners to understand and practice graph-related concepts.
  • Practical Applications: Prim's Algorithm is widely used in network design, clustering, and other applications that require efficient spanning tree solutions.

Testing

Test cases demonstrating the algorithm’s functionality with the provided example graph are included in the code.

Labels

I recommend labeling this pull request as hacktoberfest and enhancement.

Thank you for considering this addition to the repository!

@shantanu020
Copy link
Author

Contribution Proposal - Add Prim's Algorithm in Java (DSA Folder) #268

Hi, I would like to propose adding Prim's Algorithm in Java to the DSA folder of the repository (#268). This algorithm is essential for finding the Minimum Spanning Tree (MST) in a graph.

Description: Prim's Algorithm is a greedy algorithm that helps find the minimum spanning tree for a connected, undirected graph with weighted edges. The MST is a subset of the edges that connects all vertices in the graph without any cycles and with the minimum possible total edge weight. This algorithm is particularly useful in various applications, including network design and optimization problems.

Proposed Changes:

Implement Prim's Algorithm in Java and place it inside the DSA/Java folder.
I will utilize a priority queue to ensure the implementation is efficient and straightforward.
The code will be well-documented, with test cases to demonstrate its functionality.

@shantanu020 shantanu020 closed this by deleting the head repository Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant