Docsity

10 Problems on Object Oriented Program II - Final Exam | CMSC 132, Exams of Computer Science

Toggle sidebar
bg1
CMSC132
Fall 2005
Final Exam
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):
a. This exam is closed book and closed notes.
b. If you have a question, please raise your hand.
c. Total point value is 100 points.
d. Answer True/False questions by circling the T or F at the end of the question.
e. Answer multiple-choice questions by circling the letter (e.g., a, b) at the front of each
choice.
f. Answer essay questions concisely using 1 or 2 sentences. Longer answers are not necessary
and are discouraged.
g. WRITE NEATLY. If we cannot understand your answer, we will not grade it (i.e., 0
credit).
h. Honors section questions only count for credit for students in the honors section.
1
Grader Use Only:
#1 (15)
#2 (7)
#3 (8)
#4 (13)
#5 (9)
#6 (16)
#7 (9)
#8 (7)
#9 (8)
#10 (8)
Total (100)
Honors (8)
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download 10 Problems on Object Oriented Program II - Final Exam | CMSC 132 and more Exams Computer Science in PDF only on Docsity!

CMSC

Fall 2005

Final Exam

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):

a. This exam is closed book and closed notes.

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

c. Total point value is 100 points.

d. Answer True/False questions by circling the T or F at the end of the question.

e. Answer multiple-choice questions by circling the letter (e.g., a, b) at the front of each

choice.

f. Answer essay questions concisely using 1 or 2 sentences. Longer answers are not necessary

and are discouraged.

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

credit).

h. Honors section questions only count for credit for students in the honors section.

Grader Use Only:

Total (100)

Honors (8)

Problem 1 (15 pts) Software Engineering & Object-Oriented Design

a. (1 pt) The Waterfall model is reasonable for both small and large projects. T or F b. (1 pt) The Waterfall model, Unified model, and Rapid Prototyping are intended to be models of what? (Hint: Provide a 3-word answer. You get 0 points for providing definitions of each model) c. (1 pt) Define data abstraction. d. (8 pts) Given the following problem description, produce an object-oriented solution and answer the questions below. Design a software system for a bookstore that keeps an inventory of two types of books: traditional books and books on CD. Books on CD may also contain music. The bookstore purchases books from publishers and sets a price for each book. Customers can purchase books from the bookstore, using either cash or a credit card. The bookstore keeps track of which books it has its inventory, and the books purchased by each customer. i. What are the objects in your object-oriented solution? ii. What are the interactions between objects in your object-oriented solution? iii. Which objects “have” other objects? (Also list target object) iv. Which objects “use” other objects? (Also list target object) v. Which objects “are” other objects? (Also list target object)

Problem 2 (7 pts) Algorithm Complexity

a. (3 pts) Calculate the asymptotic complexity of the code snippets below (using big-O notation) with respect to the problem size n. i. for (int i=0; i<n/2; i++) { f(n) = O( ) for (int k=0; k<20; k++) { for (int j=0; j<30; j++) { // ... } } } ii. for (int i=n/2; i<=n; i++) { f(n) = O( ) for (int j=1; j<=n; j=j2) { for (int k=1; k<=n; k=k2) { // ... } } } iii. for (int i=1; i<=100; i++) { f(n) = O( ) // ... } b. (2 pts) List the following big-O expressions in order of asymptotic complexity (with the lowest complexity first) O(nlog(n)) O(1) O(log(n)) O(2^n) O(n) c. (2 pts) How can asymptotic complexity be analyzed for recursive algorithms?

Problem 3 (8 pts) Data Structures and Recursion

a. (1 pt) Elements in a map have exactly 1 successor. T or F

b. (1 pt) A base case is optional for some recursive problems. T or F

c. (6 pts) Given the following Java class definition for a binary tree, write a recursive method named

numLeafNodes that determines the number of leaf nodes in the binary tree. Remember that leaf nodes are nodes with no children. Assume “left” and “right” have the value “null” if no subtree is present. You may use helper functions. Class Node { Object myValue; Node left; Node right; } Class Tree { Node root; // root node in tree int numLeafNodes( ) { // return number of leaf nodes in tree

i. (2 pts) Decode the sequence “1001000” ii. (2 pts) Encode the string “MTZ” c. (4 pts) Create a Huffman tree for the following nodes A B C D

Problem 6 (16 pts) Multithreading and Synchronization

a. (1 pt) Excessive use of synchronization mechanisms can reduce performance. T or F b. (1 pt) A Java object can be assigned two locks. T or F

M

Z

K

1 1 1 0 0 1 0 0

H T

c. (1 pt) A program with data races will produce different results each time it is run. T or F d. (9 pts) Given the following diagram of states a thread can assume, draw all possible transitions between states, and list one possible cause for each transition. runnable new dead running blocked

Problem 7 (9 pts) Advanced Tree Data Structures

a. (2 pt) What is the property that an AVL tree must maintain so that the tree is balanced? b. (1 pt) In a Red-black tree no leaf is twice as far from root as another leaf. T or F c. (2 pt) Consider the following binary search tree and then draw the tree that will result from doing a single right rotation around node 7. d. (2 pts) Draw the 2-3 tree that will result from inserting the value 4 in the following tree. e. (2 pts) Draw a standard trie to represent the strings in the set {boy, bat, bad}

Problem 8 (7 pts) Java Language Features

a. (2 pt) What is a shallow copy? b. (1 pt) The default clone method creates a shallow copy of the object. T or F c. (2pt) What is a checked exception? d. (2 pts) Given the following Java code fragment using java.util.regex: Pattern p = Pattern.compile(“[a-z]+”); Matcher m = p.matcher(“12abc ab12c”); while (m.find()) { System.out.print(m.group() + “\n”); } What will be printed out when the code is executed?

Problem 9 (8 pts) Sorting, & Algorithm Strategies

a. (1 pt) What is the worst case complexity of sorting using quicksort? b. (2 pt) What can cause worst case behavior for quicksort? c. (1 pt) What is the average case complexity of sorting using bucket sort? d. (2 pt) Why may we want to use a stable sort? e. (1 pt) Which algorithm strategy allow us to efficiently compute the minimal spanning tree of a graph? f. (1 pt) Which algorithm strategy allow us to efficiently compute the shortest path between two nodes in a graph?

Problems for Honors Section (8 pts)

Credit is given only for Honors Section students!

Answer the following questions below. a. (2 pts) What is Catch or Declare? b. (2 pts) Explain how multithreaded Java code can improve performance even for a computer with a single processor c. (2 pts) Given the following Java code fragment using java.util.regex: Pattern p = Pattern.compile(“[a-z][0-9]+”); Matcher m = p.matcher(“12abc ab12c”); while (m.find()) { System.out.print(m.group() + “\n”); } What will be printed out when the code is executed? d. (2 pts) Why is it difficult to make a deep copy of a graph?