Basic information:
-
The project is due by Tuesday November 20, 11:00am. Do not submit your
project earlier than Monday, November 5.
It will probably just take a day of work to complete this project,
so we strongly advise you to submit it well before the due date.
-
This is an individual project, no collaboration is allowed
-
You can implement the project in C, C++, or Java
-
The project has to be submitted from your registered named account, by
typing submit proj from a directory that contains only
the content of your submission
-
Your submission will contain: the source code, a makefile producing an
executable (or .class file) called mistree, and a text file
explaining the algorithm that you use and analyzing the running time.
-
Of the 100 points this project is worth, 50 points will be given if and
only if the code compiles and the executable correctly solves our test
instances in reasonable time; 50 points will be given for devising the
right algorithm with proper running time, and correctly analyzing it.
Specification
The independent set problem
Given an undirected graph G=(V,E), an independent set is a set I
of vertices such that for every pair of vertices i,j in I, the edge (i,j)
does not belong to E. The maximum indpendent set problem is the problem
of finding a largest independent set in a given graph. For the sake of
this problem, we are just interesting in computing the size of a
largest independent set.
This problem is very hard in general, however it can be solved in O(|V|)
time on acyclic graphs (trees and forests).
What your program should do
On input an undirected graph G=(V,E) represented using adjacency lists,
your program first checks that it is an acyclic graph, and then outputs
0 if the graph has a cycle, or outputs the size of the largest independent
set of G otherwise. The program should run in O(|V|) time.
The program reads the input from a file, whose name is specified in
the command line. So if the name of your program is mis-tree, then
it is invoked with the line mistree filename (or java mistree
filename) where filename
is the name of the file containing
the description of the input graph. Your program outputs the size of the
largest independent set in the graph (or 0 if the graph has a cycle) on
the standard output.
The program expects the input file to have the following structure:
the first line contains an integer n that specifies the number of
vertices in the graph. The vertices in the graph are named with the numbers
1,. . ., n. Each following line starts with the name i of a vertex,
followed by the number of vertices adjacent to i, followed by the
list of vertices that are adjacent to i. Click here
to see the file corresponding to a triangle, and click here
to see the file corresponding to a path of length 4. Your program may expect
the adjacency lists to be given for vertices in sorted order (as in the
examples above), so that the first number in each line is there only to
facilitate reading by humans.
What your program needs not check:
-
that the graph is undirected (i.e. that v is in the list for u if and only
if u is in the list for v),
-
that the format of the input file is correct (we will test your program
only on correctly formatted input files).
What your program must check:
-
that the graph is acyclic: some of our test instances will be graphs with
cycles, and your program must output 0 for such instances.
Examples
triangle: output 0
path-4: output 3
forest: output 6
non-forest: output 0
ex1: output 9
ex2: output 0
ex3: output 1816
Once more:
To submit the project, type submit proj from your registered named
account (between November 5 and November 20), while you are in a directory
that contains only what you want to submit (that is, makefile, source code,
text file with explanation of the algorithm). Be sure that running make
on a cory.eecs machine in that directory will give no compilation error
and will produce an executable called mistree (or a file called
mistree.class)
that does what it is supposed to do.
Last modified November 8, 2001
cs170@cory.eecs.berkeley.edu