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

The spring 2007 cmsc132 midterm 1 exam for computer science students. The exam covers object-oriented programming, testing, algorithmic complexity, critical sections, recursion, data structures, operations on data structures, and generic programming. Instructions for the exam, grading rules, and specific questions with answer choices.

Typology: Exams

Pre 2010

Uploaded on 02/13/2009

koofers-user-8ra-1
koofers-user-8ra-1 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC132
Spring 2007
Midterm #1
First Name: _______________________
Last Name: _______________________
Student ID: _______________________
Section time _________ TA Name: _________________
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 80 points.
Answer True/False questions by circling the T or F at the end of the question.
oCorrect answers to True/False questions receive 1 point each (+1pt)
oUnanswered (blank) True/False questions receive 0 points each
oIncorrect answers to True/False questions are penalized 1 point each (-1pt)
Answer essay questions concisely using 1-2 sentences. Longer answers are discouraged.
PUNT RULE: For essay/coding questions, you may write PUNT, and you will get ¼ of the
points for the question (rounded down). You are encouraged to punt rather than waste your
time writing down semi-random verbiage in hopes of getting partial credit.
WRITE NEATLY. If we cannot understand your answer, you will receive 0 credit.
Honors section questions only count for credit for students in the honors section.
1
Grader Use Only:
#1 OOP (5)
#2 Testing (6)
#3 Complexity (13)
#4 Critical Section (4)
#5 Recursion (4)
#6 Data Structures (10)
#7 Operations (12)
#8 Generics & Data Structs (26)
Total (80)
Honors (12)
pf3
pf4
pf5

Partial preview of the text

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

CMSC

Spring 2007

Midterm

First Name: _______________________ Last Name: _______________________ Student ID: _______________________ Section time _________ TA Name: _________________ 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 80 points.  Answer True/False questions by circling the T or F at the end of the question. o Correct answers to True/False questions receive 1 point each (+1pt) o Unanswered (blank) True/False questions receive 0 points each o Incorrect answers to True/False questions are penalized 1 point each (-1pt)  Answer essay questions concisely using 1-2 sentences. Longer answers are discouraged.  PUNT RULE : For essay/coding questions, you may write PUNT, and you will get ¼ of the points for the question (rounded down). You are encouraged to punt rather than waste your time writing down semi-random verbiage in hopes of getting partial credit.  WRITE NEATLY. If we cannot understand your answer, you will receive 0 credit.  Honors section questions only count for credit for students in the honors section. Grader Use Only: #1 OOP (5) #2 Testing (6) #3 Complexity (13) #4 Critical Section (4) #5 Recursion (4) #6 Data Structures (10) #7 Operations (12) #8 Generics & Data Structs (26) Total (80) Honors (12)

  1. (5 pts) Object-Oriented Programming and Java a. Procedural abstraction makes it clear what algorithm is used by a program T or F b. Java interfaces are examples of data abstraction T or F c. Java requires a list of all possible values for an enumerated type T or F d. Using Java generics can cause more errors to appear during compilation T or F e. The Java Comparator interface supports generics T or F
  2. (6 pts) Testing & Program Correctness a. Compile-time errors may cause exceptions to be thrown in Java T or F b. An interactive debugger can display the value of variables in a program T or F c. Breakpoints mark where run-time errors may occur in a program T or F d. Empirical testing will find all run-time errors in a program T or F e. Integration testing tests individual classes T or F f. Test coverage measures whether code is executed by some test case T or F
  3. (13 pts) Algorithmic Complexity a. Asymptotic complexity is more accurate than benchmarking T or F b. Worst case analysis is more useful than best case analysis T or F c. Critical sections are never found outside loops T or F d. O(n) is more complex than O( log(n) ) T or F e. O(n log(n) ) is more complex than O(n^2 ) T or F (2 pts each) Give the complexity of an algorithm for problem size n whose running time: f. Triples when n triples O( ) g. Quadruples when n doubles O( ) h. Is unchanged when n triples O( ) i. Increases by 3 when n triples O( )
  4. (4 pts) Critical Sections Calculate the asymptotic complexity of the code snippets below (using big-O notation) with respect to the problem size n : a. for (i = 1; i < n ; i=i*2) { f(n) = O( ) for (k = 1; k < 1000; k=k+2) { … } } b. for (i = n ; i > 0; i=i-1) { f(n) = O( ) for (j = 2; j < n -2; j=j+2) { ... } }
  1. (26 pts) Generic Programming & Data Structures You are asked to count the number of times each String occurs in an array. You realize you can build a map from Strings to Integers to keep count of the number of occurrences for each word. You start writing a class implementing the map, using linked lists with an extra key field per node: public class MyListMap { private class Node { Object k; // key Object v; // value Node next; } private Node head; public Object get(Object key) { ... } // returns value for key (or null) public Object put(Object key, Object value) { ... } // returns previous value for key } // (or null if no previous value) a. (4 pts) Using your knowledge of generic programming, modify the MyListMap class so it supports generics (e.g., MyListMap<String,Integer>). b. (12 pts) Implement the put( ) method for the MyListMap class, using only a linked list formed from the inner Node class. c. (10 pts) Implement the following count( ) method so that it returns a map from Strings to Integers that counts the number of times each string occurs in the String array strs. You must iterate through the Strings in the strs array using the enhanced Java for loop. You must create a MyListMap object using generics and use only its get( ) and put( ) methods to count strings. // returns map of string counts public static MyListMap<String,Integer> count(String[ ] strs) { ... }