Software Development and Object-Oriented Design - Quiz Questions, Exams of Computer Science

A series of true or false and multiple choice questions related to software development, problem specification, iterative development, object-oriented design, and data structures. Topics include software life cycle, problem specification importance, iterative development methodology, object-oriented design principles, binary search trees, and minimum spanning trees.

Typology: Exams

Pre 2010

Uploaded on 02/13/2009

koofers-user-021
koofers-user-021 🇺🇸

10 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC132
Partial Solutions to Final Exam Practice Questions
Problem 1 Software Engineering & Object Oriented Design
A. Software Development and Testing
a. Software is difficult because programmers are slow T or F
b. Software life cycle refers to how software is used T or F
c. Problem specification is a component of software development T or F
d. Problem specification is less important than program testing T or F
e. Iterative development is a software development methodology T or F
f. Black box testing is usually easier than clear box testing T or F
g. Integration tests are usually more important than unit tests T or F
h. Test coverage includes consideration of lines of code tested T or F
i. Test drivers are only found on NASCAR training tracks T or F
B. 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. List two main principles of object-oriented design? Abstraction & encapsulation
d. Inheritance describes a relationship between classes T or F
e. Inheritance discourages code reuse T or F
f. Extension is a form of inheritance T or F
C. 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?
Conference, Team, Player, ScholarshipPlayer
b. What are the interactions between your objects?
Play Game, Transfer
c. Which objects “have” other objects? (Also list target object)
Conferences have Teams, Teams have Players,
d. Which objects “use” other objects? (Also list target object)
None
e. Which objects “are” other objects? (Also list target object)
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Software Development and Object-Oriented Design - Quiz Questions and more Exams Computer Science in PDF only on Docsity!

CMSC

Partial Solutions to Final Exam Practice Questions

Problem 1 Software Engineering & Object Oriented Design A. Software Development and Testing a. Software is difficult because programmers are slow T or F b. Software life cycle refers to how software is used T or F c. Problem specification is a component of software development T or F d. Problem specification is less important than program testing T or F e. Iterative development is a software development methodology T or F f. Black box testing is usually easier than clear box testing T or F g. Integration tests are usually more important than unit tests T or F h. Test coverage includes consideration of lines of code tested T or F i. Test drivers are only found on NASCAR training tracks T or F B. 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. List two main principles of object-oriented design? Abstraction & encapsulation d. Inheritance describes a relationship between classes T or F e. Inheritance discourages code reuse T or F f. Extension is a form of inheritance T or F C. 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? Conference, Team, Player, ScholarshipPlayer b. What are the interactions between your objects? Play Game, Transfer c. Which objects “have” other objects? (Also list target object) Conferences have Teams, Teams have Players, d. Which objects “use” other objects? (Also list target object) None e. Which objects “are” other objects? (Also list target object)

ScholarshipPlayers are Players f. Draw a UML diagram of your solution. Team myPlayers[12] : Player playGame() Conference myTeams[10] : Team (^) Player myTeam : Team height speed accuracy transfer() ScholarshipPlayer GPA 10 1 12 Team myPlayers[12] : Player playGame() Conference myTeams[10] : Team (^) Player myTeam : Team height speed accuracy transfer() ScholarshipPlayer GPA 10 1 12 Problem 2 Algorithmic Complexity D. Algorithmic complexity a. What is algorithmic complexity? Amount of resources required by algorithm with respect to problem size b. List a reason benchmarking is better than analyzing complexity Measures performance for a particular hardware c. What is the difference between best case, worst case, and average case? Minimum, maximum, and typical number of steps required by algorithm d. What does the Big-O notation represent? Upper bound on the number of steps required by algorithm e. Why are O(n^2 ) and O(n) not considered equivalent? The number of steps required by each algorithm grows at a different rate with respect to the problem size E. 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=i2) { f(n) = O( nlog(n) ) for (j = 1; j < n; j++) { ... } } b. for (i = 0; i < n-2; i++) { f(n) = O( n^2 ) for (j = 0; j < n; j=j2) { for (k = 1; k < 5000; k=k*5) { ... }

Breadth-first visits closer neighbors first, depth-first finishes exploring all reachable nodes from current node first c. Given the following Java class definition for a graph public class MyGraph { public class Node { E myValue; boolean tag; ArrayList myNeighbors; } ArrayList myNodes; void visitNode(Node n) {/* Action to be performed when traversing node /} void deptFirstSearch(Node n) { / Perform depth-first search of graph starting at n */ } } i. Write code for the method depthFirstSearch( n ) that performs a depth first traversal starting at node n. ii. Write code for the method breadthFirstSearch(n) that performs a breadth first traversal starting at node n. I. Minimum spanning trees a. What is a spanning tree? Tree connecting all nodes in graph (no cycles, n-1 edges) b. Describe Kruskal’s algorithm for finding minimum spanning trees Sort edges by weight, continue adding remaining edge with lowest weight if does not create cycle, until spanning tree formed c. Describe Prim’s algorithm for finding minimum spanning trees d. Describe two methods for finding connected subgraphs Traverse graph looking for cycle, or track connected subgraphs e. Consider the following graph. Using both Prim’s and Kruskal’s algorithm, calculate the minimum spanning tree, listing edges in the minimal spanning tree in the order they are added to the tree. Kruskal - (E,H), (B,F), (E,G), (D,E), (D,F), (C,G), (S,A), (A,D)

J. Single source shortest path a. Describe Djikstra’s algorithm for finding shortest paths in a graph Maintain set of nodes with known shortest path from start (and their costs & predecessors), repeatedly add node closest to set (updating table of costs & predecessors) until all nodes in set. b. Consider the previous graph. Apply Djikstra’s algorithm for this graph to calculate the shortest path from S to every other node. Store intermediate results in the table BestKnownDistances. Show the entries in the table after you finish computing the shortest distance from S to nodes in the set {S, A, B}. Table BestKnownDistances S A B C D E F G H LowestCost 0 10 14 26 22 infinity 18 infinity infinity Predecessor none S S A A or B none B none none c. Which node would be processed next using Djikstra’s algorithm? F d. Update the table BestKnownDistances after adding this node. S A B C D E F G H LowestCost 0 10 14 26 22 infinity 18 infinity 29 Predecessor none S S A A or B none B none F e. Using Djikstra’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.

A E

B F

H

D

C G

S

g. Using the same Huffman tree, encode the string “arts” as a sequence of 0’s and 1’s 010111110 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 L. Java Inner Classes a. What are inner classes? Classes defined in the scope of another class b. What are nested classes? Static inner classes c. When should inner classes be used? To define classes that need to access private members of enclosing class d. When should anonymous inner classes be used? When name of inner class is not needed because it is used only once e. Write an example anonymous inner class in Java. M. Java support for Object-Oriented programming a. The equals( ) method in Java is typically used to test for name equivalence T or F b. All non-static initialization blocks are executed when objects are created T or F c. Code in initialization blocks are executed at the end of every constructor T or F d. If no visibility modifier is specified, methods are private by default T or F e. Protected access is less visible than package access T or F N. Exceptions in Java a. What are exceptions? Run-time errors detected during program execution b. How are exceptions used in Java? To represent run-time errors found by Java c. What should be made an exception in Java? Serious run-time errors (should be made unchecked exceptions) and common errors the program can handle (should be made checked exceptions) d. What are the differences between try, catch, and finally in Java? Try surrounds code that may cause exception, catch specifies exceptions caught and action performed, finally specifies action performed after try block exits (whether an exception is thrown or not) e. What is the difference between checked and unchecked exceptions?

The Java compiler attempts to require all checked exceptions to be caught at some point in the Java program. f. 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”); } } What will be printed for the following method calls?

  1. f(1) ABD
  2. f(0) ACD O. (4 pts) Cloning and serialization in Java a. What is cloning? Creating an identical copy of an object b. What is the relationship between clone( ) and the == operator? A cloned object is not equivalent to the original when compared with == c. What is the relationship between clone( ) and equals( )? A cloned object should be equivalent to the original when compared with equals( ) d. What is serialization? Converting a graph of Java objects into a stream of data e. What is serialization used for? Provide persistence, copy, or communicate a graph of Java objects f. What is the difference between making a shallow copy versus making a deep copy? Shallow copy copies the object only, deep copy copies the object and all objects referred to by the object Problem 7 Multithreading & Synchronization (20 pts) P. Multithreading a. What is the motivation for writing multithreaded Java code? Capture logical structure of problem, better utilize hardware resources b. What are possible states for Java threads? New, Runnable, Running, Blocked, Dead c. What is the effect of invoking the start( ) method of the Thread class?

a. What may happen if an object of the class mySet is used by multiple threads calling add( ) and remove( ) at the same time? Data race on shared variable myElements b. Change the add( ) and remove( ) methods so that the class mySet can be safely used by multiple threads at once. Add synchronized keyword to both methods 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 Networking & Networking Support in Java S. Networking a. What are protocols? A formal description of formats and rules b. What is the internet? A combination of multiple layers of networking protocols c. What are packets? A fixed-size piece of data (with header information & actual data) d. What is IP? UDP? TCP/IP? All 3 are protocols: Internet Protocol, User Datagram Protocol, Transmission Control Protocol e. What is a socket? Port? URL? All three are abstractions: application-level abstraction of network connection (socket), abstraction of destination at IP address (port), abstraction of web resource (Uniform Resource Locator) f. What is the difference between reliable and unreliable network connections? Reliable network connections send data in order & report lost data g. How can a reliable connection be built on top of an unreliable network? Using a protocol based on round-trip communication between sender/receiver h. What is a server? Client? Server waits for communication and provides services, client initiate communication and requests services i. What is the difference between Java Socket, ServerSocket, and DatagramSocket? Java socket connections using TCP (client) or TCP (server), vs. UDP j. How is data transported across a Java Socket? Across a DatagramSocket? Using TCP vs. UDP Problem 9 Graphic User Interfaces T. GUIs and MVC a. In a GUI, what is the model? The view? The controller?

Model is the data, View is what is displayed, Controller is used by user to interact with the model & view b. Why should they be kept separate? Reduce complexity of software c. What are events? External events that occur outside the control of the program that must be handled by the program d. Why are events used in GUIs? To represent user actions e. How are events handled in the Java Swing library? Events are generated by individual components (e.g., JButton) and handled using ActionListeners registered for the component Problem 10 Sorting & Algorithm Strategies U. Sorting algorithms a. What is a comparison sort? Sorting algorithm using only pairwise key comparisons b. When is a sorting algorithm not a comparison sort? Depends on qualities beyond pairwise key comparisons (e.g., alls keys have values between X and Y) c. What is a stable sort? Sorting algorithm leaves relative order of keys with equal value unchanged d. What is an in-place sort? Sorting algorithm only needs small constant amount of additional space e. What is an external sort? Sorting algorithm is designed for efficiency when keys do not all fit in memory (i.e., very large number of keys) f. What is the average case complexity of sorting using i. bubble sort O(n^2 ) ii. heap sort O(nlog(n)) iii. quick sort O(nlog(n)) iv. counting sort O(n+k) for keys from 1..k g. What is the worst case complexity of sorting using i. selection sort O(n 2 ) ii. tree sort O(n 2 ) iii. heap sort O(nlog(n)) iv. radix sort O(d(n+k)) for keys = d components from 1..k h. Can the following sort be performed in a stable manner? i. bubble sort No ii. quick sort No (stable version would require extra memory) iii. counting sort Yes i. Can the following sort be performed using an in-place algorithm? i. selection sort Yes ii. tree sort No iii. merge sort No

i. Write a Java example of the Visitor pattern. j. List 2 examples of design patterns used in the Java class libraries Iterator, Decorator, Marker, Observer k. 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 if (s.equals(“big”)) return new CruiseShip( ); else if (s.equals(“small”)) return new SpeedBoat( ); else return null; // error } } l. Using the same code, use the Decorator design pattern to i. Add a BoatDecorator class implementing the Boat interface public class BoatDecorator implements Boat { Boat b; BoatDecorator (Boat b) { this.b = b; } int topSpeed( ) { return b.topSpeed( ); } } ii. Create two BoatDecorators withBarnacle( ) and withTurboEngine( ) that change the result returned by topSpeed( ) by –1 and +10, respectively

public class withBarnacle( ) extends BoatDecorator { int topSpeed( ) { return b.topSpeed( ) - 1; } } public class withTurboEngine( ) extends BoatDecorator { int topSpeed( ) { return b.topSpeed( ) + 10; } } iii. Use BoatDecorators to create a Boat object for a SpeedBoat with 2 barnacles and 1 turbo engine whose topSpeed( ) method returns 48. Boat myBoat = new withBarnacle( new withBarnacle( new withTurboEngine( new SpeedBoat( ) ) ) ); Problem 12 Effective Java X. Effective Java a. Give 3 examples of possibly confusing Java features. hashCode( ) contract, overloading + operator, ambiguous overloading methods, floats for decimals, private subclass fields b. Write an example of potentially confusing Java code. c. Name 2 approaches to Java programming styles that avoids confusing Java features. avoiding ambiguous overloading methods, using ints decimals, avoiding public fields d. Give an example of potentially confusing Java code, and how to avoid it Problem 13 Advanced Tree Structures (Honors Section Only) Y. Indexed search trees a. What is the motivation for using an indexed search tree (trie)? Fast searches for keys that can be decomposed (with redundancy) b. What is a compressed trie? Multiple connecting single edge chains are compressed into single edge c. What is a compact trie? Nodes store indices into original text, rather than key d. What is a suffix trie? A trie of all suffixes of each key e. Draw the suffix trie for the string “google” Z. (4 pts) Balanced search trees a. What is the motivation for using balanced search trees? Avoid worst case O(n) behavior for find/insert/delete operations b. Name two algorithms for maintaining balanced search trees AVL & Red-Black c. What is the mechanism used to balance search trees? Rotation d. Given the following binary search tree, draw the tree resulting from performing a single right rotation around the node X