Midterm Exam 2 CS 455, Spring 2013

Similar documents
Midterm Exam 2 CS 455, Fall 2012

Midterm Exam 2 CS 455, Spring 2014

Midterm Exam 2 CS 455, Fall 2013

Midterm Exam 2 CS 455, Fall 2014

CS 455 Final Exam Fall 2015 [Bono] Dec. 15, 2015

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018

Midterm Exam 2 CS 455, Spring 2011

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

CS 455 Midterm Exam 1 Spring 2013 [Bono] Feb. 21, 2013

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016

Midterm Exam 2 CS 455, Spring 2015

CS 455 Final Exam Fall 2013 [Bono] December 12, 2013

CS 455 Midterm Exam 2 Spring 2017 [Bono] Tuesday, April 4, 2017

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

CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011

CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017

CS 455 Midterm Exam 1 Fall 2013 [Bono] Wednesday, Oct. 2, 2013

CS 455 Midterm Exam 1 Fall 2015 [Bono] Thursday, Oct. 1, 2015

CS 455 Final Exam Spring 2017 [Bono] May 10, 2017

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

CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011

CS 455 Final Exam Fall 2016 [Bono] December 13, 2016

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

CS 455 MT 2 Sample Questions

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

CS 455 Midterm Exam 1 Spring 2015 [Bono] Thursday, Feb. 19, 2015

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

Computer Science II Fall 2009

CS 113 MIDTERM EXAM 2 SPRING 2013

Example Program. public class ComputeArea {

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

CS 455 Final Exam Spring 2015 [Bono] May 13, 2015

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Examination Questions Midterm 1

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

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

CS170 (005): Introduction to Computer Science Exam 2

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

public class Q1 { public int x; public static void main(string[] args) { Q1 a = new Q1(17); Q1 b = new Q1(39); public Q1(int x) { this.

Final Exam. COMP Summer I June 26, points

CS 307 Midterm 2 Spring 2008

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

I. True/False: (2 points each)

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

Happy Cinco de Mayo!!!!

Practice Midterm 1. Problem Points Score TOTAL 50

Problem Grade Total

CS 101 Exam 2 Spring Id Name

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

CSE 331 Spring 2018 Midterm

Final exam. CS 2110, December 15, 2016, 9:00AM

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks:

Question: Total Points: Score:

XC Total Max Score Grader

CS165 Practice Final Exam Answer Key

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

Midterm Examination (MTA)

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

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

Advanced Java Concepts Unit 3: Stacks and Queues

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

Stacks and Queues. Introduction to abstract data types (ADTs) Stack ADT. Queue ADT. Time permitting: additional Comparator example

Question: Total Points: Score:

CS 314 Exam 2 Spring

CS 314 Exam 2 Spring 2018

CMPSCI 187 Midterm 1 (Feb 17, 2016)

Happy Cinco de Mayo!!!!

Total Score /15 /20 /30 /10 /5 /20 Grader

F I N A L E X A M I N A T I O N

Question: Total Points: Score:

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Total Score /1 /20 /41 /15 /23 Grader

CS165 Practice Final Exam

Question: Total Points: Score:

CS 177 Spring 2010 Exam I

Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops.

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

NAME: c. (true or false) The median is always stored at the root of a binary search tree.

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

CS 314 Midterm 2 Spring 2013

Total Score /15 /20 /30 /10 /5 /20 Grader

New York University Intro to Computer Science (CSCI-UA.101) Fall 2014 Midterm #1 Test G. Instructions:

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

SAMPLE EXAM Second Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 11 November 2010

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

CS56 final (E03) W15, Phill Conrad, UC Santa Barbara Wednesday, 03/18/2015. Name: Umail umail.ucsb.edu. Circle one: 4pm 5pm 6pm

CMSC132 Summer 2018 Midterm 1

CS 113 PRACTICE FINAL

Csci 102: Sample Exam

CS Operating system

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

CS 101 Fall 2006 Midterm 1 Name: ID:

CSE 413 Winter 2001 Midterm Exam

Place your name tag here

Claremont McKenna College Computer Science

1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004

Transcription:

Name: USC loginid (e.g., ttrojan): Midterm Exam 2 CS 455, Spring 2013 April 4, 2013 There are 6 problems on the exam, with 60 points total available. There are 7 pages to the exam, including this one; make sure you have all of them. There is also a separate double-sided onepage code handout. If you need additional space to write any answers, you may use the backs of exam pages (just direct us to look there). Note: if you give multiple answers for a problem, we will only grade the first one. Avoid this issue by labeling and circling your final answers and crossing out any other answers you changed your mind about (though it s fine if you show your work). Put your name and loginid at the top of the exam. Please read over the whole test before beginning. Good luck! value score Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Problem 6 TOTAL 6 pts. 6 pts. 4 pts. 14 pts. 15 pts. 15 pts. 60 pts. 1

Problem 1 [6 pts. total] Consider an implementation for the Java Set interface we'll call OrderedArraySet, a class which uses an ordered array representation to store the elements of the set. Part A (2). (fill in the blanks) With this representation we can do the contains(key) operation, in O( ) time worst-case using the algorithm. Part B (4). Java does not provide an OrderedArraySet implementation for the Set interface. Why? Note: Your answer should include a discussion of specific Set operations (most of the Set interface is shown on the code handout). However, you shouldn't need all the space below it's just the way the paging worked out. 2

Problem 2 [6 pts. total] Part A. Consider the following balanced binary search tree, whose root is shown nearest the top of the page (i.e., it's not a sideways tree): Joe Hal Ned Ann Kat Sam Abe Cal Pat Van For each of the following lookups from the tree shown above, give the sequence of keys that the target key would have to be compared with to do the lookup. Part A. lookup Dan Part B. lookup Lou Part C. lookup Pat 3

Problem 3 [4 points] Consider the following Java program that uses exceptions (part of the exception class hierarchy shown above): public class MyProg { public static void main(string[] args) { try { Scanner in = new Scanner(System.in); System.out.println("Please enter an integer: "); String line = in.nextline(); Scanner linescanner = new Scanner(line); int val = getint(linescanner); if (val > 100) { throw new BadIntException("Value out of range"); System.out.println("Value entered was: " + val); catch (BadIntException exc) { System.out.println("Bad Int Exception: " + exc.getmessage()); public static int getint(scanner linescanner) { int val; try { if (!linescanner.hasnextint()) { throw new BadIntException("Problem #1"); val = linescanner.nextint(); if (linescanner.hasnext()) { throw new BadIntException("Problem #2"); catch (IOException exc) { System.out.println("IO ERROR: " + exc.getmessage()); val = -1; return val; Does MyProg compile? If you answered "no": write in the minimal changes to it above so it would compile. If you answered "yes": what exact output does the current code give if the user enters the following input at the prompt: a 200 4

Problem 4 [14 points] Part A (10). Assume we make a call to the following method, prob5func, with a stack with the following value (in this diagram the top of the stack is at the right side, and is labeled as such): value of s: 1 6 7 0 2 4 5 top Show the contents of each of the stacks listed at each of the points in the code, labeled A, B, and C. For each one clearly label where the top of your stack is in your diagram. public static Stack<Integer> prob5func(stack<integer> s) { Stack<Integer> first = new Stack<Integer>(); Stack<Integer> second = new Stack<Integer>(); boolean found0 = false; while (!s.empty() &&!found0) { int curr = s.peek(); first.push(s.pop()); at point A: if (curr == 0) { found0 = true; s: // A first: while (!s.empty()) { second.push(s.pop()); // B while (!first.isempty()) { second.push(first.pop()); // C return second; at point B: s: second: at point C: first: second: Part B (4). In general what does the function do with its argument, s? Assume it is called as follows: s = prob5func(s); 5

Problem 5 [15 pts] We can think of a Map as describing a function that maps from keys to values. Write the Java boolean function isonetoone which tells if its Map argument is a one-to-one function, that is, whether no two (key, value) entries have the same value part. Here are some examples (maps shown as they would be by a call to tostring): map isonetoone(map) {joe=3, sally=2, sam=3 false (both joe and sam have the value, 3) {joe=3, sally=2, sam=7 true (no two keys have the same value) { true (you may assume an empty map is one-to-one) To receive full credit your function must run in at most O(n) time, where n is the number of entries in the map (Hint: take advantage of the Java library). public static boolean isonetoone(map<string, Integer> map) { 6

Problem 6 [15 points] Write the method interleave, which takes two LinkedList objects and returns a new LinkedList where the values from the old lists are interleaved into the new list: that is, the new list starts with the first element from list1, then first element from list2, second element from list1, second element from list2, etc. If one of the lists is longer than the other, it puts all the leftover elements on the end of the resulting list. The original lists are unchanged by this method. Examples: list1 list2 return value of interleave(list1, list2): (1 3 5 7 9 11 13) (8 6 4 2) (1 8 3 6 5 4 7 2 9 11 13) (1 2) (3 4 5) (1 3 2 4 5) () (4 5 1) (4 5 1) public static LinkedList<Integer> interleave(linkedlist<integer> list1, LinkedList<Integer> list2) { 7