Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

Related documents


Partial preview of the text

Download Software Development and Object-Oriented Design - Quiz Questions and more Exams Computer Science in PDF only on Docsity! 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 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 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(n2) 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=i*2) { f(n) = O( nlog(n) ) for (j = 1; j < n; j++) { ... } } b. for (i = 0; i < n-2; i++) { f(n) = O( n2 ) for (j = 0; j < n; j=j*2) { for (k = 1; k < 5000; k=k*5) { ... } 2 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 HD C G S 10 14 12 8 16 13 5 7 4 15 9 6 3 11 5 S, A, B, F, D, C, E, H, G S, cost = 0 S->A, cost = 10 S->B, cost = 14 S->B->F, cost = 18 S->A->D or S->B->D, cost = 22 S->A->C, cost = 26 S->A->D->E or S->B->D->E, cost = 28 S->B->F->H, cost = 29 S->A->D->E->G or S->B->D->E->G, cost = 33 S A B C D E F G H LowestCost 0 10 14 26 22 28 18 33 29 Predecessor none S S A A or B D B E F Problem 5 Compression & Huffman Codes K. Compression a. What are two sources of compressibility? Redundancy & human perception b. What are two types of compression? Lossy & lossless c. What is a prefix code? No prefix of a code appears as another code d. What are Huffman codes? Binary prefix code based on symbol frequencies e. How do Huffman codes achieve compression? Taking advantage of redundancy of frequently appearing symbols f. Given the following Huffman tree, decode the sequence “00110010” AASAR 6 T R S A 1 1 1 0 0 0 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? 7 } } 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? 10 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(n2) 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(n2) ii. tree sort O(n2) 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 11 V. Algorithm strategies a. What is divide-and-conquer? Type of algorithm that divides problem into smaller problems of the same type and recursively solves them, combining their solutions for overall solution b. What is dynamic programming? Type of algorithm that divides problem into smaller overlapping problems of the same type and recursively solves them, remembering previous solutions to subproblems. c. What is the difference between divide-and-conquer and dynamic programming? Dynamic programming remembers solutions to subproblems, divide-and- conquer resolves subproblems d. What is the difference between recursive and backtracking algorithms? Backtracking algorithms may use recursion to implement backtracking e. What is the difference between a greedy algorithm and heuristics? Greedy algorithms achieve optimal solutions by selecting best (local) choice at each step. Heuristics use rules of thumb (such as greedy) to make a choice at each step, but are not guaranteed to achieve the best solution f. What is the difference between brute force and branch-and-bound algorithms? Branch-and-bound algorithms attempt to reduce searching by eliminating partial solutions that are already worse than the best current solution found g. List a reason to use dynamic programming Improve efficiency by avoiding repeating work h. List a reason to use backtracking Simple approach to searching for all possible solutions i. List a reason to use a brute force algorithm Need optimal solution but more efficient algorithms not known j. What type of algorithm is Kruskal’s algorithm for finding minimum spanning trees? Greedy Problem 11 Design Patterns W. Design patterns a. What is a design pattern? Descriptions of reusable solutions to common software design problems b. How were design patterns discovered? Programmers found certain problems were solved repeatedly c. When are design patterns used? When common software design problems are encountered that have been previously solved d. List 5 components of a design pattern e. List 3 types of design patterns. Give 2 example patterns for each type. f. What type of design pattern is the factory pattern? Visitor pattern? g. Write a Java example of the Singleton pattern h. Write a Java example of the Factory pattern 12
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved