# mt2 - M IDTERM E XAMINATION C OMPUTER S CIENCE 61A...

This preview shows pages 1–5. Sign up to view the full content.

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

View Full Document
L OGIN : cs61a- Scores Q UESTION S CORE T OTAL P OINTS 1 2 2 2 3 2 4 4 5 4 6 2 7 3 8 6 Bonus 0 TOTAL 25 2
L OGIN : cs61a- 1 Box and Pointers What will the Scheme interpreter print in response to the last expression in the following sequence of expressions? Also, draw a box and pointer diagram for the final result for this sequence of expressions. If any expression results in an error, circle the expression that gives the error message and just write error ; you don’t have to give the precise message. Hint : It’ll be a lot easier if you draw the box and pointer diagram first! (define a (list (list 1) 2)) (define b (list 3 4)) (define c (append a b)) (set! b (list 4 6)) (set-cdr! a 5) (set-car! a 7) (set-car! b 6) c For reference, append is defined below: (define (append ls1 ls2) (if (null? ls1) ls2 (cons (car ls1) (append (cdr ls1) ls2)))) What does STk print? Draw the box and pointer diagram below: 3

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

View Full Document
L OGIN : cs61a- 2 Vector Shuffling There are many different ways of shuffling a given set of data. For this problem, we will ex- plore a basic but probabilistically random shuffle called the Knuth shuffle. Write a procedure knuth-shuffle! that, given a vector of length n , will shuffle the elements in the vector using the following rules: 1. Initialize a variable, i , to 0 .
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern