Computer Science 61A - Spring 2006 - Harvey - Midterm 3 Solutions

Computer Science 61A - Spring 2006 - Harvey - Midterm 3 Solutions

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
http://www-inst.eecs.berkeley.edu/~cs61a/sp06/solutions/mt3 1 of 10 5/11/2006 12:10 AM CS 61A Spring 2006 Midterm 3 solutions 1. Box and pointer. > (let ((x (list 1 2 3))) (set-car! (cdr x) (cddr x)) x) (1 (3) 3) +-------------+ | | | V --------- --|------ --------- | | | | | | | | | /| ---->| | ------>| | ------>| | / | | | | | | : | | | | |/ | --|------ --:------ --|------ | : | V V V 1 2 3 (Some people had correct diagrams but wanted to print (1 3) or (1 3 3). The backbone of this list still has three pairs, so the list still has three elements! And the car of the second pair is a pair, not the number 3.) > (let ((x (list 1 2 3 4))) (set-car! (cddr x) (cons (cadr x) (cdddr x))) x) (1 2 (2 4) 4) ********* * | * 2 <-------- | -----------+ * | * | ********* | ^ | ! | ! V +---+---+ +---+---+ +-!-+---+ +---+---+ | | | | | | | ! | | | | /| x -------> | | | ----->| | | ----->| ! | ----->| | | / | | | | | | | | | | . | | | | |/ | +-|-+---+ +-|-+---+ +-.-+---+ +-|-+---+ | | . | | | . | V V V V 1 2 3 4 [In this problem a new pair is created. In the diagram above, the new pair is the one bordered by asterisks (*). That's because this problem invokes a constructor (CONS) rather than only mutators (SET-CxR!). The car of the new pair points to a number, whereas its cdr points to another pair. A very common error was to make an additional new pair with car 4 and cdr the empty list. But there's only one CONS in this problem, and it only makes one pair.] Scoring: One point for each diagram, one point for each print form. 2. Concurrency
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
http://www-inst.eecs.berkeley.edu/~cs61a/sp06/solutions/mt3 2 of 10 5/11/2006 12:10 AM The crucial point that many people missed is that a serializer only protects against another process that uses the same serializer! Serializers don't magically know what variables you want to protect; all they know is that each serializer should only allow itself to be used by one process at a time. (a) BYE or BYEBYE (b) BYE, BYEBYE, HIHI, HIBYE, or BYEHI To get BYE, first process finishes, then second process runs. To get BYEBYE, second process finishes, then first process runs. To get HIHI, first process reads BAZ twice, then second process runs, then first process sets BAZ. To get HIBYE or BYEHI, the first process reads BAZ once, then the second process runs, then the first process reads BAZ again and sets BAZ. (There are two possible results because Scheme is not guaranteed to evaluate argument subexpressions left-to-right!) Scoring: Subtract 1/2 point for each missing answer, or each incorrect answer added; round down to an integer. 3. OOP short answer. The central point of this question is that in the OOP paradigm, objects are used for everything, and the structure of the object classes reflects the structure of the real-world situation being simulated. (a) parenthood
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 10

Computer Science 61A - Spring 2006 - Harvey - Midterm 3 Solutions

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online