CS200 Final Exam Fall 2007

Similar documents
CS200 Midterm 2 Fall 2007

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

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Terminology. The ADT Binary Tree. The ADT Binary Search Tree

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

CSE 373 Final Exam 3/14/06 Sample Solution

Topics for CSCI 151 Final Exam Wednesday, May 10

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

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

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

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

About this exam review

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

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

Computer Science 302 Spring 2017 (Practice for) Final Examination, May 10, 2017

Prelim 2, CS2110. SOLUTION

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

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

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

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

CS 112 Final May 8, 2008 (Lightly edited for 2012 Practice) Name: BU ID: Instructions

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

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

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

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology

CSE 373: Practice Final

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

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

CS171 Final Practice Exam

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

Final- ECE 242 Fall 2016 Closed book/notes- no calculator- no phone- no computer

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance

CS200: Trees. Rosen Ch & 11.3 Prichard Ch. 11. CS200 - Trees

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

Course Review for Finals. Cpt S 223 Fall 2008

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1

CSE 332 Autumn 2016 Final Exam (closed book, closed notes, no calculators)

CS171 Final Practice Exam

) $ f ( n) " %( g( n)

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

CMP-338 Solutions Final Fall 2015 Version 1

( ) 1 B. 1. Suppose f x

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

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix

CMSC132, Practice Questions

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

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

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

Data Structures Question Bank Multiple Choice

( ) n 3. n 2 ( ) D. Ο

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

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Computer Science E-22 Practice Final Exam

AP Computer Science 4325

CPSC 331 Term Test #2 March 26, 2007

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# #

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

CS200: Tables and Priority Queues

Priority Queues. 04/10/03 Lecture 22 1

CS61BL. Lecture 5: Graphs Sorting

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

(a) Write code to do this without using any floating-point arithmetic. Efficiency is not a concern here.

Course Name: B.Tech. 3 th Sem. No of hours allotted to complete the syllabi: 44 Hours No of hours allotted per week: 3 Hours. Planned.

EXAMINATIONS 2012 MID YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

Tree Terminology. root. Edge. interior node. parent. path. subtree. child. leaf

CSE 332 Winter 2018 Final Exam (closed book, closed notes, no calculators)

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

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

Points off Total off Net Score. CS 314 Final Exam Spring 2016

Data Structures and Algorithm Analysis in C++

Name CPTR246 Spring '17 (100 total points) Exam 3

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

Draw the resulting binary search tree. Be sure to show intermediate steps for partial credit (in case your final tree is incorrect).

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

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

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu

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

Solutions to Exam Data structures (X and NV)

CS 2150 Final Exam, Spring 2018 Page 1 of 10 UVa userid:

CS 112 Final May 8, 2008 (Lightly edited for 2011 Practice) Name: BU ID: Instructions GOOD LUCK!

Data Structures Brett Bernstein

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

COMP 251 Winter 2017 Online quizzes with answers

4/3/13. Outline. Part 7. Tables and Priority Queues. Value Oriented Data Structures. Example: Table of Student Points. Table ADT.

Algorithms: Design & Practice

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

CS 161 Fall 2015 Final Exam

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

1. AVL Trees (10 Points)

CSCI-140 Midterm Review October 10, 2015 Presented by the RIT Computer Science Community

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

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

PROGRAMMING II ABSTRACT DATA TYPES Unassessed Coursework 4: Binary Search Trees and Heaps

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

CS171 Midterm Exam. October 29, Name:

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

Transcription:

CS200 Final Exam Fall 2007 Name Topic Possible Received Programming 53 Complexity, Recurrence 18 Divide & Conquer 16 Priority Queues, Heaps 18 Graphs 38 Hash Tables 12 Misc 45 TOTAL 200

1. Programming [53 points] a. [30 points] Given the following interfaces for BinarySearchTree and KeyedItem (based on the textbook s code) and code for a HashTable, fill in the method stubs. Note: This hash table uses Separate Chaining where the auxiliary storage is a Binary Search Tree. public class BinarySearchTree extends BinaryTreeBasis { // inherits isempty(), makeempty(), getrootitem(), and // the use of the constructors from BinaryTreeBasis public BinarySearchTree() { public BinarySearchTree(KeyedItem rootitem) { public void insert(keyeditem newitem) { public KeyedItem retrieve(comparable searchkey) { public void delete(comparable searchkey) throws TreeException { public String tostring() { public class KeyedItem { private Comparable searchkey; private Object item; public KeyedItem(Comparable key, Object value) { public Comparable getkey() { public Object getvalue() { public String tostring() { public class HashTable { public final int HASH_TABLE_SIZE=101; private BinarySearchTree[] table; public HashTable() { table = new BinarySearchTree[HASH_TABLE_SIZE]; public int hashindex(comparable key) { return Math.abs(key.hashCode() % HASH_TABLE_SIZE); public String tostring() { String output = ""; for (int i=0; i< HASH_TABLE_SIZE; i++) { if (table[i]!= null) { output = output + "\n" + i + ". " + table[i].tostring(); return output;

public void tableinsert(keyeditem data) { public boolean tabledelete(comparable searchkey) {

b. [10 points] The code in the last question did not use generics because a generified Array is not allowed in Java. 1. In addition to the hassle of my having to create non-generic versions of perfectly good classes, what hassle might programmers using my HashTable class incur? 2. What would need to be done to HashTable to make it generic? c. [13 points] Match the lines in the Java code below (method is in Graph class) to lines in Dijkstra s algorithm (from the Rosen text). Note: the code uses the Graph implementation from Carrano and Prichard. private int Dijkstras(Integer source, Integer dest) { 1. int[] distances = new int[adjlist.size()]; 2. Arrays.fill(distances, 1000000); 3. distances[source] = 0; 4. boolean[] visited = new boolean[adjlist.size()]; 5. Arrays.fill(visited, false); 6. int numvisited = 0; 7. while (numvisited < visited.length) { 8. int mindist = 100000; 9. int minindex = -1; 10. for (int i=0; i < distances.length; i++) { 11. if ((!visited[i]) && (distances[i] < mindist)) { 12. minindex = i; 13. mindist = distances[i]; 14. if (minindex > -1) { 15. Set<Integer> edges = adjlist.get(minindex).keyset(); 16. Iterator<Integer> overedges = edges.iterator(); 17. while (overedges.hasnext()) { 18. Integer neighbor = overedges.next(); 19. Integer edgeweight = adjlist.get(minindex).get(neighbor); 20. int alt = distances[minindex] + edgeweight; 21. if (alt < distances[neighbor]) {distances[neighbor] = alt; 22. visited[minindex] = true; 23. numvisited++; 24. else { numvisited = visited.length; 25. return distances[dest];

Code Lines Algorithm 0 Procedure Dijkstra(G: weighted connected simple graph, with all weights positive, z: vertex in G) for i := 1 to n { L( v i ) := " L(a) := 0 S := " while z " S { u := a vertex not in S with L(u) minimal S := S " {u for all vertices v not in S { if L(u) + w(u,v) < L(v) then L(v) := L(u) + w(u,v) return L(z) 2. Complexity/Recurrence [18 points] a. [12 points] The complexity of MergeSort can be described by the recurrence relation M(n) = 2M(n /2) + n 1. What does the first number 2 correspond to in the algorithm? 2. Solve the recurrence relation for M(8). 3. Which case for the Master Theorem applies for MergeSort: a < b d, a = b d or a > b d b. [6 points] Describe how the number of comparisons in the worst case increases when these algorithms are used to search for an item in an array when the size of the array doubles from n to 2n, where n is a positive integer. 1. binary search 2. linear search

3. Divide & Conquer [16 points] a. [6 points] Given a choice between MergeSort and QuickSort to implement for a given application, which would you pick? Justify your choice. b. [10 points] For the array [1,3,5,7,9,2,4,6,8,10] 1. how many comparisons are needed for MergeSort to merge the two partitions? 2. how large are the two partitions created by Quicksort if it chooses the median of the values at positions {0, 4, 9 as the pivot. 4. Priority Queues, Heaps [18 points] a. [12 points] Circle T or F for True or False for the following statements. T F Mergesort is more efficient than HeapSort in the worst case. T F An inorder traversal of a heap produces an ordered set. T F In an array-based implementation of a heap, the HeapInsert operation is O(n) worst case. T F When 40 is added to the heap [13, 100, 32, 101, 125, 160, 34, 102, 112, 130, 313, 175, 161, 200], the array becomes [13, 100, 32, 101, 125, 160, 34, 102, 112, 130, 313, 175, 161, 200, 40]. T F When a value is removed from the heap [13, 100, 32, 101, 125, 160, 34, 102, 112, 130, 313, 175, 161, 200], the array becomes [32, 100, 34, 101, 125, 161, 160, 102, 112, 130, 313, 175, 200]. T F A Binary Search Tree could be used to implement a Priority Queue.

b. [6 points] What makes a heap the best choice for implementing a priority queue? 5. Graphs [38 points] a. [18 points] Answer the questions that follow for this graph. Whenever you have a choice in the algorithm being used, pick the vertex that is lower alphabetically. 1. Treating the graph as though it were undirected, draw a minimal spanning tree for it starting from vertex a. 2. Treating the graph as though it were undirected, draw a spanning tree that is not the minimal spanning tree for it starting from vertex a. 3. Treating the graph as directed, draw a topological sort for it.

b. [20 points] Fill in the blanks of the following definitions and theorems: 1. in a graph G is a simple circuit containing every edge of G. 2. An undirected graph has an even number of vertices of 3. Let G=(V,e) be a graph with directed edges. Then $ deg " (v) = v #V 4. A simple graph is bipartite if and only if it is possible to assign 5. A directed path is if there is a path between every two vertices in the underlying undirected graph. 6. Hash Tables [12 points] Using the Java built in hash code as described in class and a hash table of size 7, the following words hash to the codes that follow them: (bad:1)(bear:2)(echidna:3)(slo:3)(rat:4)(xhn:1) Assuming they are added to a hashtable implemented using linear probing in the order: bear, echidna, slo, rat, bad, xhn, which pairs will experience primary clustering? Which pairs will experience secondary clustering?

7. Misc [45 points] a. [16 points] Stacks and Queues are the basis for graph and tree traversals. Each of the following traversals use one or the other: inorder binary tree traversal postorder binary tree traversal level order binary tree traversal depth first graph traversal breadth first graph traversal For each of Stack and Queue, pick a traversal that uses it and describe the algorithm. One traversal should be for a tree and the other for a graph. STACK Traversal QUEUE Traversal b. [9 points] For the following grammar: 1. Describe the language produced by it. S->0S1 1S0 0 1 2. Is 010101 a legal string for the language?

c. [20 points] Circle T or F for True or False for the following various statements: T F An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices. T F There are at most h m leaves in an m-ary tree of height h. T F New items enter a queue at its front. T F In the network routing simulation for your programming assignment, the event manager needed to maintain a queue of packets. T F The keyword extends is used in the class definition of a subclass to indicate its superclass. T F Stack can best be implemented with an ArrayList if the pushes and pops happen at position 0. T F Adjacency list graph implementation is preferred for sparse arrays. T F Hybrid data structures combine other different data structures to achieve their functionality. T F An Euler circuit requires an odd number of edges. T F Including a main method in every class expedites unit testing and debugging.