CSE 143 Midterm Key Summer 2013

CSE 143 Midterm Key Summer 2013

CSE 143 Midterm Key Summer 2013 1. Recursive Tracing Method Call mystery(18, 0) mystery(8, 18) mystery(25, 25) mystery(305, 214) mystery(20734, 1724) ...

NAN Sizes 0 Downloads 3 Views

Recommend Documents

CSE 3 Midterm Winter 2007 - UCSD CSE
C. san diego dean MINUS spanos. D. "san diego" OR "dean -spanos". 29. What is the shortcut in PowerPoint to start/restar

Midterm Exam Answer Key
... "Clever Hans" and what important lesson did he contribute to psychology? ..... Same with the case if the order of th

Introduction to Data Management CSE 344 Midterm What - CSE Home
parent(john, james). parent(james, bill). parent(sue, bill). parent(james, carol). parent(sue, carol). male(john). male(

Solutions to midterm exam - CSE - USF
control block as we learned in the setuid paper. Answer: When user jay executes the program, because the setuid bit is s

Midterm 1 - Fall 2013
Oct 21, 2013 - If the price of Raclette cheese decreased, we would expect to see: B ... In the market shown in the figur

CSE 355 Midterm Examination 27 February 2017 Last Name Sample
Feb 27, 2017 - Other than for that reason, test grades are almost never changed. If you believe that you did not receive

Summer Term Key Dates
May 30, 2016 - Small Heath School & Sixth Form Centre. NEWSLETTER. ISSUE 02. SUMMER 2016. The last few weeks have been a

midterm
Oct 31, 2011 - A: Managerial accounting focuses on information for internal decision making. ... How do these withdrawal

Midterm
(i) [5 Points] Find the marginal utility for goods 1 and 2, MU1 and MU2. .... (ii) [6 Points] Find the price the buyers

SketchUp 2013 Product Key
Copy & Paste these to install SketchUp 2013. User: Vermont Agency of Education User. License: ib1s-zd7h-wev9-rt4s-vo1k-y

CSE 143 Midterm Key Summer 2013 1. Recursive Tracing Method Call mystery(18, 0) mystery(8, 18) mystery(25, 25) mystery(305, 214) mystery(20734, 1724)

Value Returned 0 1 2 0 2

2. Recursive Programming One possible solution appears below: public static String dedup(String s) { if (s.isEmpty()) { throw new IllegalArgumentException(); } else if (s.length() == 1) { return s; } else if (s.charAt(0) == s.charAt(1)) { return dedup(s.substring(1)); } else { return s.charAt(0) + dedup(s.substring(1)); } } 3. Collections Mystery Parameter list [puppy, cat, bird, turtle] [foo, bar, baz, bar, qux] [a, a, double, bang, end, double, a, calm]

Map Returned {bird=4, cat=3, puppy=5, turtle=6} {bar=-1, baz=3, foo=3, qux=3} {a=-1, bang=4, calm=4, double=-1, end=3}

4. Collections Programming One possible solution appears below: public static Set extractShorterThan(Set s, int n) { Set result = new TreeSet(); Iterator iter = s.iterator(); while (iter.hasNext()) { String next = iter.next(); if (next.length() < n) { iter.remove(); result.add(next); } } return result; }

5. Linked Nodes One possible solution appears below: Before p->[1]->[2] q->[3]

After p->[1]->[3] q->[2]

p->[1]->[2] q->[3]->[4]

p->[1]->[3] q->[4]->[2]

p->[1]->[2]->[3] q

p->[3]->[2] q->[1]

p->[1]->[2]->[3] q->[4]->[5]

p->[2]->[1]->[4] q->[3]->[5]

Code ListNode temp = q; q = p.next; p.next = temp; q.next.next = p.next; p.next = q; q = q.next; p.next.next = null; p.next.next.next = p.next; q = p; p = p.next.next; q.next = null; p.next.next = null; p.next.next.next = q.next; ListNode temp = q; q = p.next.next; p.next.next = p; p = p.next; p.next.next = temp; temp.next = null;

6. Stacks/Queues One possible solution appears below: public static boolean isPairwiseConsecutive(Stack s) { Queue q = new LinkedList(); boolean isConsecutive = true; while (!s.isEmpty()) q.add(s.pop()); while (!q.isEmpty()) s.push(q.remove()); while (!s.isEmpty()) { int n = s.pop(); q.add(n); if (!s.isEmpty()) { int m = s.pop(); q.add(m); if (Math.abs(n - m) != 1) { isConsecutive = false; } } } while (!q.isEmpty()) s.push(q.remove()); return isConsecutive; }

7. ArrayIntList Programming One possible solution appears below: public void takeMax(ArrayIntList other) { ensureCapacity(Math.max(size, other.size)); for (int i = 0; i < other.size; i++) { if (elementData[i] < other.elementData[i] || i >= size) { elementData[i] = other.elementData[i]; } } size = Math.max(size, other.size); }