Assignment 4: Finding Minimum Spanning Trees using Prim's and Kruskal's Algorithms, Assignments of Data Structures and Algorithms

Instructions for assignment 4 in the cop 4531 algorithms course, where students are required to implement programs to find the minimum spanning tree of a connected graph using prim's and kruskal's algorithms. Details on the input and output file formats, sample files, and submission instructions.

Typology: Assignments

Pre 2010

Uploaded on 09/17/2009

koofers-user-6zr
koofers-user-6zr 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COP 4531 Algorithms
Spring 2007
Assignment 4
Due: 19 Apr 2007
Problem: In this assignment, you will implement programs to find the minimum spanning
tree in two different ways.
Sorting methods: You should create programs that will find the minimum spanning tree of a
connected graph using the following algorithms.
1. Prim's algorithm.
2. Kruskal's algorithm.
Running the program: Your program will be run as follows:
<executable-name> <input-file-name> <output-file-name>
Input and output files: The input and output files will have the following format.
Input Output
n
v1 s11 w11 s12 w12... s1k1 w1k1
.
.
vn sn1 wn1 sn2 wn1 ... snkn wnkn
n
v1 r11 r12... r1l1
.
.
vn rn1 rn2 ... rnln
Here, n is the number of vertices, vi are strings containing the names of vertices, sij is a string
giving the name of the j th neighbor of vertex i in the original graph, wij is a float number
giving the weight of the corresponding edge, ki is the degree of vertex vi in the original graph,
rij is a string giving the name of the j th neighbor of vertex i in the minimum spanning tree
found, and li is its degree in this tree.
Sample input file Sample output file
4
ab cd 4.2 e 1.0 f 1.0
cd ab 4.2 e 3.2
e ab 1.0 cd 3.2 f 2.3
f ab 1.0 e 2.3
4
ab e f
cd e
e ab
f ab
pf2

Partial preview of the text

Download Assignment 4: Finding Minimum Spanning Trees using Prim's and Kruskal's Algorithms and more Assignments Data Structures and Algorithms in PDF only on Docsity!

COP 4531 Algorithms

Spring 2007

Assignment 4

Due: 19 Apr 2007

Problem: In this assignment, you will implement programs to find the minimum spanning tree in two different ways.

Sorting methods: You should create programs that will find the minimum spanning tree of a connected graph using the following algorithms.

  1. Prim's algorithm.
  2. Kruskal's algorithm.

Running the program: Your program will be run as follows: <executable-name> <input-file-name> <output-file-name>

Input and output files: The input and output files will have the following format.

Input Output n v1 s 11 w 11 s 12 w 12 ... s (^1) k 1 w (^1) k 1 . . vn sn1 wn1 sn2 wn1 ... sn (^) kn wn (^) k n

n v1 r 11 r 12 ... r (^1) l 1 . . vn rn1 r (^) n2 ... rn (^) l n

Here, n is the number of vertices, vi are strings containing the names of vertices, sij is a string giving the name of the j th neighbor of vertex i in the original graph, wij is a float number giving the weight of the corresponding edge, ki is the degree of vertex vi in the original graph, rij is a string giving the name of the j th neighbor of vertex i in the minimum spanning tree found, and l (^) i is its degree in this tree.

Sample input file Sample output file 4 ab cd 4.2 e 1.0 f 1. cd ab 4.2 e 3. e ab 1.0 cd 3.2 f 2. f ab 1.0 e 2.

ab e f cd e e ab f ab

Files: You should create a directory called COP4531/hw4 on linprog. This directory should contain the following files, implementing the algorithm indicated by the file name.

  1. prim.c
  2. kruskal.c
  3. Makefile : The makefile for this assignment. Typing make should create two executables: prim and kruskal , corresponding to each of the above algorithms.

Sample application: Please run your code on a graph that arises from some real world application, using real world data, and report the results you get, in one or two pages. Your report you should mention the application you considered, identify what the vertices, edges, and edge weights represent (for example, vertices are cities, edges are roads between cities, and weights are driving distances), give the size of the data in terms of the number of edges and number of vertices, cite the source of your data, and summarize your findings.

Turning in your assignment: The code is due by midnight of the due date. Turn in instructions will be provided later. A hardcopy of the report is due by 5 pm on 20 April 2007.

Grading: You will be graded on the following (i) correctness of your codes, (ii) performance of your codes, and (iii) the quality of your report.