DOC PREVIEW
Berkeley COMPSCI 61B - Data Structures – Midterm Exam

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CompSci-61B, Data Structures – Midterm ExamCompSci-61B Midterm Exam, page 1Your Name: ___________________________Your 8-digit Student ID: ___________________________This is a midterm test for mastery of the material covered in our labs, lectures, and readings from introduction to Javathrough sorting. It is worth 100 points. Circle the correct answer for the multiple-choice questions, and write in the space provided for the essay questions. This exam is open book and open note. This exam consists of 28 questions: 16 worth 2points each, 10 worth 4 points each, an 8-pointer, and a 20-pointer. Partial credit is possible.1. If the integer a has a value of 11, and is declared as an int, what is the exact numeric result of this Java expression:( a / 3 ) ? [2 points]_____________________________________________________________________________________2. Write the logical opposite of this logical expression: score >= 0 && score <= 100 [2 points]_________________________________________________________________3. Comment on the following program: (circle one) [2 points] public class MidtermExam {(a) will not compile because try/catch is missing public static void main(String[] argv) {(b) will compile and run int a = 89; int b = 99; (c) will not compile because division is not allowed for integers System.out.print((a + b) / 2); }(d) will not compile because there is a missing import }4. For a Java array of references to objects of class X to be traversed with a for-each loop, what must be true about class X? [2 points]_____________________________________________________________________________________5. Does the programmer have to write one or more constructor methods for every class that has private data members? Explain.[2 points](a) yes, one or more contructors must be written… (b) no, constructors do not always have to be written…explain:___________________________________________________________________________________________________________________________________________________________________6. What gets printed by the following code block? Look carefully – it’s not as easy as it may first appear! (Circle one) [2 points] // count to 3 int i; for (i = 0; i < 3; i++); System.out.print("" + i + ' '); System.out.println(); (a) 1 2 3 (b) 0 1 2 (c) 0 1 2 3 (d) 3 (e) nothingCompSci-61B, Data Structures – Midterm ExamCompSci-61B Midterm Exam, page 27. The following code compiles and runs. But it does not behave as its programmer intended. Explain the logic error. Hint: the problem is not with the console input programming: [4 points]1 import java.io.*; Explain: ______________________________________2 _____________________________________________3 public class MidtermExam _____________________________________________3 { _____________________________________________5 public static void main(String[] argv) throws Exception6 {7 BufferedReader cin;8 cin = new BufferedReader(new InputStreamReader(System.in)); 910 int score;11 System.out.print("Enter your CS61B midterm exam score: ");12 score = new Double(cin.readLine()).intValue();1314 if (score >= 80 || score <= 100)15 System.out.println("Wow – that’s pretty good!");16 else17 System.out.print("Hmm... study harder!");18 }19 }8. The following code will not compile. Explain the coding error that prevents the code from compiling. Hint: the problem is not with the console input programming: [4 points]1 import java.io.*; Explain: ______________________________________2 _____________________________________________3 public class MidtermExam _____________________________________________4 { _____________________________________________5 public static void main(String[] argv) throws Exception6 {7 BufferedReader cin;8 cin = new BufferedReader(new InputStreamReader(System.in)); 910 int score;11 System.out.print("Enter your CS61B midterm exam score: ");12 score = new Double(cin.readLine()).intValue();1314 if (score == 100)15 System.out.println("Wow – that’s perfect!");16 System.out.println("You get an A!");17 else if (score >= 80)18 System.out.println("Pretty good!");19 else20 System.out.println("Hmm... maybe you need to study more!");21 }22 }CompSci-61B, Data Structures – Midterm ExamCompSci-61B Midterm Exam, page 39. The following code will not compile! Explain what I am doing wrong. Hint: the problem is not with the console input programming:[4 points]1 import java.io.*; Explain: ______________________________________2 _____________________________________________3 public class MidtermExam _____________________________________________4 { _____________________________________________5 public static void main(String[] argv) throws Exception6 {7 BufferedReader cin;8 cin = new BufferedReader(new InputStreamReader(System.in)); 910 int score;11 int sum;12 while (true)13 {14 System.out.println("Enter a CS61B midterm exam score [-1 to exit]: ");15 score = new Double(cin.readLine()).intValue();1617 if (score < 0) break;18 sum = sum + score;19 }20 System.out.println("The total of all scores is: " + sum);21 }22 }Write the big oh of these operations in questions 10-12:10. quick sort, randomly-ordered array? fill in the blank: O( _________ ) [2 pts]11. insertion sort of an already-sorted array? fill in the blank: O( ______ ) [2 pts]12. selection sort of a simple, singly-linked list, without a “current node”? fill in the blank: O( ________ ) [2 pts]13. A certain search algorithm scales by O(1) when applied to a data structure containing n values. In a timing test with 1000 values, the search took 5 milliseconds to complete. How many milliseconds would you expect another timing test to take with 2000 values, or 4000 values? (Circle one each) [2 points]with 2000 values : (a) 5 ms (b) 6 ms (c) 10 ms (d) 20 mswith 4000 values: (a) 5 ms (b) 7 ms (c) 20 ms (d) 80 ms14. A certain search algorithm scales by O(log n) when applied to a data structure containing n values. In a timing test with 256 values, the search took 8 milliseconds to complete. How many milliseconds would you expect another timing test to take with 512 values, or 1,024 values? (Circle one each) [4 points]with 256 values : (a) 8 ms (b) 9 ms (c) 16 ms (d) 32 ms with 1,024 values: (a) 8 ms (b) 10 ms (c) 32 ms (d) 256 msCompSci-61B,


View Full Document

Berkeley COMPSCI 61B - Data Structures – Midterm Exam

Documents in this Course
Lab

Lab

4 pages

Matrix

Matrix

3 pages

Numbers

Numbers

14 pages

Lectures

Lectures

12 pages

Project 1

Project 1

24 pages

Exam

Exam

8 pages

Load more
Download Data Structures – Midterm Exam
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Data Structures – Midterm Exam and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Data Structures – Midterm Exam 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?