Docsity

Practice Questions for Exam 1 - Object-Oriented Program II | CMSC 132, Exams of Computer Science

Toggle sidebar
bg1
CMSC132
Fall 2006
Midterm #1
First Name: _______________________
Last Name: _______________________
Student ID: _______________________
Section time ___________ TA: __________________________
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.
Answer essay questions concisely using 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).
Honors section questions only count for credit for students in the honors section.
1
Grader Use Only:
#1 (13)
#2 (9)
#3 (7)
#4 (6)
#5 (12)
#6 (15)
#7 (18)
Total (80)
Honors (20)
pf3
pf4
pf5

Partial preview of the text

Download Practice Questions for Exam 1 - Object-Oriented Program II | CMSC 132 and more Exams Computer Science in PDF only on Docsity!

CMSC

Fall 2006

Midterm

First Name: _______________________ Last Name: _______________________ Student ID: _______________________ Section time ___________ TA: __________________________ 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.  Answer essay questions concisely using 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).  Honors section questions only count for credit for students in the honors section. Grader Use Only: #1 (13) #2 (9) #3 (7) #4 (6) #5 (12) #6 (15) #7 (18) Total (80) Honors (20)

  1. (13 pts) General Topics a. Abstraction and encapsulation help make programs run faster T or F b. Run-time errors are easier to detect than logic errors T or F c. Big-O notation indicates an upper bound on complexity T or F d. Critical sections are usually found inside loops T or F e. Best case analysis is more useful than worst case analysis T or F f. Linear data structures are a type of collection T or F g. Linked lists require more memory than arrays T or F h. We insert A, B, C into a stack. The first element to be removed is C. T or F i. We insert A, B, C into a queue. The first element to be removed is C. T or F j. Recursive code always requires a base case T or F k. Recursive code can always be rewritten as iterative code T or F l. Maps may have more values than keys T or F m. Maps may be implemented using arrays T or F
  2. (9 pts) Java constructs a. Java interfaces are examples of functional abstractions T or F b. Java methods are examples of data abstractions T or F c. Java throws exceptions for run-time errors T or F d. Java enumerations can grow in size during program execution T or F e. Java Collections consist of both interfaces and classes T or F f. Java Collections use the Comparable interface T or F g. Generic classes help detect errors in Java programs T or F h. If a.hashCode( ) == b.hashCode( ), then a.equals(b) == true T or F i. If a.hashCode( ) != b.hashCode( ), then a.equals(b) == false T or F
  3. (7 pts) Complexity of Data Structures For a data structure containing n elements a. Finding an element in a sorted array is O( ) b. Finding an element in a sorted linked list is O( ) c. Finding an element in a hash table of size 5 n is O( ) d. Inserting an element in an unsorted array (at beginning) is O( ) e. Inserting an element in an unsorted linked list (at beginning) is O( ) f. Inserting an element in a sorted linked list (keeping list sorted) is O( ) g. Inserting an element in a hash table of size 5 n is O( )

c. Write a recursive function to compare two array of ints, returning true if the arrays have the same elements and in the same order. Assume neither a nor b are null. The static method sameArray has the following prototype: public static boolean sameArray (int[ ] a , int[ ] b ) Feel free to add an auxiliary method. Non-recursive solutions will receive no credit.

  1. (15 pts) Generic Classes & Linked Data Structures a. Given the following Node class for Objects, convert it into a generic Node class (e.g., a class that can support generic programming such as Node, Node): public class Node { public Object data;  public Node next; Node( Object o ) { data = o; next = null; } }

b. Use the generic Node class to build a generic myQueue class that supports i. Constructor for empty myQueue( ) ii. Enqueue( ) method for adding element to queue iii. Dequeue( ) method for removing element from queue

Honors Section – Credit is given only for Honors Section students!

  1. (20 pts) Honors a. Expected cost is usually smaller than average cost T or F b. Amortized cost is usually smaller than worse cost T or F c. Java classes are examples of encapsulation T or F d. Java class inheritance is an example of generic programming T or F e. Iterative code can always be rewritten as recursive code T or F f. The clone( ) method makes a shallow copy of an object T or F g. The enhanced Java for loop relies on the Iterable interface T or F For a data structure containing n elements h. Finding an element in an open addressing hash table of size n+5 is O( ) i. Finding an element in an chained hash table of size n+5 is O( ) Give the complexity of an algorithm whose run time for n elements j. Is unchanged when n doubles O( ) k. Doubles when n doubles O( ) l. Increases by constant amount when n doubles O( ) m. Increases by ½ when n doubles O( ) n. Triples when n doubles O( ) o. Doubles when n increases by 2 O( ) p. Implement a showQueue( ) method for your myQueue class that prints out the contents of the queue (in the order elements will be dequeued), using the toString( ) method. The showQueue( ) method must not change the current contents of the queue.