Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Coloring a Graph - Introduction to Algorithms - Programming Assignment | CMPSCI 311, Assignments of Algorithms and Programming

Material Type: Assignment; Professor: Sitaraman; Class: Intro To Algorithms; Subject: Computer Science; University: University of Massachusetts - Amherst; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-t7w
koofers-user-t7w 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMPSCI 311 - Spring 09
PROGRAMMING ASSIGNMENT: Coloring a Graph
Due date: Tuesday, May 5th - Beginning of lecture.
Note: We did this problem in the discussion hour. If you did not attend this class, please make
sure that you talk to your friends or come and meet me.
Description:
In this programming assignment, you must write an efficient program to determine whether or
not an (undirected) graph G= (V, E ) is 2-colorable. Your algorithm should run in O(|V|+|E|)
steps. Please a language such as C, C++, or Java for this assignment.
A graph is said to be 2-colorable if and only if it is possible to assign one of two colors (say red
or blue) to each of the nodes of the graph such that no two nodes which are connected by an edge
are assigned the same color.
The input file to your program is in the following format. The first line of the file contains the
number of nodes (|V|). The nodes are numbered 1 through |V|. Each subsequent line contains a
pair of nodes such that each such pair defines an edge. You are provided with three different input
files in directory /courses/cs300/cs311/cs311/311 PROG1 INPUT on the EDLAB machines. The
names of the input files are smallgraph,largegraph1, and largegraph2. You must run your
program on all three input files.
Checklist of what you must submit:
1. Code: You must submit a printout of your code. Your code must be well-documented with
ample comments, so that it is easy to figure out what your code is doing.
2. Description, Correctness and Time analysis. Describe your algorithm. Append a
paragraph proving why your algorithm produces the right answer, and also a derivation of
the running time in terms of |V|and |E|.
3. Timing: Run you algorithm on all three input files. Time your algorithm on these inputs
using the unix command time. Submit all the timing information (user time, system time
etc) that time gives you. Write down and submit the machine that you timed it on (e.g.,
Alpha workstation). Also place your program and executable in your class directory. The TA
will look at it if necessary.
4. Output: Your program must produce the following output.
Whether or not the graph is 2-colorable (Yes or No).
If the graph is not 2-colorable, output a substructure of the graph that makes it non-
colorable, example, a cycle with an odd-number of nodes that is contained in the graph
If the cycle is long, say over 50 nodes, do not print it out. Leave it in a clearly marked
file for the TA to see. Your writeup should say where the file is located.
If the graph is 2-colarable, output a valid coloring of the graph. If the graph has more
than 50 nodes, do not print it out. Leave it in a clearly marked file for the TA to see.
Your writeup should say where the file is located. (Only the color assignment for the
smallgraph need be printed out.
pf2

Partial preview of the text

Download Coloring a Graph - Introduction to Algorithms - Programming Assignment | CMPSCI 311 and more Assignments Algorithms and Programming in PDF only on Docsity!

CMPSCI 311 - Spring 09

PROGRAMMING ASSIGNMENT: Coloring a Graph

Due date: Tuesday, May 5th - Beginning of lecture.

Note: We did this problem in the discussion hour. If you did not attend this class, please make sure that you talk to your friends or come and meet me.

Description:

In this programming assignment, you must write an efficient program to determine whether or not an (undirected) graph G = (V, E) is 2-colorable. Your algorithm should run in O(|V | + |E|) steps. Please a language such as C, C++, or Java for this assignment.

A graph is said to be 2-colorable if and only if it is possible to assign one of two colors (say red or blue) to each of the nodes of the graph such that no two nodes which are connected by an edge are assigned the same color.

The input file to your program is in the following format. The first line of the file contains the number of nodes (|V |). The nodes are numbered 1 through |V |. Each subsequent line contains a pair of nodes such that each such pair defines an edge. You are provided with three different input files in directory /courses/cs300/cs311/cs311/311 PROG1 INPUT on the EDLAB machines. The names of the input files are smallgraph, largegraph1, and largegraph2. You must run your program on all three input files.

Checklist of what you must submit:

  1. Code: You must submit a printout of your code. Your code must be well-documented with ample comments, so that it is easy to figure out what your code is doing.
  2. Description, Correctness and Time analysis. Describe your algorithm. Append a paragraph proving why your algorithm produces the right answer, and also a derivation of the running time in terms of |V | and |E|.
  3. Timing: Run you algorithm on all three input files. Time your algorithm on these inputs using the unix command time. Submit all the timing information (user time, system time etc) that time gives you. Write down and submit the machine that you timed it on (e.g., Alpha workstation). Also place your program and executable in your class directory. The TA will look at it if necessary.
  4. Output: Your program must produce the following output.
    • Whether or not the graph is 2-colorable (Yes or No).
    • If the graph is not 2-colorable, output a substructure of the graph that makes it non- colorable, example, a cycle with an odd-number of nodes that is contained in the graph If the cycle is long, say over 50 nodes, do not print it out. Leave it in a clearly marked file for the TA to see. Your writeup should say where the file is located.
    • If the graph is 2-colarable, output a valid coloring of the graph. If the graph has more than 50 nodes, do not print it out. Leave it in a clearly marked file for the TA to see. Your writeup should say where the file is located. (Only the color assignment for the smallgraph need be printed out.

Helpful Hints: You want to consider using standard search techniques like BFS and DFS and modifying them.

Administrivia: You must use the EDLAB for doing these assignments. All of you have accounts on the EDLAB machines (if you do not, contact the TA or me). After you login please type cd cs311, so that you do all your work for this course in the cs311 directory.