Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Kruskal In this assignment, you will implement Kruskal s Algorithm in C . There are very few rules in how you approach your implementation. You
Kruskal
In this assignment, you will implement Kruskals Algorithm in C There are very few rules in how you approach your implementation.
You must only use the standard libraries or implement yourself.
You may use code from previous assignments.
You must follow the general algorithm concepts as described in lecturelecture notestextbook
You must sort an array of edges using Quick Sort. You may modify your sort code from previous homeworks, but you need to write the sort for edges yourself.
When printing edges, you are required to print the smaller node first. For example, if there is an edges from to always print it as never This is a necessity for the autograder.
Since you need to compare edges, you need to break ties. To compare two edges:
The lower weight wins
On tied weight the smaller from node wins
On tied from node the smaller to node wins
You will implement a program that ask for one input. The only input is the name of a file containing the graph. You will run Kruskals Algorithm on this graph. You will print out the edges as they are added to the MST Then you will print the total weight of the MST
You may assume that you will always be given valid filename. You do not need to do error checking.
You may also assume that all edge weights will be positive nonzero integers.
File Format
The first line of the file is an integer containing the number of nodes in the graph.
Every other line contains three numbers seperated by spaces. The first number is the from edge. The second number is the to edge. The third number is the weight.
This is an undirected graph. Each edge listed in the file may be taken either direction.
Graphs
You are provided with three graphs as example input. They are in the folder graphs. There is also a folder img. It contains images of the graphs. These may be helpful for debugging. The code you write will not use the images at all, they are just provided for reference.
Readme
If there is anything you want to grader to know when reviewing your assignment please put it in readme.md
Examples
Example Graph
Enter File Containing Graph:
submissionfilesgraphsgraphtxt
Running Kruskal's Algorithm
Input File: submissionfilesgraphsgraphtxt
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
MST Weight:
Example Graph
Enter File Containing Graph:
submissionfilesgraphsgraphtxt
Running Kruskal's Algorithm
Input File: submissionfilesgraphsgraphtxt
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
MST Weight:
Example Graph
Enter File Containing Graph:
submissionfilesgraphsgraphtxt
Running Kruskal's Algorithm
Input File: submissionfilesgraphsgraphtxt
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
Added Edge: with weight
MST Weight:
Rubric
All points can be earned by the autograder. If you fail the autograder, a manual review will be completed on the assignment.
Manual Deductions will be applied for break either of the following rules:
points for using any library not in the C standard
points for solving the problem without using a custom Quick Sort
The test file names tell you what they test. The file testGtxt tests Graph
Component Points
testGtxt
testGtxt
testGtxt
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started