UMBC CMSC202, Computer Science II, Spring 1998,
Sections 0101, 0102, 0103, 0104 and Honors
Project 3 Notes
This page contains notes about Project 3 and will be updated
Project 3 Extension
The deadline for Project 3 has been extended:
- If you submit Project 3 by Friday March 20, you receive a 5% bonus.
- If you submit Project 3 by Wednesday March 25, there won't be
- Project 3 will not be accepted after Wednesday March 25.
- Some common bugs I've seen all day long:
- Forgetting to malloc space for a matrix pointer to point to.
- Forgetting to multiply by sizeof() in the malloc
or realloc argument. That is,
temp = realloc(M->headers[i].row, limit) ;
should really be
temp = realloc(M->headers[i].row, limit * sizeof(entry)) ;
- Forgetting to store the values of temporary variables back
into the sparse matrix data structure:
count = M->headers[i].count ;
/* ... insert a new element into row i ... */
Here count is incremented, but you really want to
increment M->headers[i].count. Similar pitifalls
abound for the row and limit fields as well.
- Remember that the arguments to mergesort are the low and
high indices. So, unless you modified mergesort a lot,
the function call
mergesort(M->headers[i].row, 0, M->headers[i].count) ;
should really be:
mergesort(M->headers[i].row, 0, M->headers[i].count - 1) ;
- Finally, if the debugger says that your program crashed while
calling malloc or realloc, it most likely
means that you failed to allocate the correct amount of space,
or that you overran the end of some dynamically allocated
array sometime prior to the call to malloc or
realloc. These bugs do not have to be near where
the program crashed.
Suppose that you add two matrices A and B where the (2,3) entry of A
is -1.20 and the (2,3) entry of B is 1.20. Then, the (2,3) entry of
A+B is 0.0. You should not have a record in your sparse matrix data
structure for A+B that stores this 0.0 value since the sparse matrix
data structure should not store entries with zero value.
General warning: if you have a pointer ptr that points to a block
of memory and your reallocate this block to size 0 using the call:
realloc() does not return NULL. It returns a valid address to a
block of memory that is zero bytes long. Try the following
program. You might be surprised. The final value of temp is not
NULL. You should be careful with this "feature" when you trim down
the sizes of your dyanmically allocated arrays.
int *ptr, *temp ;
ptr = malloc(16) ;
temp = NULL ;
printf("%p %p\n", temp, ptr) ;
temp = realloc(ptr, 0) ;
printf("%p %p\n", temp, ptr) ;
- Sample input/output and a sample driver program is now available
in the ~chang/pub/cs202/proj3 directory. Read the file called
- You can modify the sorting routines from the class notes.
However, beware that these routines do need modification and that
you may not share the modified versions with other students.
- Important: we will start row and column indices from
0. So, a matrix with 3 rows and 4 columns has rows indexed from
0 through 2 and columns from 0 through 3.
- StoreMatrix(A,"savefile") stores the matrix data
in A to the file named "savefile". StoreMatrix() must use the
same file format as LoadMatrix(). The intention is that you
can use LoadMatrix() to read in a matrix previously saved using
19 Mar 1998 19:54:49 EST
to Spring 1998 CMSC 202 Section Homepage