UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

Similar documents
UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger and Josh Hug

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger. Test #1 (corrected)

CS61B, Fall 2015 Final Examination (with corrections) P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

CS61B, Spring 2006 Final Examination P. N. Hilfinger

CS61B, Fall 2007 Final Examination P. N. Hilfinger

CS61B, Fall 2011 Final Examination (corrected) P. N. Hilfinger

CS61B, Fall 2009 Final Examination (revised) P. N. Hilfinger

UNIVERSITY OF CALIFORNIA

DO NOT. package java.lang; public final class String implements Serializable, Comparable, CharSequence {

UNIVERSITY REGULATIONS

CS61B, Summer 2002 Exam #1 Barath Raghavan

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.

CS171 Midterm Exam. October 29, Name:

UNIVERSITY REGULATIONS

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

CS 101 Fall 2006 Midterm 3 Name: ID:

I have neither given nor received any assistance in the taking of this exam.

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

You must include this cover sheet. Either type up the assignment using theory3.tex, or print out this PDF.

CIS Fall Data Structures Midterm exam 10/16/2012

Test #2. Login: 2 PROBLEM 1 : (Balance (6points)) Insert the following elements into an AVL tree. Make sure you show the tree before and after each ro

CSE wi: Practice Midterm

Cornell University Computer Science 211 Second Preliminary Examination 18 April 2006

Midterm II Exam Principles of Imperative Computation Frank Pfenning. March 31, 2011

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

CSE373 Fall 2013, Midterm Examination October 18, 2013

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

I have neither given nor received any assistance in the taking of this exam.

Exam I Principles of Imperative Computation, Summer 2011 William Lovas. May 27, 2011

Section 03: Asymptotic Analysis

Midterm 1 Review Document

CSE413 Midterm. Question Max Points Total 100

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)

1 out of 3 points. 2 out of 3 points. 3 out of 8 points. 4 out of 6 points. 5 out of 5 points. 6 out of 6 points. Total. Birthday: Month: Day:

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

ESC101 : Fundamental of Computing

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

CS 2505 Computer Organization I

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. Fall 2016.

Computer Science 62. Midterm Examination

CS 112 Midterm Exam Fall 2016

Final: CSS 342 SAMPLE. Data Structures, Algorithms, and Discrete Mathematics I

Nested Loops. A loop can be nested inside another loop.

Exercise 7 Bytecode Verification self-study exercise sheet

CSE 131 Introduction to Computer Science Fall Final Exam

DUKE UNIVERSITY Department of Computer Science. Test 1: CompSci 100

CSE331 Winter 2014, Midterm Examination February 12, 2014

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

6. Asymptotics: The Big-O and Other Notations

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

DO NOT REPRODUCE. CS61B, Fall 2008 Test #3 (revised) P. N. Hilfinger

CIS 120 Midterm II November 8, Name (printed): Pennkey (login id):

Final CSE 131B Spring 2004

Last Name: Circle One: OCW Non-OCW

CSE 131 Introduction to Computer Science Fall Exam II

CSE 241 Algorithms and Data Structures Fall Semester, Midterm Exam

Collections, Maps and Generics

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 10: Asymptotic Complexity and

CS 101 Spring 2007 Midterm 2 Name: ID:

Before exam: [! ]. After exam: [! ]. UC Berkeley Computer Science CS61B: Data Structures. Midterm #1, Spring 2015

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

Final Exam. COMP Summer I June 26, points

Test #1. Login: Initials: 2 PROBLEM 1 : (The Sorted Link (12 points)) Using the following definition of a linked list node, write a function that inse

I have neither given nor received any assistance in the taking of this exam.

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

1 Method Signatures and Overloading (3 minutes, 2 points)

Midterm Exam CS 251, Intermediate Programming October 8, 2014

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

CS 61B, Midterm #3 and solutions, Spring 1996

CSE373 Midterm I Fall 2009 (Closed book, closed notes)

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Java Review: Objects

Midterm I Exam Principles of Imperative Computation André Platzer Ananda Gunawardena. February 23, Name: Andrew ID: Section:

Administrivia. Last modified: Fri Aug 25 10:59: CS61B: Lecture #2 1

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Read and fill in this page now

ENGI 1020 Introduction to Computer Programming J U L Y 5, R E Z A S H A H I D I

CS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2010

Practice Midterm Exam Solutions

Read and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:

DO NOT. In the following, long chains of states with a single child are condensed into an edge showing all the letters along the way.

CSE351 Winter 2016, Final Examination March 16, 2016

CS 116 Week 8 Page 1

CS61B Lecture #24. Today: Java support for generic programming. Readings for today: A Java Reference, Chapter 10.

Use the Scantron sheets to write your answer. Make sure to write your Purdue ID (NOT Purdue Login ID) and your name on the Scantron answer sheet.

Midterm I Exam Principles of Imperative Computation André Platzer Ananda Gunawardena. February 23, 2012

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3

Sample Examination Paper Programming and Software Development

Transcription:

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS61B Fall 2007 P. N. Hilfinger Midterm Test READ THIS PAGE FIRST. Please do not discuss this exam with people who haven t taken it. Your exam should contain 5 problems on 10 pages. Officially, it is worth 40 points (out of a total of 200). This is an open-book test. You have two hours to complete it. You may consult any books, notes, or other inanimate objects available to you. You may use any program text supplied in lectures, problem sets, or solutions. Please write your answers in the spaces provided in the test. Make sure to put your name, login, and lab section in the space provided below. Put your login and initials clearly on each page of this test and on any additional sheets of paper you use for your answers. Be warned: my tests are known to cause panic. Fortunately, this reputation is entirely unjustified. Just read all the questions carefully to begin with, and first try to answer those parts about which you feel most confident. Do not be alarmed if some of the answers are obvious. Should you feel an attack of anxiety coming on, feel free to jump up and run around the outside of the building once or twice. Your name: Login: 1. /10 Login of person to your Left: Right: 2. /10 3. /10 Discussion section number or time: 4. / Discussion TA: 5. /10 Lab section number or time: TOT /40 Lab TA: 1

Midterm Test Login: Initials: 2 1. [10 points] a. How can you check to see if a number is less than 0 using only == and the bit operators (&,, ^, ~, <<, >>,>>>)? b. The following program compiles correctly. What does the main program (in D) print? class A { int z = 2; void f () { this.g (); void g () { System.out.printf ("A:%d%n", z); int h () { return z; class B extends A { int z = 15; void g () { System.out.printf ("h:%d z:%d%n", h(), z); class C extends A { int z = 42; void f () { this.g (); class D { public static void main (String[] args) { A c1 = new C(); C c2 = new C(); A b1 = new B(); B b2 = new B(); c1.f (); c2.f (); b1.f (); b2.f ();

Midterm Test Login: Initials: 3 c. Succinctly describe the result of calling the following function: int p (int x) { int n; n = 0; while (x!= 0) { n = n ^ x; x = x >>> 1; return n & 1; d. In the function for part (c) above, how would the result differ if we replaced >>> with >>? e. What is the result of compiling and executing the following? Briefly explain your answer. abstract class A { abstract void f (); class B { void f () { printf ("Hello, world!"); public class Main { public static void main (String[] args) { Object b = new B(); g ((A) b); static void g (A x) { x.f ();

Midterm Test Login: Initials: 4 2. [10 points] Provide simple and tight asymptotic bounds for each of the following. Here, simple means roughly no unnecessary terms or constants and tight means either the largest Ω( ) and smallest O( ) bounds you can find or, if possible, a Θ( ) bound. a. 9x 2 + 3x + 14 logx b. N i j i=0 j=0 c. The running time, as a function of N, for foo(n), for foo declared. (I m asking for running time here, not worst-case time. So we re asking for upper and lower bounds on how long the program will run with input N.) void foo(int N){ int x; for(x = 0; x < N; x += 1) { int y; for (y = 0; y < x; y += 1) { bar(x,y); // bar runs in constant time More parts on the next page.

Midterm Test Login: Initials: 5 d. The running time, as some function of low and high, for search, declared below. That is, define a suitable function s(low, high), and then give a bound for C search (N), in terms of N, where N = s(low, high). (E.g., Cost of search(n) = O(N 2 ), where N = lg(high + low) ). (Again, I m asking for upper and lower bounds on the time, not just a bound on the worstcase time). bool search (int A[], int value, int low, int high) { if(high < low) return false; int mid = (low + high) / 2; if (A[mid] > value) return search(a, value, low, mid - 1); else if (A[mid] < value) return search(a, value, mid + 1, high); return true; e. The running time (not just worst-case), as a function of n, for G(n), for G declared void G(int n) { if (n == 1) return; for(int i = 0; i < n; i += 1) G(n-1);

Midterm Test Login: Initials: 6 3. [1 point] What is an example of preadaptation? 4. [10 points] Using the following class definitions: class IntList { // final means head can t be changed after the constructor // sets it. public final int head; public IntList tail; public IntList (int head, IntList tail) { this.head = head; this.tail = tail; class IntList2 { public final IntList head; public IntList2 tail; public IntList2 (IntList head, IntList2 tail) { this.head = head; this.tail = tail; fill in the methods below and on the next page to agree with their comments. Define any additional methods you d like. HINT: don t try to make things efficient. You ll probably find it easier to create one list at a time. /* a. */ /** Slice the list L into a list of N lists such that list #k contains * all the items in L that are equal to k modulo N, in their original * order. For example, if N is 3 and L contains [9, 2, 7, 12, 8, 1, 6], * then the result is [ [9, 12, 6], [7, 1], [2, 8] ]. The operation * is destructive (it may destroy the original list) and creates no new * IntList objects (it will, of course, create new IntList2 objects). */ static IntList2 dslice (IntList L, int N) { // FILL THIS IN Continues on next page.

Midterm Test Login: Initials: 7 /* b. */ /** A list of N lists such that list #k contains all the items in L * that are equal to k modulo N, in their original order. For * example, if N is 3 and L contains [9, 2, 7, 12, 8, 1, 6], * then the result is [ [9, 12, 6], [7, 1], [2, 8] ]. The operation * is nondestructive (the original contents of L are not changed). */ static IntList2 slice (IntList L, int N) { // FILL THIS IN // ADDITIONAL METHODS MAY GO HERE.

Midterm Test Login: Initials: 8 5. The class FilteredList represents a read-only view of a List that selects only certain of its members. In this problem, you are to fill in part of its implementation. For example, if L is any kind of object that implements List<String> (that is, the standard java.util.list), then writing List<String> FL = new FilteredList<String> (L, filter); gives a list containing all items, x, in L for which filter.test (x) is true. Here, filter is of type Predicate: interface Predicate<T> { boolean test (T x); (Don t worry about that Predicate<T>, even though we haven t talked about it explicitly. It just means For any type, T,.... ) The object pointed to by FL above is supposed to be a view of L; when L changes, so does FL (since FL is a read-only view, we aren t going to worry about the other direction). a. Fill in the indicated places below to achieve this effect. Do this from scratch. That is, do not use the standard AbstractList or AbstractSequentialList classes. public class FilteredList<T> { // Put private instance variables here. public FilteredList (List<T> L, Predicate<T> filter) { // FILL IN public int size () { // FILL IN public T get (int k) { // FILL IN continues on next page

Midterm Test Login: Initials: 9 public Iterator<T> iterator () { return // Put additional methods and nested classes here. Continues on next page.

Midterm Test Login: Initials: 10 b. Here is a second formulation of the slice problem from above. Fill it in, using the FilteredList abstraction from part (a) above. We suggest that the returned value be an ArrayList<List<Integer>>. /** A list of N lists such that list #k contains all the items in L * that are equal to k modulo N, in their original order. For * example, if N is 3 and L contains [9, 2, 7, 12, 8, 1, 6], * then the result is [ [9, 12, 6], [7, 1], [2, 8] ]. The operation * is nondestructive (the original contents of L are not changed). */ static List<List<Integer>> slice (List<Integer> L, int N) { // FILL THIS IN // Put any other methods and classes you need here.