{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# midterm - CSE 143 Winter 2010 Midterm Exam Wednesday...

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

1 of 6 CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010 Personal Information: Name: ___________________________________________ Section: ___________________ TA: ___________________ Student ID #: ___________________ You have 50 minutes to complete this exam. You may receive a deduction if you keep working after the instructor calls for papers. This exam is open-book/notes. You may not use any computing devices including calculators. Code will be graded on proper behavior/output and not on style, unless otherwise indicated. Do not abbreviate code, such as "ditto" marks or dot-dot-dot . .. marks. The only abbreviations that are allowed for this exam are: ± S.o.p for System.out.print , and ± S.o.pln for System.out.println . You do not need to write import statements in your code. If you enter the room, you must turn in an exam before leaving the room. You must show your Student ID to a TA or instructor for your exam to be accepted. Good luck! Score summary: (for grader only) Problem Description Earned Max 1 ArrayList Mystery 20 2 Recursive Tracing 20 3 Comparable 15 4 Stacks and Queues 15 5 Collections 15 6 Linked Lists 15 TOTAL Total Points 100

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

View Full Document
2 of 6 1. ArrayList Mystery Consider the following method: public static void mystery(ArrayList<Integer> list) { for (int i = 1; i < list.size(); i += 2) { if (list.get(i - 1) >= list.get(i)) { list.remove(i); list.add(0, 0); } } System.out.println(list); } Write the output produced by the method when passed each of the following ArrayList s: List Output a) [10, 20, 10, 5] b) [8, 2, 9, 7, -1, 55] c) [0, 16, 9, 1, 64, 25, 25, 14, 0] 2. Recursive Tracing For each of the calls to the following recursive method below, indicate what value is returned: public static int mystery(int n, int k) { if (k == 0 || k == n) { return 1; } else if (k > n) { return 0; } else { return mystery(n - 1, k - 1) + mystery(n - 1, k); } } Call Returns a) mystery(7, 1) b) mystery(4, 2) c) mystery(4, 3) d) mystery(5, 3) e) mystery(5, 4)
3 of 6 3. Comparable Suppose you have a pre-existing class Dieter that models a person trying to monitor diet and weight to improve

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

midterm - CSE 143 Winter 2010 Midterm Exam Wednesday...

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

View Full Document
Ask a homework question - tutors are online