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

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

View Full Document Right Arrow Icon
M IDTERM E XAMINATION 2 C OMPUTER S CIENCE 61A Department of Electrical Engineering and Computer Sciences University of California, Berkeley July 29, 2010 Instructions (Read Me!) You will be given 180 minutes to complete this exam. This exam is closed book. Collaboration is not permitted. You may not use or access, or cause to be used or accessed, any reference in print or electronic form at any time during the exam, except two double-sided 8.5” × 11” sheets of handwritten notes having no ap- pendage. Computing, communication, and other electronic devices (except dedicated time- keepers) must be turned off. Noncompliance with these or other instructions from the teach- ing staff—including, for example, commencing work prematurely or continuing beyond the announced stop time—is a serious violation of the Code of Student Conduct. This booklet contains 8 (eight) substantive questions, spanning pages numbered 1 through 15 including the cover page. If you find a defect in your copy, notify the staff immediately. You will also be given a list of commonly used procedures that you may find useful. Put all answers on these pages; don’t hand in any stray pieces of paper. Scratch paper will be provided to you; ask for more if you run out. You may not use your own scratch paper. Please write neatly and legibly, because if we can’t read it, we can’t grade it . If you find one question difficult, leave it for later; start with the ones you find easier. There may be partial credit for incomplete answers; write as much of the solution as you can. When writing procedures, don’t put in error checks. Assume that you will be given arguments of the correct type. Don’t panic! Breathe deeply: this exam is not worth having a heart attack about. We hope you do a great job on this exam. ¨ ^ 1
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 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
Image of page 3

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

View Full Document Right Arrow Icon
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 .
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern