CS 241 Frequently Asked Questions (FAQs)


Lab 4 Related Questions:

I'm not sure if I am using the provided minutesSince method correctly.

To help illustrate how it is used. To compute the length of a flight you should be using:
     arrivalTime.minutesSince(departureTime)
So t1.minutesSince(t2) is the minutes from the time when t2 occured until when t1 occurs. So you can think of it as t1-t2.

When using the provided code to read in the flight data, I get a java.util.NoSuchElementException. How do I fix this?

This is being caused by an empty line at the end of flight-data.txt. The easiest solution is to remove that blank line. A more robust solution is to replace
   if (nextline == null)
      stop = true;
by
   if (nextline == null || nextline.trim().equals(""))
      stop = true;
The flight data has 1200 N for noon, versus 1200 P. Is this a problem?

A student pointed this out. If you use the provided code for reading the data, it has a boolean am which will treat anything other that "A" as a "P" and so the "N" will be handled correctly since noon is 12:00pm. However, feel free to modify the provided code fragements or the flight data file if you would like.

I'm trying to use heapify to fix the problem in the binary heap caused by decreasing a key, but there seems to be a problem?

Remember that Heapfiy is not a magic "fix-all" method for the binary heap. If you call heapify(i), this fixes the binary heap if the only violation for the binary heap property is that A[i] might be in violation (e.g. bigger when the min is in A[0]) with one of its children. Heapify does not resolve any other problems.

Should minimumKey, the method that just returns the value of the minimum key, run in O(1) time? It wasn't included on the list of methods we were told should run in O(1) time.

Yes! It was just inadvertantly left off the list. Also, while this should be clear, the toString method must run in O(n) time. The methods insert, decreseKey, and extractMin should run in O(log n) time.

Should I use an arraylist for the array used for storing the references to the binary heap objects?

No, you would get a more efficient solution by using an array. You know how bit the array needs to be and so there is no advantage of using an array list, and the array list has extra overhead associated with it that the array does not have.


Lab 2 Related Questions:

I get compiler errors when trying to compile the provided code without changing anything. What is wrong?

The provided code was not intended to compile without first filling in the missing methods. None of the methods return anything but most of them should and so this will cause compiler errors. For those using C++, it also assumes that you have an instance variable tableSize which holds the size of the hash table, and you need to provide the DictionaryRecord class. I've put a very basic one in DictionaryRecord.h for you. You'll need to add this to the first line of the lines that create the object (.o) files in the makefile for everything put SeqReader.o. If there are questions just let me know.

How can we check our output from Lab2PutTester?

The value of baseHash and stepHash are provided with the lab. You should be able to hand simulate exactly where the probes are made and where the items are placed. Now check you output to be sure it matches and if it doesn't and you don't fix it, then let us know where the output is wrong. (For those using C++, for "dragon", only "dra" is used as the key and for it both baseHash and stepHash is 1.)

Which C++ compiler should be used?

Use pkgadd gnu.


Lab 1 Related Questions:

I'm using C++ and the distance between the closest pair is zero even when n is small since there are two identical points. Should that be happening?

Please load a new copy of lab1.cc from the web page. You can directly save that one page or get a new copy of everything and unzip it (but be careful to do this in a different directory so you don't lose any changes you made to the other files). The problem was caused by the fact that the abs and mod functions both returned integers versus doubles. The solution used was just to compute these functions directly. Note that none of your code will need to be changed because of this -- It will just generate more interesting data sets. Finally, I added a sample protytpe for the brute force and divide and conquer closest pair algorithms. You can replace those by whatever prototype you need.

In C++ how can I overload "<<" to output a PointPair?
Both pointpair.h and pointpair.cc have been updated to include this. You can either get a new copy of the zip file and unzip it (but be careful to do this in a different directory so you don't lose any changes made). Or you can just save those two files from the webpage. If you are already using the original version of the PointPair class and don't want the version with "<<" overloaded that is fine. You can use either version.

I'm getting errors when trying to compile the provided C++ code (using "make"). What should I do?
Instead of using "pkgadd gnu" as it said in the lab, instead use "pkgadd sc_4.0". It should then give the following:
CC -g +w -c lab1.cc
CC -g +w -c closest-pair.cc
"closest-pair.cc", line 14: Warning: n is defined but not used.
"closest-pair.cc", line 14: Warning: Y is defined but not used.
2 Warning(s) detected.
CC -g +w -c sort.cc
CC -g +w -c point.cc
CC -g +w -c pointpair.cc
CC -g +w -c Profile_Timer.cc
CC -g +w -o lab1.out point.o pointpair.o sort.o closest-pair.o\
                 Profile_Timer.o lab1.o 
The warnings will go away when your divide-and-conquer algorithm is put in place since it will use n (the number of points) and Y (the name used for pointsByY).


Return to the CS 241 Home Page