ECE36800 Programming Assignment 3: Due Saturday, December 11, 2021, 11:59pm
ECE36800 Programming Assignment 3: Due Saturday, December 11, 2021, 11:59pm
This assignment covers learning objective 4: An ability to apply graph theoretic techniques, data struc-
tures, and algorithms for problem solving; learning objective 5: An ability to design and implement appro-
priate data structures and algorithms for engineering applications.
Grid traversal
This programming assignment is to be completed on your own. You will implement a program that
involves finding a fastest way to travel from a location at the top of a grid and exit at a location at the bottom
of the grid. Consider the following 4×5 (or 4-rows-by-5-rows) grid:
4 2 1 0 5
2 0 4 1 0
4 2 2 2 7
1 7 2 9 2
We label the rows from top to bottom 0 to 3 and the columns from left to right 0 to 4. Let the coordinates
of location i be (ri , ci ), where ri is the index of the row that i is in, and ci is the index of the column that i is
in. The highlighted (2, 1)-location of the grid, for example, stores the a non-negative value of 2 (stored as
short).
The value at a location corresponds to the amount of time a visitor has to spend there once the visitor
enters that location. After spending that amount of time at that location, the visitor moves to one of its
adjacent locations. If a visitor enters the (2, 1)-location at time t, the earliest the visitor can leave that
location and enter a location adjacent to (2, 1) is at time t + 2.
If a visitor enters the (1, 1)-location, which stores the value 0, at time t, the visitor can immediately exit
that location and enter a location adjacent to (1, 1) at time t.
Two locations, i of coordinates (ri , ci ) and j of coordinates (r j , c j ), are adjacent if r j = ri − 1 ( j is above
i), r j = ri + 1 ( j is below i), c j = ci + 1 ( j is to the right of i), or c j = ci − 1 ( j is to the left of i). For the
(2, 1)-location, the adjacent neighbor above it is the (1, 1)-location, the adjacent neighbor below it is the
(3, 1)-location, the adjacent neighbor to its right is the (2, 2)-location, and the adjacent neighbor to its left is
the (2, 0)-location. For the boundary locations in the grid, they do not have four adjacent neighbors. They
have only two adjacent neighbors (for the corner entries) or three adjacent neighbors (for the non-corner
boundary entries).
For the given 4 × 5 grid, a visitor must enter the grid at one of the (0, i)-locations, 0 ≤ i ≤ 4. It must exit
the grid at one of the (3, j)-locations, 0 ≤ j ≤ 4.
Suppose a visitor enters the grid at the (0, 0)-location at time 0, the values stored in the following table
show the respective earliest times when the visitor could enter the corresponding locations in the given grid:
0 4 6 7 7
4 6 6 7 8
6 6 8 8 8
10 8 10 10 15
For the entrance at the (0, 0)-location at time 0, the highlighted path of (0, 0) → (1, 0) → (2, 0) → (3, 0)
allows the visitor to exit the grid at the (3, 0)-location the earliest in 11 time units. The visitor arrives at
the (3, 0)-location the earliest in 10 time units, as shown in the preceding table, spends 1 unit of time there
before exiting. This path contains 4 locations in the grid.
Deliverables
In this assignment, you are required to develop include file(s) and source file(s) that can be compiled
with the following command:
gcc -std=c99 -pedantic -Wvla -Wall -Wshadow -O3 *.c -o pa3
It is recommended that while you are developing your program, you use the “-g” flag instead of the
“-O3” flag for compilation so that you can use a debugger if necessary.
The executable pa3 should be run as follows:
The file 4 5.t should store the 2-dimensional grid in text form. The file 4 5.f should store the fastest
times to exit the grid for all entry locations in binary form. The file 4 5.p should store the fastest path in
binary form. These files are also provided to you for this assignment.
Electronic Submission
The project requires the submission (electronically) of the C-code (source and include files) through
Brightspace. You should create and submit a zip file called pa3.zip, which contains the .h and .c files.
Your zip file should not contain a folder.
If the zip file that you submit contains a Makefile, we use that file to make your executable (by typing
“make pa3” at the command line to create the executable called pa3).
Additional information
You may want to write a program that allows you to convert from a text grid file into a binary grid file.
This allows you to easily create other examples to test your programs. Similarly, you may want to create
programs to convert from a binary fastest times file (or binary path file) to a text fastest times file (or text
path file) for testing.