






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







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):
Grader Use Only: #1 (20) #2 (20) #3 (20)
#4 (20) #5 (20) #6 (20) #7 (20)
#8 (20)
#9 (20) #10 (20)
Total (200)
Honors (20)
Problem 1 Software Engineering & Object Oriented Design (20 pts)
A. (4 pts) Software engineering a. What is the main reason many software projects fail? b. What is the software life cycle? c. According to the waterfall model, design all algorithms before coding T or F d. According to the unified model, design all algorithms before coding T or F e. What is the difference between program verification and empirical testing?
B. (4 pts) Object-oriented design a. State, behavior, and identity are the main qualities of objects T or F b. Object oriented design produces faster programs T or F c. What are two main principles of object-oriented design?
C. (4 pts) Object-oriented design II. Given the following problem description, produce an object- oriented solution. Answer the following questions about your object-oriented solution.
Design a simulation of a basketball conference. Each conference has 10 teams. Each team has 12 players. Each player has a specific height, speed, and accuracy. Players know which team they belong to. Some players are scholarship players. Scholarship players need to record their current grade-point average. Players may be transferred between teams. Teams play basketball games against other teams in the conference. The result of each game is determined using a function based on the height, strength, speed, and accuracy of the players on each team.
a. What are the objects in your object-oriented solution? b. What are the interactions between your objects? c. Which objects “have” other objects? (Also list target object) d. Which objects “use” other objects? (Also list target object) e. Which objects “are” other objects? (Also list target object)
b. for (i = 0; i < n-2; i++) { f(n) = O( ) for (j = 0; j < n; j=j2) { for (k = 1; k < 5000; k=k5) { ... } } for (j = 0; j < 1000*n; j=j+1) { ... } for (j = 0; j < n/5; j=j+5) { ... } }
Problem 3 Data Structures and Recursion (20 pts)
G. (4 pts) Taxonomy & properties a. Describe the main difference between linear and hierarchical data structures b. What is the key property of a binary search tree? c. On average, what is the complexity of doing an insertion in a binary search tree? d. Pre-order, in-order, and post-order are all depth-first traversals T or F e. What operation(s) supported by binary search trees are not supported by heaps? f. What is the difference between a set and a map? g. What happens when an open addressing hash table is close to full? h. Describe the 2 main parts of a recursive algorithm
Problem 4 Graph Algorithms (20 pts)
H. (4 pts) Properties a. Describe the main difference between hierarchical and graph data structures b. Describe the difference between a directed and undirected graph c. Describe the difference between a path and a cycle d. Describe two methods of storing edges in a graph e. Which method of storing edges in a graph requires more space?
I. (4 pts) Traversals a. Why is graph traversal more difficult than a tree traversal? b. Describe the difference between a breadth-first and depth-first traversal of a graph c. Given the following Java class definition for a graph
public class Node { Object myValue; boolean tag; ArrayList
public class myGraph { ArrayList
Write code for deptFirstSearch( n ) to perform a depth first traversal of nodes in the graph, invoking visitNode( ) for each node once
J. (4 pts) Minimum spanning trees a. What is a spanning tree? b. Describe Kruskal’s algorithm for finding minimum spanning trees c. Describe two methods for finding connected subgraphs d. Consider the following graph. Using Kruskal’s algorithm, calculate the minimum spanning tree, listing edges in the minimal spanning tree in the order they are added to the tree.
g. Using the same Huffman tree, encode the string “arts” as a sequence of 0’s and 1’s h. Given the following symbol frequencies, create a Huffman tree for the symbols A = 5, B = 8, C = 4, D = 6, E = 7
Problem 6 Advanced Tree Structures (20 pts)
M. (4 pts) Indexed search trees a. What is the motivation for using an indexed search tree (trie)? b. What is a compressed trie? c. What is a compact trie? d. What is a suffix trie? e. Draw the suffix trie for the string “google”
N. (4 pts) Balanced search trees a. What is the motivation for using balanced search trees? b. Name two algorithms for maintaining balanced search trees c. What is the mechanism used to balance search trees? d. Given the following binary search tree, draw the tree resulting from performing a single right rotation around the node X e. For the same search tree, draw the tree resulting from performing a single left rotation around the node X
O. (4 pts) Multi-way search trees a. What is the motivation for using multi-way search trees? b. What is a 2-3 tree? c. Describe the algorithm for finding items in a 2-3 tree d. Given the following 2-3 tree, draw the tree resulting from inserting the value 11.
e. Given the same 2-3 tree, draw the tree resulting from inserting the value 22.
Problem 7 Java Language Features (20 pts)
P. (4 pts) Regular expressions in Java a. What are regular expressions? b. What is the motivation for using regular expressions? c. Given the following Java code fragment using java.util.regex:
Pattern p = Pattern.compile(“[a-z]+”); Matcher m = p.matcher(“a0 ab5 42 cd ef13”); while (m.find()) { System.out.print(m.group() + “\n”); }
What will be printed out when the code is executed?
d. Given the following Java code fragment using java.util.regex:
Pattern p = Pattern.compile(“[a-z0-9]+”); Matcher m = p.matcher(“a0 ab5 42 cd ef13”); while (m.find()) { System.out.print(m.group() + “\n”); }
What will be printed out when the code is executed?
Problem 8 Multithreading & Synchronization (20 pts)
S. (4 pts) Multithreading a. What is the motivation for writing multithreaded Java code? b. What are possible states for Java threads? c. What is the effect of invoking the start( ) method of the Thread class? d. What is scheduling? e. What is the difference between preemptive and non-preemptive scheduling? f. What are data races? g. Why should programs avoid data races?
T. (4 pts) Synchronization& deadlocks a. What is synchronization? b. Why should programs use synchronization? c. What are Java locks? d. What are deadlocks? e. Why should programs avoid deadlocks? f. What are Java wait( ) and notify( ) methods? g. What is the effect of invoking the wait( ) method?
U. (4 pts) Multithreading code Consider the following code:
public class mySet { List myElements = new ArrayList( );
public boolean add( Object o ) { myElements.add( o ); }
public Object remove( ) { if (myElements.isEmpty( ) == false) return myElements.remove( 0 ); // removes & returns object at position 0 return null; } }
a. What may happen if an object of the class mySet is used by multiple threads calling add( ) and remove( ) at the same time? b. Change the add( ) and remove( ) methods so that the class mySet can be safely used by multiple threads at once. c. Change the add( ) and remove( ) methods so that the method remove( ) will always return an object when used by multiple threads (by waiting until an object has been added).
Problem 9 Design Patterns (20 pts)
V. (4 pts) Definitions and properties a. What are design patterns? b. What is the difference between a design pattern and an API? c. What are creational design patterns? d. List 2 structural design patterns e. What is the factory design pattern used for? Why? f. What is the visitor design pattern used for? Why? g. List 2 examples of design patterns used in the Java class libraries h. Given the following code, complete the code for a BoatFactory class so it can be used to create big and small boat objects:
public interface Boat { int maxCapacity; int topSpeed( ) }
class CruiseShip implements Boat { // big boat int topSpeed( ) { return 20; } }
class SpeedBoat implements Boat { // small boat int topSpeed( ) { return 40; } }
Boat myBigBoat = BoatFactory.create(“big”); Boat mySmallBoat = BoatFactory.create(“small”);
public class BoatFactory { static Boat create(String s) { … // your code here } }
i. Using the same code, use the Decorator design pattern to i. Add a BoatDecorator class implementing the Boat interface ii. Create two BoatDecorators withBarnacle( ) and withTurboEngine( ) that change the result returned by topSpeed( ) by –1 and +10, respectively iii. Use BoatDecorators to create a Boat object for a SpeedBoat with 2 barnacles and 1 turbo engine whose topSpeed( ) method returns 48.