Basic information:

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:

What your program must check:

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