Spring 2008 CMSC132 Midterm 1 - Prof. Nelson Padua-Perez, Exams of Computer Science

The instructions and questions for the midterm 1 exam of the cmsc132 course offered in spring 2008. The exam covers topics such as algorithmic complexity, program correctness, hashing, java language features, and sets and maps. Students are required to answer short answer questions related to these topics, and the exam is closed book and closed notes. The document also includes information about grading, rules, and exceptions.

Typology: Exams

Pre 2010

Uploaded on 02/13/2009

koofers-user-y40
koofers-user-y40 🇺🇸

9 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC132
Spring 2008
Midterm #1
First Name: _______________________
Last Name: _______________________
Student ID: _______________________
Discussion TA: ______________________
Discussion Time: _____________________
I pledge on my honor that I have not given or received any unauthorized assistance on this
examination.
Your signature: _____________________________________________________________
General Rules (Read):
This exam is closed book and closed notes.
If you have a question, please raise your hand.
Total point value is 100 points.
The short answer questions are not essay questions. Strive to answer them in 1 or 2
sentences. Longer answers are not necessary and are discouraged.
WRITE NEATLY. If we cannot understand your answer, we will not grade it (i.e., 0
credit).
PUNT RULE:. For any question, you may write PUNT, and you will get ¼ of the points
for the question (rounded down). If you feel totally lost on a question, you are encouraged
to punt rather than waste time writing down an incorrect answer in hopes of getting some
partial credit.
Honors section questions only count for credit for students in the honors section
1
Grader Use Only:
#1 Algorithmic Complexity (16 pts)
#2 Program Correctness (10 pts)
#3 Hashing (10 pts)
#4 Language Features (30 pts)
#5 Sets and Maps (34 pts)
Total (100 pts)
Honors (10 pts)
pf3
pf4
pf5
pf8

Partial preview of the text

Download Spring 2008 CMSC132 Midterm 1 - Prof. Nelson Padua-Perez and more Exams Computer Science in PDF only on Docsity!

CMSC

Spring 2008

Midterm

First Name: _______________________

Last Name: _______________________

Student ID: _______________________

Discussion TA: ______________________

Discussion Time: _____________________

I pledge on my honor that I have not given or received any unauthorized assistance on this

examination.

Your signature: _____________________________________________________________

General Rules (Read):

 This exam is closed book and closed notes.

 If you have a question, please raise your hand.

 Total point value is 100 points.

 The short answer questions are not essay questions. Strive to answer them in 1 or 2

sentences. Longer answers are not necessary and are discouraged.

 WRITE NEATLY. If we cannot understand your answer, we will not grade it (i.e., 0

credit).

 PUNT RULE:. For any question, you may write PUNT, and you will get ¼ of the points

for the question (rounded down). If you feel totally lost on a question, you are encouraged

to punt rather than waste time writing down an incorrect answer in hopes of getting some

partial credit.

 Honors section questions only count for credit for students in the honors section

Grader Use Only:

#1 Algorithmic Complexity (16 pts)

#2 Program Correctness (10 pts)

#3 Hashing (10 pts)

#4 Language Features (30 pts)

Sets and Maps

(34 pts)

Total (100 pts)

Honors (10 pts)

Problem 2 (10 pts) Program Correctness and Exceptions

1. (1 pt) 90% code coverage implies there is a probability 90% of the code is correct. T or F

2. (1 pt) 100% code coverage is not possible. T or F

3. (1 pt) A checked exception must be catch or declared. T or F

4. (1 pt) A finally block is executed only when an exception occurs. T or F

5. (6 pts) Modify the following code in order to handle a ListEmptyException that might be

thrown by a method called f(). The exception handler must print (using System.out.println)

the message “Error: Empty List Detected”.

public void test() { f(); }

Problem 3 (10 pts) Hashing

1. (2 pts) Name two properties of a good hashing function.

2. (4 pts) Briefly describe the Java Hash Code Contract.

3. (4 pts) Does the default hashCode and equals methods for a class (those provided by the

Object class) satisfy the Java Hash Code Contract? Yes or No answer with no justification

will receive no credit.

Problem 4 (30 pts) Java Language Features

1. (2 pts) Java interfaces are examples of procedural abstractions. T or F

2. (2 pts) Procedural Abstraction specifies what actions should be performed. T or F

3. (2 pts) Abstraction and encapsulation help make programs run faster. T or F

4. (2 pts) If class A extends B then List extends List T or F

5. (2 pts) A class implementing the Iterable interface can be used in an enhanced for loop. T or F

6. (2 pts) A static initialization block is executed when each object is created. T or F

7. (2 pts) A constructor can override any initialization performed by an initialization block. T or F

8. (2 pts) A private visibility modifier allow us to enforce encapsulation. T or F

9. (2 pts) All methods of an abstract class must be abstract. T or F

10. (2 pts) We cannot have instance variables in abstract classes. T or F

11. (2 pts) Which of the following are valid assuming a class C with a default constructor?

Circle your answer.

a. C temp = new C(); VALID/INVALID

b. C temp = null; VALID/INVALID

12. (5 pts) Make the following class generic so that it can deal with an arbitrary class rather than

only Strings. Feel free to cross out parts of the following code.

public class Col { private ArrayList c; public String get() { return c.remove(0); } public void insert(String value) { c.add(value); } }

13. (3 pts) Rewrite the following for loop using an enhanced for loop.

String[] names = {"John", "Kate", "Laura"}; for (int i=0; i < names.length; i++) System.out.println(names[i]);

Problem 5 (34 pts) Sets and Maps

Honors Section problems are on the reverse

NOTE: Only Honors Section Students Will Receive Credit

(10 pts) Honors Section

Java provides two different standard implementations of the List interface: LinkedList and ArrayList.

a. What is an operation supported by Lists that would have substantially slower asymptotic

complexity on a LinkedList than on an ArrayList. What are the complexities in each implementation? Don’t worry if you don’t remember the exact method name, just describe what the method does.

b. The same question, except an operation that has slower asymptotic complexity on an ArrayList

than on a LinkedList. Name/describe the operation, and give the asymptotic complexity in each implementation.

c. The same question, except an operation is supported by both Sets and Lists, and has slower

asymptotic complexity either List implementation than on a HashSet. Name/describe the operation, and give the asymptotic complexity in List implementations, and in HashSet.