CS200: Computer Science, Spring 2003

Final: Auction Bots  Comments
Question 1: How much work is findelementnumber? Express your answer using Θ notation. Be sure to clear explain what any variables (e.g., n) you use in your answer mean.Answer: Θ (n) where n is the number of elements in the input list.Question 2: Is the find element problem decidable or undecidable? Argue convincingly to support your answer.findelementnumber will cdr down the whole list, looking at each element one at a time. On average, the element to be found will be in the middle of the list (or not in the list at all). So, if the length of the list doubles, the amount of work would double.
Decidable.Question 3: How complex is the find element problem? Provide and justify both an upper (O) and lower (Ω) bound.Since the findelementnumber procedure provided for question 1 solves the find element problem, to show it is decidable all we need to do is argue that we have procedure that solves it that always terminates. We know findelementnumber will always terminate, since every time it is called it either stops because the list is null (or because it has found the element), or it calls findelementnumber recursively with the cdr of the list. Since (cdr lst) is always one shorter than lst, we know the size of the input list will decrease by one for each recursive call. It must eventually reach zero. When it does, the list is null and the evaluation will terminate.
We use n to represent the length of the input list. We know the problem is O(n) from question 1 — since we have a procedure that solves the find element problem that is Θ(n) we know we can to at least that well, and the upper bound is O (n).Question 4: How much work is the gethighestbid procedure? Express your answer using Θ notation. Be sure to clear explain what any variables (e.g., n) you use in your answer mean.We need to look at every element in the input list, though, since if we stop before looking at every input we may miss the matching element. Hence, it is also Ω (n). Note that the lower bound is different from the best case execution time. In the best case, the first element matches the one we are looking for and we do not need to look beyond it (hence, we can solve the problem in the best case with Θ(1) work). But, for a lower bound we need to know how much work the best possible procedure will require for a typical input.
Since we know the problem is O (n) and Ω (n), we also have a tight bound Θ (n).
Answer: Θ (b log _{2} b) where b is the number of bids.Question 5: How much work is Effy's gethighestbid procedure? Express your answer using Θ notation. Be sure to clear explain what any variables (e.g., n) you use in your answer mean.The procedure uses quicksort to sort the bids:
(quicksort (lambda (entry1 entry2) (> (bidamount entry1) (bidamount entry2))) (getbids item))))The (getbids item) evaluation uses tableselect to find the number of bids for the item. This involves going through each bid in the bids table. The amount of work for each bid is constant — it depends only on the number of fields in the table (a constant). So, it involves &Theta(b) work, and evaluates to a list that contains at most b elements.Evaluating the quicksort application will evaluate the passed procedure n log _{2} n times where n is the length of the input list to quicksort. The length of the list is at most b, the total number of bids. The amount of work to evaluate the procedure is constant. Even though bidamount uses findelementnumber which is Θ(n), the important thing to recognize is that the n here is a constant (the number of fields in the table); it does not increase with the input size, so the amount of work is constant. Hence, the total work is Θ(b) for the (getbids item) evaluation plus Θ(b log_{2} b) for the quicksort application evaluation. Since b log_{2} b grows faster than b, we can simplify this to Θ(b log_{2} b).
Answer: Θ (b) where b is the number of bids.Question 6: Define the resetbidbots! procedure. It takes an item as its parameter and sets the bid value of every bidbot for that item to #f.This procedure is faster since it does not sort the bids, but just looks down the list at each bid in turn to find the highest bid.
Question 7: Define the reevaluatebidbots procedure. It takes an item and the new highest bid for that item as parameters. It reevaluates all the bidbots for that item with the new highest bid. If a bidbot produces a new higher bid, it should print out the new bid, reset all the other bidbots and then reevaluate all the bidbots with the new higher bid. Your reevaluatebidbots procedure should keep giving bidbots a chance to bid until every bidbot has had a chance to bid with the new highest value.(define (resetbidbots! item) (map (lambda (bid) (if (bidbot? bid) (setcar! bid #f))) (getbidvalues item)))Question 8: Is the settle auction problem decidable? Provide a very convincing argument to support your answer.(define (reevaluatebidbots item highbidvalue) (define (reevaluatehelper bids item highbidvalue) (if (null? bids) (void) (let ((bid (bidbid (car bids)))) (if (bidbot? bid) (if (not (bidbotamount bid)) (let ((newbid ((bidbotproc bid) highbidvalue))) (if newbid (begin (resetbidbots! item) (setcar! bid newbid) (printf "New automated high bid for ~a from ~a: ~a~n" item (bidbidder (car bids)) newbid) (reevaluatebidbots item newbid)) (reevaluatehelper (cdr bids) item highbidvalue))) (reevaluatehelper (cdr bids) item highbidvalue)) (reevaluatehelper (cdr bids) item highbidvalue))))) (reevaluatehelper (getbids item) item highbidvalue))This question was designed to be tough enough that anyone who got close to a correct procedure deserved (and received) an A in the course.No, the settle auction problem is undecidable.If the bidbots can be any procedure (as stated in the question), it is easy to reduce the halting problem to the settle auction problem:
(define (halts? P I) (> 0 (settleauction (list (lambda (x) (if (< x 1) (begin (P I) 1) #f))))))If (P I) halts the bidbot will bid 1 the first time it gets a change to bid (starting from 0), and the auction will end with high bid 1.Its harder to see (and not necessary for this question) that even if bidbots must be simple procedures that do not use anything that could not terminate, that the settle auction problem is still undecidable. We can convert any input program into a set of bidbots that calculate the same thing by dividing the code among bidbots that are themselves simple (terminating) procedures, and relying on the auction procedure to provide the looping behavior.
Question 9: (Optional, no credit) Do you feel your performance on this exam will fairly reflect your understanding of the course material? If not, explain why.
Several students said they thought the exam was unfair because it only covered a small subset of the material, focusing on measuring work and defining procedures. It is certainly true that this exam didn't attempt to cover the whole course. It wasn't meant to be comprehensive, since you had recently taken Exam 2 (which was fairly comprehensive), but rather to give students an opportunity to convince me they understand the most important things that caused the most trouble on Exam 2. To make the exam short, this meant the questions were designed to be hard enough so that if you could answer them well it was convincing evidence that you deserved a good grade in the course. I think some students found this overly traumatizing because I didn't make it clear that that was the point of the final, but I believe a short, hard final is a better use of your time than a long, comprehensive one.

cs200staff@cs.virginia.edu Using these Materials 