Skip to content

veniva/algo-minimal-network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimal network

This is the problem 107 from the Project Euler. Initially I did this algorithm as part of a HackerRank challenge. It is an implementation of the Prim's algorithm for finding the minimum weight spanning tree on an un-directed graph that connects the vertices via weighted edges:

Network graph Minimal network
Because the implementation is not very well explained in Wikipedia (difficult to follow), for the second version of the algorithm I followed as an example the C++ implementation of this algorithm at Stephan Brumme's page and did it in Java aiming to improve my Java skills

Input & Output

The input & output are read from a file, and format is as described in HackerRank: First line, consists of two numbers - the number of nodes and the number of edges respectively. The next N number of lines consists of three numbers - the edge represented as start and finish node and the weight:
Input data
The output is a single number - the sum of the total weight of the resulting graph:

15

Program execution

There is a compiled file called minimal-network.jar which you can run using the following command:
java -jar minimal-network.jar data.txt

About

Implementation of the Prim's algorithm

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages