I attached a un-finished file for this assignment, it should help and make this a lot easier.
==========================================================================_x000D_
_x000D_
READING_x000D_
_x000D_
Read the text, sections 7.1 – 7.4 for explanations of what the dfs skeleton_x000D_
and dfsTrace functions are are doing. This has been covered in lectures_x000D_
and will be covered further in sections._x000D_
Depth-first search (DFS) is a major topic for this course._x000D_
_x000D_
Read the text, section 7.5 for explanations of how the the SCC algorithm_x000D_
is based on DFS._x000D_
The SCC algorithm will be covered in lectures before the assignment is due,_x000D_
and further in sections._x000D_
_x000D_
Depth-first search (DFS) and the strongly connected component algorithm (SCC)_x000D_
are major topics for this course._x000D_
_x000D_
Several online Unix tutorials are mentioned on the class web page._x000D_
_x000D_
==========================================================================_x000D_
_x000D_
INFORMATION SOURCES_x000D_
_x000D_
Same as ho04.txt and ho07.txt, the 1st and 2nd program assignments._x000D_
_x000D_
There are usually quite a few questions and clarifications about programs_x000D_
on the “C101” mailing list, so keep up. Consider the source when_x000D_
evaluating a message, because there is no screening of the postings._x000D_
CHECK YOUR SPAM BOX REGULARLY. Google likes to put things there._x000D_
_x000D_
Throughout this handout and this class, “unix.ic” abbreviates_x000D_
“unix.ic.ucsc.edu”, the Linux server provided by the campus._x000D_
JBE 105 is a lab with workstations that have the same OS as unix.ic._x000D_
_x000D_
==========================================================================_x000D_
_x000D_
PROGRAM REQUIREMENTS_x000D_
_x000D_
You will implement Depth First Search as explained in the text, Ch. 7._x000D_
This will be the DFS skeleton for directed graphs, with some added_x000D_
code to carry accomplish the functions described._x000D_
The procedure will correspond closely to DFS Trace in the text._x000D_
_x000D_
The ADDED WORK after DFS Trace works is to find the_x000D_
strongly connected components (SCCs) for unweighted graphs._x000D_
_x000D_
SUBMIT AS YOU GET EACH STAGE WORKING and make backups._x000D_
_x000D_
dfsTrace1.c_x000D_
will implement dfsTrace (Algorithm 7.4, which is a refinement of_x000D_
Algorithm 7.3) on a directed graph represented as an array of_x000D_
adjacency IntVecs._x000D_
(Note that graph02.c and the associated files in pa02, your second_x000D_
program assignment, read a directed graph from input, create_x000D_
the array of IntVecs, and print the graph, so you can simply copy_x000D_
this code from your WORKING pa02. If pa02 was working correctly,_x000D_
this allows you to concentrate on DFS and SCC parts of the program.)_x000D_
_x000D_
intVec.h should be commented as found in the class locker._x000D_
It is almost the same as in pa02, but has one new constructor._x000D_
_x000D_
In this assignment, your intVec.o will be tested with_x000D_
other students’ programs and their intVec.o will be tested with_x000D_
yours. So use the standard names in this class._x000D_
A starter intVec.h is in the course locker, but you need to copy it and_x000D_
put in your comments, as indicated by the questions in the file._x000D_
The starter for pa02 is there too, named intVec.h-pa02, so you can see_x000D_
what changed with “diff”._x000D_
_x000D_
RE-USE THE MAIN C FILE FROM pa02_x000D_
_x000D_
Right from pa02, graph02.c can be renamed to scc03.c and compiled into_x000D_
scc03, for pa03; it contains main() and probably other functions._x000D_
Several other C and .h files can be used right from pa02._x000D_
_x000D_
Of course, for pa03, the “main” procedure will be changed to do_x000D_
different things after the graph is loaded._x000D_
Also, the loadGraph functionality will be separated, as assigned in pa02._x000D_
_x000D_
HIGH-LEVEL FLOW_x000D_
_x000D_
main() should read and interpret the command-line parameters, which_x000D_
are different from in pa02, then open the input file and interact with_x000D_
loadGraph.c functions to input the graph, as in pa02._x000D_
Then call your function to convert the array of adjacency lists to_x000D_
the 2-D adjacency matrix, as in pa02._x000D_
_x000D_
main() should call a function to print the graph, as in pa02._x000D_
As in pa02, when n <= 20 vertices print the adjacency matrix also._x000D_
_x000D_
To compute SCCs, main calls a function with a name like findSCCs()_x000D_
that is also in scc03.c to manage the SCC computation._x000D_
findSCCs() should call the main subroutines dfsTrace1(),_x000D_
transposeGraph(), dfsPhase2(), as well as calling the printing functions._x000D_
IN PARTICULAR, dfsTrace1(), transposeGraph(), dfsPhase2() WILL NOT PRINT_x000D_
ANYTHING. Their job is to compute data structures._x000D_
_x000D_
findSCCs() in scc03.c will allocate the arrays filled by its subroutines._x000D_
Because there are two runs of dfsTrace now, name the arrays filled by_x000D_
dfsTrace1(): discoverTime1, finishTime1, parent1, and finishStk1,_x000D_
or recognizable abbreviations, such as dtime1, etc._x000D_
_x000D_
Also findSCCs() allocates adjVerticesT for the transpose graph._x000D_
Finally, it will allocate the arrays filled by the second dfs,_x000D_
which works on the transpose graph and finds the SCCs: _x000D_
discoverTime2, finishTime2, parent2, dfstRoot2 (or abbreviations)._x000D_
Other procedures will output the contents of the arrays after_x000D_
each dfsTrace has completed._x000D_
_x000D_
Allocating all the arrays in scc03.c makes it easier to pass them as_x000D_
arguments to functions in other files, without making any global arrays._x000D_
However, if you already have working code that allocates and returns_x000D_
an array from a different file (such as loadGraph.c)_x000D_
it is okay to use and build upon that code._x000D_
_x000D_
A more sophisticated way to pass several run-time parameters is that_x000D_
main() or findSCCs() creates a struct with fields for all of them,_x000D_
and then a pointer to that struct is passed around._x000D_
For this technique you should declare the struct AS A TYPE in scc03.h._x000D_
Then scc03.c and loadGraph.c and maybe others #include scc03.h._x000D_
_x000D_
Write dfsTrace1.h to declare the function prototypes in dfsTrace1.c that_x000D_
are called from a different C file. State the pre- and post-conditions_x000D_
in dfsTrace1.h._x000D_
_x000D_
In pa03 dfsTrace1.c should be a separate file and you should have it_x000D_
working before copying it into dfsPhase2.c as a starter._x000D_
It is better to copy working code than debug both versions._x000D_
_x000D_
Aside from intVec.h, intVec.c, scc03.c and scc03, the names of files,_x000D_
functions and arrays should be understandable but do NOT need to be_x000D_
strictly the same as this handout._x000D_
_x000D_
==========================================================================_x000D_
_x000D_
COMMAND-LINE ARGUMENTS_x000D_
_x000D_
If your program receives no command-line arguments, it should print_x000D_
a usage message and exit. If your program receives incorrect_x000D_
command-line arguments, such as an unknown flag or no file name,_x000D_
it also should print a usage message and exit with a positive exit code,_x000D_
such as 1 or 2 or 3._x000D_
_x000D_
Command-line arguments of the form “-something” are often called “flags”,_x000D_
and provide the means for varying the way the program runs,_x000D_
or varying the form of the output. (“-” by itself denotes stdin.)_x000D_
_x000D_
The final command-line argument is the name of the input file,_x000D_
and this name will not begin with a “-” unless it is “-” by itself._x000D_
_x000D_
The command-line flag “-U” instructs the program to build an UNDIRECTED_x000D_
graph from the input. That is, if the input contains “3 5” on a line, enter_x000D_
5 as an adjacency of 3 AND enter 3 as an adjacency of 5._x000D_
DO NOT WORRY ABOUT DUPLICATE EDGES._x000D_
_x000D_
DFS Trace will expect the graph not to be weighted._x000D_
Therefore weights in the input should be parsed if they are present, but_x000D_
they do not become part of the data structure for the graph._x000D_
_x000D_
When running the program on a large input file remember to use “>”_x000D_
to redirect the stdout to a file. DO NOT SUBMIT VERY LARGE TEST FILES_x000D_
OR THEIR OUTPUTS. We will supply some large files._x000D_
_x000D_
Example command lines for doing SCCs:_x000D_
_x000D_
scc03_x000D_
_x000D_
(user wants usage message.)_x000D_
_x000D_
scc03 -_x000D_
_x000D_
(user wants to type in the file, directed.)_x000D_
_x000D_
scc03 test1.in_x000D_
_x000D_
(test1.in is treated as directed.)_x000D_
_x000D_
scc03 -U test2.in_x000D_
_x000D_
(test2.in is treated as undirected.)_x000D_
_x000D_
==========================================================================_x000D_
_x000D_
INPUT FORMAT_x000D_
_x000D_
This is the same as pa01 and pa02, repeated for self-containment._x000D_
_x000D_
Input consists of a sequence of lines read from a file that was given_x000D_
as the LAST command-line argument. The string “-” as a filename_x000D_
stands for “standard input”, as usual._x000D_
We will use stdin to denote either case._x000D_
_x000D_
End-of-file signals the end of input, and is typed on the keyboard_x000D_
as cntl-D in Unix (maybe cntl-Z in DOS, Windows, etc.)._x000D_
_x000D_
Lines will have the format expected by graph01.c with or without_x000D_
without weights._x000D_
_x000D_
One int on the first line to tell us the value of “n”._x000D_
Two ints per line for each edge after that, or two ints and a double per line_x000D_
if the graph is weighted._x000D_
For pa03, weights are parsed but ignored, even if they are_x000D_
present in the input._x000D_
_x000D_
PRINT AN INFORMATIVE ERROR MESSAGE if the input contains a bad vertex_x000D_
number, outside 1,…,n, or has the wrong number of words on a line._x000D_
This is for your own protection. It is not a grading issue and_x000D_
submitting tests to check bad input is not asked and will not count as_x000D_
testing credit._x000D_
_x000D_
Example 1 input, unweighted_x000D_
_x000D_
6_x000D_
1 4_x000D_
5 4_x000D_
1 3_x000D_
2 3_x000D_
3 3_x000D_
5 6_x000D_
6 5_x000D_
4 3_x000D_
1 2_x000D_
_x000D_
Remember that graphs want to start on index 1, not index 0._x000D_
So allocate 1 extra space in the array and start loading at 1._x000D_
_x000D_
Example 2, with weights:_x000D_
6_x000D_
1 4 2.7_x000D_
5 4 -3_x000D_
1 3 0.0_x000D_
_x000D_
UNDIRECTED INPUT_x000D_
_x000D_
Whether the input is treated as undirected or directed depends on a_x000D_
command-line argument “-u”, as described before._x000D_
If the graph is considered undirected, create an edge in each direction_x000D_
from one edge in the input file. In the above example, when “-u” is_x000D_
specified, “1 4 2.7” should result in edges (1,4) and (4,1)._x000D_
_x000D_
Do not worry if edges are not unique. The algorithms will work anyway._x000D_
_x000D_
==========================================================================_x000D_
_x000D_
OUTPUT_x000D_
_x000D_
Print information on stdout. You should know how to structure your_x000D_
unix command line to redirect stdout to a file or another process,_x000D_
so your program is not concerned about these details._x000D_
_x000D_
For a preliminary version, print the input graph as in pa01._x000D_
_x000D_
Example 2 would look something like this:_x000D_
1 [3, 4]_x000D_
2 []_x000D_
3 []_x000D_
4 []_x000D_
5 [4]_x000D_
6 []_x000D_
Using “[]” instead of “null” for an empty list is preferred._x000D_
Details like punctuation may vary but the numbers should be in the order shown._x000D_
_x000D_
It would be quite complicated to try to show that structure of the DFS_x000D_
forest graphically, so for phase 1, write a PROCEDURE that just prints_x000D_
a table of 5 columns for_x000D_
vertex, color, dtime, ftime, and parent,_x000D_
IN THAT ORDER (spacing is flexible). DO NOT USE NUMBERS FOR COLORS!_x000D_
Include column titles (exact spelling not required) and print_x000D_
an empty line after the table._x000D_
_x000D_
Use “-1” for the parent if the vertex is the root of a DFS tree._x000D_
_x000D_
This first table should present the arrays filled by dfsTrace1._x000D_
Also print the arrays filled by dfsTrace1_x000D_
to show whether the graph is being visited correctly._x000D_
Example 2 after dfsTrace1 is finished would look something like this:_x000D_
_x000D_
V color dTime fTime parent_x000D_
1 B 1 6 -1_x000D_
2 B 7 8 -1_x000D_
3 B 2 3 1_x000D_
4 B 4 5 1_x000D_
5 B 9 10 -1_x000D_
6 B 11 12 -1_x000D_
_x000D_
Color should be one of W,G,B and other table entries are ints._x000D_
_x000D_
The reason for making this a procedure is so you can call it at any time_x000D_
(in gdb, most likely, or in debugging code that you remove later)._x000D_
_x000D_
If you call this print function BEFORE dfsTrace1 is finished,_x000D_
every vertex with color W should show 0 for the last 3 columns,_x000D_
and every vertex with color G should show 0 for fTime._x000D_
This might be helpful for debugging and for midterm studying,_x000D_
but should not occur in the submitted program._x000D_
_x000D_
After the table for dfsTrace1, print finishStk1 ON A SINGLE LINE_x000D_
with the bottom element to the left, top to the right._x000D_
E.g.,_x000D_
FSTK: 3 4 1 2 5 6_x000D_
_x000D_
There should not be any other numbers on this line. The title and spacing_x000D_
are flexible, but don’t make the mistake of using “FSTK1”._x000D_
_x000D_
Print the transpose graph in the same format as the original graph._x000D_
The same print function should work for both (the title can be printed_x000D_
before calling the function or passed as a parameter)._x000D_
_x000D_
The last part of the output shows the result of dfsTrace2._x000D_
This shows values for the tranpose graph._x000D_
Write a separate procedure for this._x000D_
_x000D_
Example 2 after dfsTrace2 is finished would look something like this:_x000D_
_x000D_
V color2 dTime2 fTime2 parent2 dfstRoot2_x000D_
1 B 7 8 -1 1_x000D_
2 B 5 6 -1 2_x000D_
3 B 11 12 -1 3_x000D_
4 B 9 10 -1 4_x000D_
5 B 3 4 -1 5_x000D_
6 B 1 2 -1 6_x000D_
_x000D_
This is a pretty boring example, and just shows the format, not an_x000D_
interesting test. In this case, every dfs tree has one vertex and no edges._x000D_
Every SCC has one vertex and is its own dfsRoot._x000D_
_x000D_
==========================================================================_x000D_
_x000D_
HOW TO PROCEED_x000D_
_x000D_
Make a new directory to work in. Do this first._x000D_
_x000D_
If you wrote a weighted edge ADT for pa01, save it for last._x000D_
(It was not assigned in pa01.)_x000D_
_x000D_
YOU NEED TO USE THE STANDARD NAMES GIVEN IN THIS SECTION so your ADTs_x000D_
can interface with other students’ clients and vice versa._x000D_
_x000D_
The function names in the intVec ADT must be as given in the intVec.h_x000D_
starter file for pa02._x000D_
_x000D_
These names must be spelled and capitalized as shown in that file._x000D_
_x000D_
For this program, loadGraph.c should be a separate file, although that_x000D_
was not required in pa01. loadGraph.h will provide the interface._x000D_
Functions in loadGraph.c that are only called within loadGraph.c should NOT_x000D_
appear in loadGraph.h._x000D_
_x000D_
loadGraph is NOT required to be an ADT, so the functions and prototypes_x000D_
do not need to agree with other students._x000D_
Similarly, dfsTrace1 and dfsTrace2 are not ADTs._x000D_
_x000D_
dfsTrace1 needs to build a finishing-time stack, call it finishStk1._x000D_
Starting with an empty stack at the beginning of dfsTrace1(),_x000D_
simply push v (the vertex whose visit is finishing) on to the stack_x000D_
at its finishing time, as explained in Section 7.5._x000D_
finishStk1 should be implemented as an IntVec with the new constructor_x000D_
intMakeEmptyVecN(). What should the parameter be for this constructor_x000D_
so you never need to do a realloc on it?_x000D_
RE-USED FUNCTION: transposeGraph()_x000D_
_x000D_
Write a function to transpose a graph, after it is built._x000D_
It is the same as pa02, if that was working; specs repeated here_x000D_
in case it was not._x000D_
_x000D_
Make your function as simple as you can to be sure it is correct._x000D_
There is a fast way to do this, but if you do not see it, think of a_x000D_
simpler, possibly slower, way._x000D_
_x000D_
For C the function prototype is_x000D_
_x000D_
IntVec* transposeGraph(IntVec* origGraph, int n);_x000D_
_x000D_
It may be implemented in scc03.c; a separate file is unnecessary._x000D_
_x000D_
The transpose graph has edges in the opposite direction of the_x000D_
original graph, in one-to-one correspondence._x000D_
Suppose the original graph prints like this_x000D_
_x000D_
1 [ 3, 2 ]_x000D_
2 [ 3, 4 ]_x000D_
3 [ ]_x000D_
4 [ 1 ]_x000D_
_x000D_
The transpose graph should have edges (2,1), (3,1), (4,2), (3,2), (1,4),_x000D_
and print accordingly. Most likely it would appear as_x000D_
_x000D_
1 [ 4 ]_x000D_
2 [ 1 ]_x000D_
3 [ 2, 1 ]_x000D_
4 [ 2 ]_x000D_
_x000D_
but other orders are possible._x000D_
See the text for more details. if needed._x000D_
_x000D_
NEW C FILE: dfsPhase2.c_x000D_
_x000D_
dfsPhase2() in dfsPhase2.c will implement phase 2 of the SCC algorithm,_x000D_
and also will compute discoverTime2, finishTime2 for insurance, although_x000D_
the SCC algorithm does not need them._x000D_
_x000D_
After you get dfsTrace1.c working, you should be able to use almost all_x000D_
the code here, with some name modifications._x000D_
_x000D_
Keep in mind that dfsPhase2() uses finishStk1 for dfsSweepT() and_x000D_
operates on the transpose graph. The recursive function is named something_x000D_
like dfsT() or dfsTrace2(). Read the text for details._x000D_
_x000D_
An additional array, dfstRoot2, will be filled to keep track of the_x000D_
separate DFS trees in a second dfs._x000D_
Some function prototypes will be altered to pass this value down_x000D_
from dfsTsweep() through dfsTrace2() calls._x000D_
_x000D_
The purpose of dfstRoot2 is to tell every vertex who is its SCC leader._x000D_
dfsSweepT() passes the number of the root into the recursive function dfsT._x000D_
(Where does dfsSweepT get this number from?)_x000D_
Then dfsT(v, …) puts this number into dfstRoot[v] and passes this number_x000D_
down into its own recursive calls of dfsT()._x000D_
_x000D_
Write dfsTrace1.h and dfsPhase2.h to declare the function prototypes_x000D_
in the respective C files, and state the pre- and post-conditions._x000D_
_x000D_
==========================================================================_x000D_
_x000D_
SUBMITTING_x000D_
_x000D_
The assignment name is pa03. An example (but incomplete) submit command is:_x000D_
_x000D_
submit cmps101-avg.s17 pa03 scc03.c dfsTrace1.c README Makefile_x000D_
_x000D_
Submit ALL the work you want to be considered for grading, but DO NOT SUBMIT_x000D_
files produced by compilers, such as *.o and binaries._x000D_
Also, DO NOT SUBMIT VERY LARGE TEST FILES OR THEIR OUTPUTS._x000D_
_x000D_
You can list as many files as you want to submit. If you update files,_x000D_
just submit them again. Don’t resubmit unchanged files needlessly._x000D_
_x000D_
Simply typing “make” should compile your program, creating a binary_x000D_
named after the main program, scc03._x000D_
To accomplish this, simply list scc03 as the first “target” in Makefile._x000D_
However the testing script will type “make scc03” to be safe._x000D_
_x000D_
Your Makefile should have an entry for each file that needs to be compiled._x000D_
A “generic” that just compiles everything it can find will lose credit._x000D_
The example mentioned in pa01 is a guide. You should understand your_x000D_
own Makefile. If you use fancy features, include comments to explain_x000D_
what they do._x000D_
_x000D_
Submit a README that includes both parts of the certification stated_x000D_
at the beginning of this file, THEN_x000D_
briefly describes your program with a few sentences,_x000D_
mainly to tell the reader how to compile it, how to run it,_x000D_
what test inputs and outputs you supplied, any known bugs._x000D_
Pleading for a nice grade is bad form._x000D_
If the purpose of some files might be mysterious, here is the place to_x000D_
explain them._x000D_
_x000D_
==========================================================================_x000D_
_x000D_
PROGRAMMING STANDARDS_x000D_
_x000D_
All code to be graded should follow good style practices including_x000D_
decomposition into reasonably simple procedures, appropriate indentation,_x000D_
descriptive names, consistent capitalization, and useful comments._x000D_
_x000D_
Comments should indicate the purpose, preconditions,_x000D_
and postconditions of important procedures. Avoid comments of_x000D_
self-explanatory code. The reader may grade your program low_x000D_
if it is sloppily done, making it hard to understand or follow.
RESPECT THE READER’S TIME.
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!Use Discount Code “Newclient” for a 15% Discount!NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.
C programing assignment help – Quality Nursing Writers
"Is this question part of your assignment? We will write the assignment for you. click order now and get up to 40% Discount"
