Docsity

Final Exam - Object Oriented Program II - Spring 2007 | CMSC 132, Exams of Computer Science

Toggle sidebar
bg1
CMSC132
Spring 2007
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 and wait for us to come to you.
c. Total point value is 122 points.
d. Answer True/False questions by circling the T or F at the end of the question.
a. Correct answers to True/False questions receive 1 point each (+1pt)
b. Unanswered (blank) True/False questions receive 0 points each
c. Incorrect answers to True/False questions are penalized 1 point each (-1pt)
e. Answer fill-in-the blank questions using 1-2 words only. Longer answers will be penalized.
f. Answer essay questions concisely using 1 or 2 sentences. Longer answers will be penalized.
g. WRITE NEATLY. If we cannot read your handwriting, you will receive no credit.
h. Honors section questions only count for credit for students in the honors section
1
Grader Use Only:
#1 (15)
#2 (10)
#3 (10)
#4 (10)
#5 (10)
#6 (7)
#7 (6)
#8 (8)
#9 (5)
#10 (18)
#11 (12)
#12 (11)
Total (122)
# 13 Honors (16)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

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

CMSC

Spring 2007

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 and wait for us to come to you. c. Total point value is 122 points. d. Answer True/False questions by circling the T or F at the end of the question. a. Correct answers to True/False questions receive 1 point each (+1pt) b. Unanswered (blank) True/False questions receive 0 points each c. Incorrect answers to True/False questions are penalized 1 point each (-1pt) e. Answer fill-in-the blank questions using 1-2 words only. Longer answers will be penalized. f. Answer essay questions concisely using 1 or 2 sentences. Longer answers will be penalized. g. WRITE NEATLY. If we cannot read your handwriting, you will receive no credit. h. Honors section questions only count for credit for students in the honors section Grader Use Only: #1 (15) #2 (10) #3 (10) #4 (10) #5 (10) #6 (7) #7 (6) #8 (8) #9 (5) #10 (18) #11 (12) #12 (11) Total (122)

13 Honors (16)

Problem 2 (10 pts) Algorithmic Complexity C. (7 pts) Algorithmic Complexity a. Benchmarking measures # steps used by algorithm T or F b. Asymptotic complexity measures # steps used by algorithm T or F c. Big-O notation represents the minimum # of steps required by an algorithm T or F d. O(n^2 ) algorithms always requires more steps than O(n) algorithms T or F e. (3 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(2n) O(n^2 ) D. (3 pts) Finding Critical Regions Calculate the asymptotic complexity of the code snippets below (using big-O notation) with respect to the problem size n. a. for (int i=2; i b. (8 pts) Given the following Java class definition for a binary search tree, implement the method twoChildVisit that invokes the visit( ) method on nodes in the tree with exactly two children. The nodes must be visited in order , and the method should return the number of such 2-child nodes visited. You may add auxiliary/helper methods public class BinarySearchTree { private class Node { E data; Node left, right; void visit( ) {…} // Method to invoke in order on 2-child nodes } Node root; public int twoChildVisit ( ) { // Method you need to implement }

Problem 5 (10 pts) Graphs F. (2 pts) Graph traversals a. (1 pts) List the set of nodes visited (in the order first visited) while performing a Breadth First Search starting at E. Use alphabetical order to choose the next node to process, when several successors are available. b. (1 pts) List the set of nodes visited (in the order first visited) while performing a Depth First Search starting at E. Use alphabetical order to choose the next node to process, when several successors are available. G. (4 pts) Minimal spanning trees a. (2 pts) Apply Kruskal’s minimum spanning tree algorithm to the above graph. List the edges (e.g., AF) in the minimum spanning tree created, in the order they are added to the tree. b. (2 pts) Apply Prim’s minimum spanning tree algorithm to the above graph starting from vertex A. List the edges of the minimum spanning tree created, in the order they are added to the tree.

A

F

D

B

E

C

1 2 4 5 7 4 2 1 2 A F D C E 18 6 14 B 9 13 4 22 21 33

Problem 7 (6 pts) Multithreading and Synchronization K. (3 pts) Multithreading a. Using multiple threads always improves program performance T or F b. Using multiple threads can simplify the structure of a program T or F c. Using multiple threads may cause intermittent bugs T or F L. (3 pts) Synchronization Consider the following code if several MaybeRace objects are created and multiple threads execute their increment methods in parallel: public class MaybeRace { static int x = 0; Object y = new Object ( ); static Object z = new Object( ); public void inc1( ) { synchronized(y) { x = x + 1; } } public void inc2( ) { synchronized(z) { x = x + 1; } } public synchronized void inc3( ) { x = x + 1; } } a. Using inc1( ) will prevent data races T or F b. Using inc2( ) will prevent data races T or F c. Using inc3( ) will prevent data races T or F Problem 8 (8 pts) Networking M. (8 pts) Networking a. Networks are designed as layers of protocols to improve efficiency T or F b. The internet is composed of a packet layer and a stream layer T or F c. UDP and TCP are protocols that treat data communication as packets T or F d. Network address translation (NAT) is used to find domain names T or F e. Servers may contact clients first T or F f. Clients may contact multiple servers at the same time T or F g. The Java Socket class is used by clients T or F h. The Java DatagramSocket class is used by servers T or F

Problem 9 (5 pts) Graphic User Interfaces N. (5 pts) GUIs a. Model-View-Controller reduces the complexity of GUI implementations T or F b. The View must inform the Model when its state changes T or F c. The Model must inform the View when its state changes T or F d. Java Swing components implement the View and Controller T or F e. Java Swing components react to events through ActionListeners T or F Problem 10 (18 pts) Sorting Algorithms O. (18 pts) Sorting algorithms Sorts include: selection, bubble, tree, heap, quick, merge, counting, bucket, radix. a. (7 pt) Given the list of numbers 345, 543, 111, 676, 943, 343, 223, 512, 752 (in this order), name a sorting algorithm that could yield the following partially sorted list(s) after applying one pass of the algorithm. Any sublists produced by an algorithm are enclosed in curly brackets, e.g., { … }. i. {111}, {223}, {345, 343}, {543, 512}, {676}, {752}, {943} ______ ii. 345, 111, 543, 676, 343, 223, 512, 752, 943 ______ iii. {345, 543, 111, 676, 943}, {343, 223, 512, 752} ______ iv. 111, 543, 345, 676, 943, 343, 223, 512, 752 ______ v. 111, 512, 752, 543, 943, 343, 223, 345, 676 ______ vi. 111, 512, 223, 543, 752, 345, 343, 676, 943 ______ vii. {343, 223, 111}, 345, {543, 676, 943, 512, 752} ______ b. (4 pt) Given the following description of data to be sorted, name a sorting algorithm that would be appropriate for you to implement: i. 20 numbers ______ ii. 20,000 numbers ______ iii. 2 million short strings ______ iv. 200 billion numbers ______

Problem 12 (11 pts) Design Patterns Q. (11 pts) Design patterns a. Design patterns describe solutions to common programming problems T or F b. Design patterns are language independent T or F c. The Factory pattern is a structural design pattern T or F d. The State pattern describes how to save the state of the program T or F Consider the following code for representing the number of rooms in a house. public interface Residence { int rooms( ) } class House implements Residence { int rooms ( ) { return 8; } } class Apartment implements Residence { int rooms ( ) { return 3; } } e. (3 pt) Use the Decorator design pattern to add a ResidenceDecorator class implementing the Residence interface f. (2 pt) Create a ResidenceDecorator ExtraRoom that adds an additional room to a Residence (increases the number of rooms by 1) g. (2 pt) Use the ExtraRoom decorator to create an Apartment object with 2 extra rooms

Problem 13 (16 pts) Advanced Tree Structures (Honors Section Only) R. (11 pts) Advanced search trees a. Self-balancing trees perform rotations to avoid degeneracy T or F b. Self-balancing trees are always faster than standard search trees T or F c. AVL trees ensure left and right subtrees are close to balanced T or F d. All red-black trees are not AVL trees T or F e. Red-black trees perform at most 5 rotations after each insertion T or F f. All rotations are performed in O(1) steps T or F g. All insertions in self-balancing trees are performed in O(log(n)) steps T or F h. Multi-way search trees require only pairwise comparisons between keys T or F i. Multi-way search trees may split nodes during insertion T or F j. (2 pts) Draw the following tree after a left rotation around the node Y S. (5 pts) Indexed search trees a. Indexed search trees require only pairwise comparisons between keys T or F b. Suffix tries are larger than normal tries for a given string T or F c. Compact tries are smaller than compressed tries for a given string T or F d. (2 pts) Draw the suffix trie for the string “abbab” D K A M = N Z Y C E