Docsity

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

Toggle sidebar
bg1
1
CMSC132
Final Exam Practice Questions
Problem 1 Software Engineering & Object Oriented Design
A. 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?
B. 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)
Problem 2 Algorithmic Complexity
C. Algorithmic complexity
a. What is algorithmic complexity?
b. List a reason benchmarking is better than analyzing complexity
c. What is the difference between best case, worst case, and average case?
d. What does the Big-O notation represent?
e. Why are O(n
2
) and O(n) not considered equivalent?
D. 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 (i = 0; i < n; i=i*2) { f(n) = O( )
pf3
pf4
pf5

Partial preview of the text

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

CMSC

Final Exam Practice Questions

Problem 1 Software Engineering & Object Oriented Design

A. 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?

B. 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)

Problem 2 Algorithmic Complexity

C. Algorithmic complexity a. What is algorithmic complexity? b. List a reason benchmarking is better than analyzing complexity c. What is the difference between best case, worst case, and average case? d. What does the Big-O notation represent? e. Why are O(n 2 ) and O(n) not considered equivalent?

D. 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 (i = 0; i < n; i=i*2) { f(n) = O( )

for (j = 1; j < n; j++) { ... } }

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

E. 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

F. 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?

G. 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 MyGraph {

Table BestKnownDistances

S A B C D E F G H LowestCost Predecessor

c. Which node would be processed next using Dijkstra’s algorithm? d. Update the table BestKnownDistances after adding this node. e. Using Dijkstra’s algorithm, calculate the shortest path (and its cost) from S to every other vertex in the graph. List vertices in the order they are added to the table BestKnownDistances.

Problem 5 Compression & Huffman Codes

J. Compression a. What are two sources of compressibility? b. What are two types of compression? c. What is a prefix code? d. What are Huffman codes? e. How do Huffman codes achieve compression? f. Given the following Huffman tree, decode the sequence “00110010”

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 Java Language Features

T

R

S

A

1

1

1

0

0

0

K. 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?

e. Given the following Java code fragment using java.util.regex:

Pattern p = Pattern.compile(“[a-z]+[0-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?

L. Exceptions in Java a. What are exceptions? b. How are exceptions used in Java? c. What should be made an exception in Java? d. What are the differences between try, catch, and finally in Java? e. Given the following code

public static void f( int y ) { try { System.out.print(“A”); int x = 1 / y ; // generates ArithmeticException if y == 0 System.out.print(“B”); } catch (ArithmeticException e) { System.out.print(“C”); } finally { System.out.print(“D”);

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 8 Sorting & Algorithm Strategies

P. Sorting algorithms a. What is a comparison sort? b. When is a sorting algorithm not a comparison sort? c. What is a stable sort? d. What is an in-place sort? e. What is an external sort? f. What is the average case complexity of sorting using i. bubble sort ii. heap sort iii. quick sort iv. counting sort g. What is the worst case complexity of sorting using i. selection sort ii. tree sort iii. heap sort iv. radix sort h. Can the following sort be performed in a stable manner? i. bubble sort ii. quick sort iii. counting sort i. Can the following sort be performed using an in-place algorithm? i. selection sort ii. tree sort iii. merge sort