University of Toronto - Fall 1996
Department of Computer Science

CSC 148H: INTRODUCTION TO COMPUTER SCIENCE



Old Announcements -- Week 11



Saturday 23 November: Assignment 3 -- miscellaneous Q&A

Question: Could you perhaps give me a hint as to where to start looking for this bug? I can't seem to find it. I thought that ... may be the cause but I look at that and tinkered with it and no luck.
Answer: I don't plan to give hints on this. The point is for you to hone your debugging skills by tackling a real bug. (And by the way, this is indeed a real bug. It occurred naturally. We know how to fix it, but we thought it would be an excellent, and very real, exercise for you.) You mentioned tinkering. Be sure that it's not a random process -- you can't debug code by random tinkering. Being systematic is the key.

Question: In part 1 of Assignment 3, do we have to free up the memory for procedure ?
Answer: For correctness, not necessarily. For efficiency, definitely.

Question: For procedure printSet, should the output be a sideway tree diagram, as in the one in Assign 3a?
Answer: Do you think that that is an appropriate sort of output? Think about it.

Question: I've a simple question about recursion and part 1 of assignment 3. I'm reluctant to use recursion when implementing the addElement procedure in the revised Set class. My algorithm uses a loop statement to descend the tree. The algorithm is fairly straightforward and simple. My thinking is that recursion may be too sophisticated to do something simple like moving to a leaf node. My question: Are we required to use recursion in all revised subprograms in the Set class?
Answer: You do not have to use recursion in all the subprograms. You are right that there are some which can be nicely handled with just loops. I wouldn't say, though, that recursion is too sophisticated to use in these cases.

Question: Are we going to be graded on the amount of time we took on each section, or is that only for statistical use? (i.e. if it ends up taking me 120 hours to fix the bug, will that count against me?)
Answer: The hours that you report are just for our information -- it will help us in planning future assignments. This will have no effect on your mark.

Question: Instead of using two layers for recursion, could we not have a global variable within the class to point to the current and/or the next leaf. i.e. the global variable would would point to a different leaf for every time the function calls itself
Answer: It's possible to make this work, but it would be really bad style. To get the hang of recursion, make sure that the parameters convey everything that must be known about the data to be processed (in this case, the tree).



Saturday 23 November: Assignment 3 -- functions as parameters

Question: In assignment #3, part 1 (changing the implementation of the set class): I'm not sure how to handle subprograms that use other subprograms as their parameters. For instance :
procedure recSubset (r : ^treeNode, function f (e : elementType) : boolean,
                     var buildingSet : ^Set)
I'm not sure I even know where function f is, so I don't know what to do with it here.
Answer: Function f isn't defined anywhere -- it's just the name of a formal parameter to recSubset. This is no different than buildingSet. You don't see a variable of that name defined anywhere except here in the header to the function. Both f and buildingSet will receive actual values when recSubset is called. There is indeed something special about f, however. You've probably never seen functions passed as parameters before. Here's how it works in this example.

Function Subset (and also recSubset, which it calls) is going to produce a subset of the present set and return it to you. (By the "present set", I mean whatever set is currently stored in the instance variables for this instance of the Set class.) But it needs some criterion for deciding which elements of the present set to include in the subset it's creating. You could use an if-statement to express some specific criterion, e.g., include only StreetObjects whose colour is not blue, but then your Subset function would be very specific. If you wanted to create a subset using some other criterion, you'd have to write another subset function.

The alternative used here is to not code in a fixed criterion. Instead ask the caller to name a function that expresses whatever criterion they want used. In the formal parameters to Subset and recSubset, we use a very generic name, f, because we have no idea what sort of function will be passed in. All we know is that it must take something of type elementType and return a boolean answer, which we'll use to decide whether or not to include the element in the new subset.

For an example of how to call Subset and pass in a specific function, see the sample testing driver that I posted to the course web site on Thursday. In that case, the function is called `odd', and it says yes to odd-valued SimpleObjects only.



Thursday 21 November: Assignment 2 -- promised code, plus testing advice

The 3 subprograms we promised to provide for your revised Set class (removeElement, Subset, and GetRandomElement) are now available. Along with them, is some better advice about testing your Set class, and a sample driver program. Click here or go to the tests and assignments page.


Thursday 21 November: Interested in a degree in CSC?

On Monday, November 25, 3:10 p.m., there will be an information session on "how to apply for admission to a CSC program". The session will be held in the Galbraith Building (which is attached to Sandford Fleming), in room 221.

Attendance is not compulsory; this is simply intended to be helpful.



Thursday 21 November: Assignment 2 -- Testing your revised Set class

My suggestion about changing elementType to int is a little simplistic. It would make testing easy, but then when you change elementType back to be ^StreetObject, your class will not work. This is because things you do to elements of your set cannot be done the same way on things of type int as on things of type ^StreetObject. For example, Set's printSet procedure must have code for printing individual elements of the set. You can print an int with a simple put statement, but you can't print a StreetObject that way. And you can print a StreetObject using its drawSelf method, but you can't print an int this way.

I'm working out another suggestion for doing your testing, and will post it on the web page.



Wednesday 20 October: Assignment 3 -- how to recurse???

Question: I was just looking at the newset.tu for a3 and I started to wonder how you were going to be able to move through the set without passing a pointer into the function. I then thought that maybe the functions that are already given were just going to be used to call recursive functions that would then move through the set to do what you wanted. Is this wrong? Ex. isMember would call isMemberR which would search through the set recursivly and return true iff the element was in the set to isMember, then isMember would return the same result outside.
Answer: That's exactly the idea. :-)

You may wonder why have two layers -- why not just export the recursive routine that includes the extra parameter? One reason is that the caller, being outside the class, doesn't have access to the root pointer, and so wouldn't be able to make the initial call.



Wednesday 20 November: Problem with your mark on Test 2 or Assignment 2?

If you disagree with or are confused about your mark on Test 2 or A2, click here to find out what you should do. You must address any concerns regarding these marks by Friday 29 November.

Monday 18 November: Part 1 starter code ready

The code mentioned below is now out of date. See the later announcement (Thursday 21 November) for the latest version.

The starter code for your revised set module is now ready. Click here or get it through the Assignments and Tests page.

Note that I have indicated the subprograms for which we'll provide bodies, but haven't provided the bodies yet. You can proceed with the assignment and then paste those bodies in when they're available.


Back to the csc148 home page