


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Data Structures and Algorithms; Subject: Computer Science and Engineering ; University: University of Nebraska - Lincoln; Term: Spring 2009;
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Name
Student ID
Instructions Follow instructions carefully, failure to do so will result in points being deducted. It is highly recommended that you typeset your homework using LATEX or Word. Staple this cover page to the front of your assignment for easier grading. Be sure to submit a hardcopy of your problem answers and your program analysis in class. Clearly label each problem and submit the answers in order. Put your program analysis to the end. In addition, submit your homework in- cluding the problem answers, all the program files and the program analysis via the webhandin (http://www.cse.unl.edu/~cse310/handin). Late homework policy specified in course syllabus will be strictly followed. Be sure to show sufficient work to justify your answer(s). Numerical and yes/no answers with no explanation will NOT be granted full points. If you are asked to prove something, you must give as formal, rigorous, and complete proof as possible. You are to work individually, and all work should be your own. The CSE academic dishonesty policy is in effect (http://cse.unl.edu/undergrads/academic integrity.php).
Problem Page Points Score 1 see below 10 2 see below 10 5.1.2 163 10 5.1.3 163 5 5.3.1(b) 176 5 5.4.2 181 10 Program Correctness 30 Style/Documentation 10 Analysis 10 Total 100
B) Give a more efficient solution to this problem, using divide-and-conquer.
Write a program (based on a graph traversal algorithm you’ve learned in this class) that, for a given undirected graph, outputs: (i) vertices of each connected component; (ii) a cycle or a message that the graph is acyclic (if there are more than one cycles in a graph, you are required to output just one of them).
Your program must be written in C++, execute correctly on the CSE unix environment, and com- pile using the g++ compiler using a makefile. The makefile should compile your program into an executable called graph inspector. Your main.cpp program should take input from a file via the command line (example: prompt:>graph inspector inputfile) with the following structure in the input file (you may assume that an input file will be well structured so you don’t have to error check the input).
Each line of the input file represents a graph. The first number in a line specifies the number of vertices in the graph. Then pairs of nodes define the edges.
An example of an input file is as follows:
5 (1,2) (3,4) (3,5) (4,5) 4 (1,2) (2,3) (1,4)
It specifies two graphs. The first graph has five vertices (1,2,3,4,5) and four edges. The second graph has four vertices (1,2,3,4) and three edges.
Proper output should look (something) like:
//////////////////////////////////////////////////// Graph1: Two connected components: {1 2} {3 4 5} Cycle detected: 3 - 4 - 5 - 3
Graph2: One connected component: {1 2 3 4} The graph is acyclic. ///////////////////////////////////////////////////
Points will be awarded based on the following categories: