CMSC132, Practice Questions

Similar documents
R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

Prelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader

University of Maryland College Park Dept of Computer Science

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

INSTITUTE OF AERONAUTICAL ENGINEERING

Computer Science E-22 Practice Final Exam

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Total Score /1 /20 /41 /15 /23 Grader

Summer Final Exam Review Session August 5, 2009

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Prelim 2. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Data Structures Brett Bernstein

CS/ENGRD2110: Final Exam

AP Computer Science 4325

Table of Contents. Chapter 1: Introduction to Data Structures... 1

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

Prelim 2 SOLUTION. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

Prelim 2, CS2110. SOLUTION

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CS 445: Data Structures Final Examination: Study Guide

University of Maryland College Park Dept of Computer Science

MLR Institute of Technology

CS61BL. Lecture 5: Graphs Sorting

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

Prelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

2. (a) Explain when the Quick sort is preferred to merge sort and vice-versa.

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Programming II (CS300)

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

Course Review for Finals. Cpt S 223 Fall 2008

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

York University AK/ITEC INTRODUCTION TO DATA STRUCTURES. Final Sample II. Examiner: S. Chen Duration: Three hours

a graph is a data structure made up of nodes in graph theory the links are normally called edges

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

Programming II (CS300)

CS521 \ Notes for the Final Exam

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

: Advanced Programming Final Exam Summer 2008 June 27, 2008

CS2013 Course Syllabus Spring 2017 Lecture: Friday 8:00 A.M. 9:40 A.M. Lab: Friday 9:40 A.M. 12:00 Noon

DYNAMIC MEMORY ALLOCATION AND DEALLOCATION

Total Score /15 /20 /30 /10 /5 /20 Grader

DIT960 Datastrukturer

Department of Computer Science and Technology

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

UCS-406 (Data Structure) Lab Assignment-1 (2 weeks)

CS6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK UNIT I

CS301 - Data Structures Glossary By

Course Review. Cpt S 223 Fall 2009

Prelim 2 SOLUTION. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

Lecture Summary CSC 263H. August 5, 2016

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

Info View Practice Test

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

EXAMINATIONS 2016 TRIMESTER 2

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING ADVANCED DATA STRUCTURES AND ALGORITHMS EXAM EXAMINATION JUNE 2014

TREES. Trees - Introduction

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 25: Review and Open Problems

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

INF2220: algorithms and data structures Series 1

CSE 373: Practice Final

Total No. of Questions : 18] [Total No. of Pages : 02. M.Sc. DEGREE EXAMINATION, DEC First Year COMPUTER SCIENCE.

( ) 1 B. 1. Suppose f x

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)

Visit ::: Original Website For Placement Papers. ::: Data Structure

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: CS6402- Design & Analysis of Algorithm Year/Sem : II/IV UNIT-I INTRODUCTION

CSE373 Fall 2013, Midterm Examination October 18, 2013

D.K.M.COLLEGE FOR WOMEN (AUTONOMOUS), VELLORE-1.

Course Review. Cpt S 223 Fall 2010

CS 314 Final Fall 2012

Computer Algorithms. Introduction to Algorithm

Topics for CSCI 151 Final Exam Wednesday, May 10

Programming II (CS300)

CS302 Data Structures using C++

DS ata Structures Aptitude

Big Java Late Objects

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

CSC 207 (17fa) Practice Final Page 1 of 19. Practice Final

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

CS171 Final Practice Exam

Prelim 2. CS 2110, 24 April 2018, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph.

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

Recitation 9. Prelim Review

n 2 ( ) ( ) + n is in Θ n logn

Data Structures Question Bank Multiple Choice

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

namibia UniVERSITY OF SCIEnCE AnD TECHnOLOGY

CS2110 Assignment 3 Inheritance and Trees, Summer 2008

Transcription:

CMSC132, Practice Questions Notice the final exam can include material not covered by the practice questions. You should practice beyond what is covered in this document. Although solutions will not be provided, you are welcome to discuss your solutions with TAs or instructors. Problem 1 (Software Development & Testing) 1. What is the main reason many software projects fail? a. Poorly trained programmers b. Insufficient project funding c. Complexity of projects d. Slow computers e. Insufficient computer memory 2. What is the software life cycle? 3. What is the first phase of the software life cycle? a. Testing b. Coding c. Design d. Specification e. Documentation 4. True or False According to the waterfall model a. Design all algorithms before coding b. Write test cases before coding c. Use prototype implementation to refine design 5. True or False According to the unified model a. Design all algorithms before coding b. Write test cases before coding c. Use prototype implementation to refine design 6. True or False Compared to program verification, empirical testing a. Handles larger programs b. Always catches more errors c. Ensures code is correct d. Can be applied without examining code

7. Given the following problem description, produce an 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 (Trees) 1. Binary search trees (BST) a. What is the key property of a binary search tree? b. On average, what is the complexity of doing an insertion in a binary search tree? c. On average, what is the complexity of doing a find in a binary search tree? d. What is the worst-case complexity of doing a find in a binary search tree? e. What can cause worst-case behavior in a binary search tree? 2. Binary search trees examples a. Draw the binary search tree created when the following values are inserted in order: 6, 5, 2, 8, 10, 3 b. Given the previous BST, draw the tree created when the node 5 is removed 3. Traversals a. What is a tree traversal? b. What is the difference between a depth-first and breadth-first traversal? c. Pre-order, in-order, and post-order are all depth-first traversals T or F d. Pre-order traversals are faster than post-order traversals T or F e. For the following binary tree, provide an example of a i. Preorder traversal ii. Postorder traversal iii. Breadth-first traversal 1 5 4 2 2 3

4. Given the following Java class definition for a binary tree public class BinarySearchTree <K extends Comparable<K>, V> { private class Node { private K key; private V data; private Node left, right; public Node(K key, V data) { this.key = key; this.data = data; private Node root; Write the following code: a. find(k key) Use a recursive algorithm to find a node with a key value that corresponds to key in tree b. treeheight( ) Use a recursive algorithm to find the height of a tree c. preorderprint( ) Use a recursive algorithm to print the key and data for each node using a preorder traversal of the tree, starting from the root. d. submap(k lower, K upper) Use a recursive algorithm to implement a method that returns a BinarySearchTree with elements that have a key value between lower (inclusive) and upper (inclusive). e. retrieveleaves(map<k,v> map) Use a recursive algorithm to implement a method that initializes the map with elements that are leaf nodes. The leaves must be removed from the original tree. f. size() Implement the size method without using recursion. g. thread() Add an additional Node reference (e.g., Node thread) to the BinarySearchTree and implement a method that threads the tree based on different criteria. For example, given a tree, the thread() method can set the thread reference of every node to point to the next element in an inorder traversal. Problem 3 (Heaps) 1. Properties & characteristics a. What are two key properties of a heap? b. What operation(s) supported by binary search trees are not supported by heaps? c. On average, what is the complexity of doing an insertion in a heap? d. On average, what is the complexity of doing a find in a heap? e. How can heaps be stored in a compact array representation? f. Why are heaps used to implement priority queues? 2. Examples a. Draw the heap created when the following values are inserted in order: 6, 5, 2, 8, 10, 3 b. Given the previous heap, draw the heap produced when the smallest value is removed c. Show the tree representation of the following heap (in array representation) A, B, C, D, E, F d. Show the array representation of the following heap (in tree representation) 2 6 2 8 4 2

Problem 4 (Algorithmic Complexity) 1. 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? 2. 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 = 1; 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 = j * 2) { for (k = 1; k < 5000; k = k * 5) {... for (j = 0; j < 1000 * n; j = j + ) {... for (j = 0; j < n / 5; j = j + 5) {...

Problem 5 (Graphs) 1. Properties a. Describe the difference between a directed and undirected graph b. Describe the difference between a path and a cycle c. Describe two methods of storing edges in a graph. Which requires more space? 2. 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<E> { public class Node<E> { E myvalue; boolean tag; ArrayList<Node> myneighbors; ArrayList<Node> 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. 3. Graph traversals A F C D E a. Give two different possible orders in which the nodes of this graph could be visited in performing a breadth-first search (BFS) starting at node A. Note: there may be more than two possible orders that BFS could visit the nodes; you only have to give two orders. b. Give two different possible orders in which the nodes of this graph could be visited in performing a depth-first search (DFS) starting at node A. Note: there may be more than two possible orders that DFS could visit the nodes; you only have to give two orders.

4. Single source shortest paths 8 C 1 A 2 E 2 3 7 B 5 D Apply Dijkstra s algorithm using A as the starting (source) node. Indicate the cost and predecessor for each node in the graph after processing two nodes (A and another node). Remember to update the appropriate table entries after processing a node (after it has been added to the set of processed nodes). An empty table entry implies an infinite cost or no predecessor. After processing the first node. Write the name of the node you are processing here: A Node A B C D E Cost Predecessor After processing the second node. Write the name of the node you are processing here: Node A B C D E Cost Predecessor

Problem 6 (Java Language Features) 1. Java Inner Classes a. What are inner classes? b. What are nested classes? c. When should inner classes be used? d. When should anonymous inner classes be used? e. What relationship exists between lambda expressions and anonymous inner class? f. Write an example anonymous inner class in Java. 2. Java support for Object-Oriented programming a. All non-static initialization blocks are executed when objects are created T or F b. Code in initialization blocks are executed at the end of every constructor T or F c. If no visibility modifier is specified, methods are private by default T or F d. Protected access is less visible than package access T or F 3. Generics a. What are the advantages of using generics? b. Define a class that implements a double-ended queue (dequeue) for integer values. Modify the class so it becomes a generic class. 4. Lambda Expressions a. What is a lambda expression? b. Write a lambda expression for the Runnable interface. The run() method will print even values between 1 and 100. c. What property must an interface have in order to be used with a lambda expression? d. Provide a listener (e.g., for a JavaFX button) that relies on an inner class, an anonymous inner class, and a lambda expression. 5. 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. What is the difference between checked and unchecked exceptions? 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) 2. f(0)

Problem 7 (Multithreading & Synchronization) 1. 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 the effect of invoking the join() method of the Thread class? e. What is scheduling? f. What is the difference between preemptive and non-preemptive scheduling? g. What are data races? h. Write a Java program that can experience a data race i. Why should programs avoid data races? 2. Synchronization & deadlocks a. What is synchronization? b. Why should programs use synchronization? c. What are Java locks? d. How may Java locks be used? e. What are deadlocks? f. Write a Java program that can experience deadlock. 3. 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. 4. Implement a Java program that increases the value of each entry of a two-dimensional array using threads. For example, each row can be processed by a different thread. Once all the entries have been increased, the program will print the sum of all the updated entries. 5. How can you use threads to speed up the processing of a search operation in a binary search tree? Problem 8 (Graphic User Interfaces) 1. In a GUI, what is the model? The view? The controller? 2. Why should they be kept separate? 3. What are events? 4. Why are events used in GUIs?

Problem 9 (Sorting & Algorithm Strategies) 1. 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 2. Algorithm strategies a. What is divide-and-conquer? b. What is dynamic programming? c. What is the difference between divide-and-conquer and dynamic programming? d. What is the difference between recursive and backtracking algorithms? e. What is the difference between a greedy algorithm and heuristics? f. What is the difference between brute force and branch-and-bound algorithms? g. List a reason to use dynamic programming h. List a reason to use backtracking i. List a reason to use a brute force algorithm j. What type of algorithm is Kruskal s algorithm for finding minimum spanning trees? k. A new graph algorithm can find the best set of nodes that solve a problem by selecting each time the node that have the lowest number of neighbors until no more nodes are left. Which algorithm strategy is this algorithm relying on? l. Which algorithm strategy (in addition to recursion) can be used to efficiently compute Fibonacci numbers? Select only one. Problem 10 (Hashing) 1. What are the advantages of hashing? 2. Describe the Java Hash Code Contract. 3. A class has as instance variables a string, an integer, a float and a StringBuffer object reference. Define possible hashcode methods for this class. 4. What would happen if you use a HashMap or HashSet with a class that does not implement the Java Hash Code Contract?

Problem 11 (Design Patterns) 1. Design patterns a. What is a design pattern? b. When are design patterns used? c. List 3 types of design patterns. Give 2 example patterns for each type. d. Write a Java example of the Singleton pattern e. Write a Java example of the State pattern f. List 2 examples of design patterns used in the Java class libraries g. Based on the following 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. public interface Boat { int maxcapacity; int topspeed( ) class CruiseShip implements Boat { int topspeed( ) { return 20; class SpeedBoat implements Boat { int topspeed( ) { return 40; // big boat // small boat Boat mybigboat = BoatFactory.create( big ); Boat mysmallboat = BoatFactory.create( small ); public class BoatFactory { static Boat create(string s) { // your code here

Problem 12 (Linear Data Structures) 1. Name three kinds of linked lists traversals we saw in class. 2. Name one advantage of a linked list over an array list. 3. Given the following Java class definition for a linked list public class LinkedList<T extends Comparable<T>> { private class Node { private T data; private Node next, thread; private Node(T data) { this.data = data; next = thread = null; private Node head, tail; public LinkedList() { head = tail = null; Write the following code: a. find(k key) Use a recursive algorithm to find a node with a key value that corresponds to key in the list b. printlistreverse Use a recursive algorithm to print the list in reverse order c. removeevennumberednodes Use a recursive algorithm to remove even-numbered nodes from a list. Reimplement your code using a non-recursive algorithm d. removeduplicates() Use a recursive algorithm to remove duplicates from the list e. removeinrange(t lower, T upper) Use a recursive algorithm to remove nodes present in the range defined by lower (inclusive) and upper (inclusive). Elements removed must be placed in a set