Solving Graph Problems

As your instructor said in class, there are many situations when you'll have to use your knowledge about graphs to solve real-life problems. The problem described here is one people in certain businesses (road-construction, communications, etc.) face all the time.

A complete description of the problem is included in a memo from your instructor.

What you'll turn in

  1. A well commented listing of your program. Note that grading, as described below, considers both the functionality and the readability of your code. You may also want to have a look at a grading sheet used in the past for a similar assignment. You must follow the coding style and documentation standards used in the Computer Science and Applied Mathematics Department
  2. A floppy disk (3.5") which contains the source file(s) for your program, a DOS executable named assign1 and a README file indicating what the program does, how to build the executable, the platform it's been tested on, and how to run it, plus any other information you consider useful - like the name of the author, etc. Also two input files (use the extension .din for the name), you have used to test your program (with a minimum of four vertices each), and the corresponding output files (with the extension .out).

    Please note that if your program reads input from standard input then it can get input from a file by using input redirection. Similarly, if the program writes to standard output, then the output can be easily written to a file by using output redirection.

  3. A memo describing your work. You will indicate what you have looked for and how you solved the problem. Direct the memo to your class instructor. A hardcopy of the program and a paper which introduces the necessary theoretical background will be attached to the memo. Also attach a hardcopy of your sample input and the output corresponding to it.


  1. A mark between 0 and 10 for functionality. The mark basically indicates in what measure your program works properly and how well you have followed the initial specification.
  2. A mark between 0 and 10 for readability. This mark indicates how well documented your program is; it also considers the general appearance of your final report.
  3. Multiply the above two marks to get the mark for this programming assignment.

For each business day you turn in your project earlier you receive a 5% bonus. However, penalties increase by 5% as well. You can turn in your assignment up to ten business days ahead of the deadline.

  • You turn in your assignment three days earlier: a 3*5=15% bonus will be added to your assignment mark
  • We find a single mistake in the functionality section and the penalty for that mistake is 0.5 points. Since you have turned the assignment three days earlier than the deadline, the penalty becomes 0.5*(1+3*5%)=0.5*(1+3*0.05)=0.575
  • We calculate the mark by multiplying the marks for the functionality and readability; in your case the mark for functionality is 10-0.575=9.425, and the mark for readability is 10. The result is 9.425*10=94.25
  • We add the bonus to this mark: 94.25+94.25*15%=108.38 which we round to 108. This is your final mark.

You may be asked to do a code review with your instructor.

Department of
Computer Science
Applied Mathematics

DATE: September 19, 1998
TO: CS-330 students
FROM: Your instructor
SUBJECT: Project Description

A computer business in Chicago -- they do networking -- has asked me to find a solution to their problem. I pass the problem on to you and I just add some details about input ond output formats.

The problem can be modelled as a graph problem. What you have to do is to write a general program that takes a description of a connected graph from standard input, finds the shortest path between two vertices specified in the command line, and prints the result out to standard output.

Here is a description for the input and the output of your program.


Each line in the input will give the names of two vertices in the graph and the weight of the edge connecting them. For simplicity vertex names are non-negative integers. Weights are non-negative integers as well.

There must be at least two vertices, the graph must be connected and each edge may be listed only once. Your program must enforce these rules.

Here is an example of input for a graph with four vertices:

     0 1  10
     1 2   9
     0 3   8
     2 3  12


There are two output lines: the first contains the names of the vertices in the shortest path, the second is the actual length of the shortest path.

Using the graph described by the sample above, let's assume the program is run as assign1 0 2. Then the output will be:
     Path: (0,1,2)
     Length: 19

Have fun,


(c) 1998, Virgil Bistriceanu Last update: September 19, 1998 The cs330 home page