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

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

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

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

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

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

Midterm Exam 2 CS 455, Spring 2011

Midterm Exam 2 CS 455, Spring 2013

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

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

Midterm Exam 2 CS 455, Fall 2013

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

Midterm Exam 2 CS 455, Spring 2014

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

Midterm Exam 2 CS 455, Fall 2012

Midterm Exam 2 CS 455, Fall 2014

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

Midterm Exam 2 CS 455, Spring 2015

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

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

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

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

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

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

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

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

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

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

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

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

CS 455 MT 2 Sample Questions

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

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

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

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

CS 12 Fall 2003 Solutions for mid-term exam #2

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

CS 113 MIDTERM EXAM 2 SPRING 2013

Dynamic arrays / C Strings

CS32 Final Exam. E03, F15, Phill Conrad, UC Santa Barbara

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

Prelim 1. CS2110, October 2, 2014, 5:30 PM Extra Total Question TrueFalse Multiple Object Oriented

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

Csci 102: Sample Exam

CMSC 341 Lecture 7 Lists

CS 314 Exam 2 Fall 2017

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

CS 216 Exam 1 Fall SOLUTION

FORM 2 (Please put your name and form # on the scantron!!!!)

CSCI 102 Fall 2010 Exam #1

CSE 333 Midterm Exam 7/25/16. Name UW ID#

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

CSE332 Summer 2010: Final Exam

CS 314 Exam 2 Spring

#101 Page: 1 Name: CS32 Midterm Exam. E01, W15, Phill Conrad, UC Santa Barbara

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

Final Exam. COMP Summer I June 26, points

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

Section 1: True / False (2 points each, 30 pts total)

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

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

CS61BL: Data Structures & Programming Methodology Summer 2014

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

CS 307 Midterm 2 Spring 2008

CS 104 (Spring 2014) Final Exam 05/09/2014

CS 314 Exam 2 Spring 2018

(the bubble footer is automatically inserted into this space)

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

Points off A 4B 5 Total off Net Score. CS 314 Final Exam Spring 2015

Prelim 2. CS 2110, April 26, 2016, 5:30 PM Total Question True/False Complexity Heaps Trees Graphs Max Score Grader

Hash tables. hashing -- idea collision resolution. hash function Java hashcode() for HashMap and HashSet big-o time bounds applications

Final Exam COMP Fall 2004 Dec 16, 2004

Midterm Exam. Sample Solutions

Data Structures CSci 1200 Test 1 Questions

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

Prelim 2. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Points off Total off Net Score. CS 314 Final Exam Fall 2016

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer

CS 307 Final Fall 2009

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

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

Test 1: CPS 100. Owen Astrachan. October 1, 2004

UMBC CMSC 331 Final Exam

ComS 228 Exam 1. September 27, 2004

CSE 333 Midterm Exam July 24, Name UW ID#

CSCE 2014 Final Exam Spring Version A

mypoly

CS 202: Introduction to Computation Fall 2010: Exam #1

CS 314 Final Fall 2012

Separate compilation

Prelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer

CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.

CS 201, Fall 2016 Dec 2nd Exam 3

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

Prelim 2 Solution. CS 2110, April 26, 2016, 7:30 PM

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

Transcription:

Name: USC loginid (e.g., ttrojan): CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012 There are 6 problems on the exam, with 70 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 two-sided one-page 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 USC 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. 10 pts. 15 pts. 6 pts. 13 pts. 20 pts. 70 pts. 1

Problem 1 [6 pts. total] Consider the following Java method computes the sum of the elements in a LinkedList object: public static int sumlist(linkedlist<integer> list) { int sum = 0; for (int i = 0; i < list.size(); i++) { sum += list.get(i); return sum; This problem concerns the implementation of sumlist assume we cannot change the interface to the function. Part A (4). The code works, but is written in a bad way. What's the problem with the code? (Be specific.) Part B (2). Describe how we can improve the code, and how your improvement helps. (You should not rewrite the function; just write one sentence or so.) 2

Problem 2 [10 pts] Part A (8). Implement the boolean Java method sortbyscore, which sorts an ArrayList of students so they are in decreasing order by score. You must use the Java sort utility (more info about that on the code handout), and include any additional code necessary to make it work (outside of the sortbyscore method). Here is the Student class it uses (only shows interface, since that's all we are using here). This is an already completed class; you may not modify Student for this problem. public class Student implements Comparable<Student> { public Student(String name, int score) {... public String getname() {... public int getscore() {... public void changescore(int newscore) {... // compares this student with b by name: if this student's name comes before // b's name returns a negative value, positive if it comes after, and 0 if // they are equal public int compareto(student b) {...... // private stuff not shown public static void sortbyscore(arraylist<student> students) { Part B (2). Using big-o notation give the worst-case time for your method as a function of, n, the size of the array list. 3

Problem 3 [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) { 4

Problem 4 [6 pts. total] Assume we are trying to compile the C++ grades program we did for assignment 5. Here's a reminder of the file organization: Table.h Table.cpp Header file for the Table class (contains Table class definition) Implementation file for the Table class (contains Table method definitions) grades.cpp A program that uses the Table class (contains main) Consider the following non-ideal Makefile for the program (compile commands are numbered at the right for your convenience): grades: grades.o Table.o g++ -ggdb Wall grades.o Table.o o grades (1) Table.o: Table.cpp Table.h g++ -ggdb Wall c Table.cpp (2) grades.o: grades.cpp Table.cpp Table.h g++ -ggdb Wall c grades.cpp (3) Suppose we have already compiled our grades program successfully once using this Makefile. Give a scenario such that the Makefile given will do more work than necessary to create the updated executable for our program the next time we call gmake. a. File(s) modified in your scenario: b. Step(s) done by the Makefile above on the next call to the gmake grades command: (Note: you may use the numbers shown above; numbers must be given in a valid order) c. Minimum step(s) that would have been necessary to create the updated executable for our program under this scenario: (Note: you may use the numbers shown above; numbers must be given in a valid order): 5

Problem 5 [13 pts.] Consider the following C++ program: (Note: the Node class is on code handout.) void swap(node * a, Node * b) { Node * tmp = a; a = b; b = tmp; cout << a->data << " " << b->data << endl; int main() { Node * x = new Node(3); Node * y = new Node(8); cout << x->data << " " << y->data << endl; swap(x, y); cout << x->data << " " << y->data << endl; return 0; Part A [7]. In the space below, draw a box-and-pointer diagram (a.k.a., memory diagram) showing all variables, objects, and their state as they have changed during the code sequence. This includes showing all of swap's variables and parameters. Part B [6]. In the space below show the output of the program: 6

Problem 6 [20 pts] Implement the C++ function removeeveryother which removes every other element from a linked list of ints starting with the first element. For full credit you need to reclaim memory no longer used. The Node and ListType definitions are on the code handout. list before call list after call to removeeveryother(list) (1 2 3) (2) (7 6 7 5 7 8) (6 5 8) (1 2 3 4) (2 4) (1 2 3 4 5) (2 4) () () (3) () // PRE: list is a well-formed linked list void removeeveryother(listtype & list) { 7