CSC 141: Assignment 1

The solutions for the written part in 10 pages.
Only pdf and gif is available.
Page 1 ps or pdf or gif
Page 2 ps or pdf or gif
Page 3 ps or pdf or gif
Page 4 ps or pdf or gif
Page 5 ps or pdf or gif
Page 6 ps or pdf or gif
Page 7 ps or pdf or gif
Page 8 ps or pdf or gif
Page 9 ps or pdf or gif
Page 10 ps or pdf or gif

ATTENTION
The written part is due at the beginning of the class on the 24 Oct.
The programming part is due on the 11:59pm on 23 Oct.
 

Part I.  Theoretical / Written. [50 points]

 Note: 1. You are not required to type this part, but you have to make sure that
your hand-writing is eligible.
            2. You have to provide full answers to the questions; complete english phrases
and complete proofs. A figure without a comment is not an answer. Figures are auxiliary,
answers "something like this figure" do not count for much.

Answer the following exercises from the book.

1. Exercise  5.4-1 [5]
2.                 5.4-3   [5]
3.                 5.4-4   [5]
4.                 5.5-2   [5] Hint: show a graph for n=7 and then try to generalize it for n>7
5.                 5.5-3    [5]

6. Problem  5-1  [20] ONLY  questions a) and b)

7. Exer.         23.2-4 [5]
 
 

Part II.  Programming. [50]

To be submitted with the submit service by 11:59pm on 23 Oct.
 The program should run in Linux.  you can ofcourse develop it in any platform you want,
but you have to make sure that submitted version runs in linux. Contact your TA if this seems to be a problem.

We want to write a program in C++ that to identify and create undirected  rooted trees. The program should read a file with the graph data, convert it into an adjacency-list representation.
It should check if the input graph is  a tree, create an instance of the class Tree, and print it in the format shown
below.
If the input graph is not a tree, it should identify redundant edges, list redundant edges, and create
an instance of a Tree without the redundant edges, verify that the new Tree is a tree, and the print it in the format shown below.
Redundant edges in this context mean the edges of a cycle that we want to remove.
If the graph is disconnected you should focus on the component that has the root, but you have
to print a message showing that it is disconnected.

OUTPUT:  For each execution:
a. [5] the input graph
b. [5] is it a tree? yes/no
c. [5]     If yes, print the tree
d. [5]     If no,  is it connected?
e. [10]             If yes,  show redundant edges
f.                             Remove edges, is the remaining a tree? (should be), print tree.
g.                If not connected, repeat setps e, f for the component with the root.
h.  [+5]      BONUS: treat each connected component as the initial input with root the minimum id node
                    i.e. print all possible "hidden" in the input trees

The other 20 points: are the report, the makefile, the programming style, programming efficiency etc.

Note: the input data will be a legitimate graph in the format shown below. However, the graph may  be any graph,
i.e. have cycles or be disconnected, or have one node etc. But you do NOT have to consider cases where
strings are given instead of numbers or that an edge has a missing node etc.

---------------------------------------------------------
Please follow the directions, names and conventions carefully. This is essential for the ease and speed of
grading. Failure to comply will end up in small grade reductions.
---------------------------------------------------------

In more detail, your executable should be named "run" and it should be run as follows:

$ run  < datafile

Your program should handle more than the sample data files given.
The data file should  first give the  total number of nodes, the root of the tree and then pairs of nodes that are connected with an edge:

30                            // number of nodes
3                              // root id
1     2
2     3
. . .
n1     n2

Note:  n1  n2  implies the undirected edge between n1 n2

We want to implemement the following classes:

  - class Graph;
  - class Tree;
  - class Node;
  - class Edge;
 

We want to implement the following methods:
 For all four  classes:
* constructors and destructors

Furthermore:
* Graph:: show();              // print all edges of the graph in the format: n1  --  n2
* Tree:: show();                 // start from root and show children in BFS order showing the depth of the child
                                              // from the root  i.e.   Root: 3
                                                                                         depth: 1  node: 11
                                                                                         depth: 2  node: 23
* Tree:: isTree();                 // check to see if the  input data represents a tree
* Tree:: identifyCycles();   //  Do BFS to identify redundant edges
* Tree:: listRemovedEdges();  // list redundant edges
* Tree:: removeCycles(); // create a new Tree instance without the redundant edges

[Clarification Oct 14:  It may seem more natural to have the last 4 methods in the
classGraph. You can do that if you want, but you have to mention it in your report]

You can have as many methods and fiels you want. Your code should be documented: every method should have a brief  explanation.

You should have the program in multiple files: header.h,  [class].cc, main.cc. You should compile it with
the use of a makefile. Your wonderful TAs will explain this in the lab and provide some makefile samples.

You have to provide a report, the programs and an output.

Report

   You must write a 1 page report explaining what you did and how, what you did not do, a sample output.
The grader should be able to grade the assignment by just reading the report. However, the grader will check out your program and your programming style.
    The report should:
     * report whether your program runs correctly or not
     * mention any assumptions that you make
     * give an overview  how your program works (no more than 500-800 words)
and list and explain very briefly the major classses and methods, especially if we used complicated algorithms and solutions
     * report any problems and limitations
    The report is a way for you to get more points by showing that you understood more things than
what probably your non-perfect or buggy program does. However, it is required.

Programs and output

  Electronically: submit
         a. your program ready to compile and your executable named: run
         b. your makefile
         c. a README file for instructions on how to run it
         f. the report in ascii.
         e. the output of your program in the sample datasets
A copy of your report should be given with the Part I of the assignment.

WARNING: A report that makes false claims about the program will be considered as cheating.
                        An output sample that is not generated by the submitted program will also be considered
as cheating.

Check:  http://www.cs.ucr.edu/~klick/    the links for linux (for makefiles) and programming for
stylisitc and programming suggestions.