COS 226 Midterm Exam, Spring 2011

Similar documents
COS 226 Midterm Exam, Spring 2009

COS 226 Midterm Exam, Spring 2010

COS 226 Midterm Fall 2007

COS 226 Algorithms and Data Structures Spring Midterm

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Spring Midterm

COS 226 Algorithms and Data Structures Spring Midterm

COS 226 Algorithms and Data Structures Spring Midterm Exam

Princeton University Computer Science COS226: Data Structures and Algorithms. Midterm, Fall 2013

Midterm, Spring 2013

COS 226 Final Exam, Spring 2009

COS 126 General Computer Science Spring Written Exam 1

COS 126 Midterm 1 Written Exam Fall 2011

COS 226 Algorithms and Data Structures Spring Midterm

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

CSE 373 Spring 2010: Midterm #2 (closed book, closed notes, NO calculators allowed)

Examination Questions Midterm 2

COS 126 Midterm 1 Written Exam Fall 2014!

COS 126 Midterm 1 Written Exam Fall 2012

Computer Science 302 Spring 2007 Practice Final Examination: Part I

COS 126 General Computer Science Spring Midterm 1

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

COS 126 General Computer Science Spring Written Exam 2

COS 226 Written Exam 2 Fall 2016

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

COS 126 General Computer Science Fall Midterm 1

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

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

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

COS 126 Written Exam 2, Fall 2009

Questions Total Points Score

COS 126 General Computer Science Spring Written Exam 1

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

Computer Science Spring 2005 Final Examination, May 12, 2005

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

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

Programming II (CS300)

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

COS 226 Algorithms and Data Structures Fall Midterm Solutions

COS 126 Midterm 1 Written Exam, Fall 2009

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

COS 126 Midterm 1 Written Exam Spring 2015

CISC 621 Algorithms, Midterm exam March 24, 2016

Programming II (CS300)

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 332, Spring 2010, Midterm Examination 30 April 2010

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

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

Course Review for Finals. Cpt S 223 Fall 2008

Final Examination CSE 100 UCSD (Practice)

Student number: Datenstrukturen & Algorithmen page 1

CSE 373 Autumn 2012: Midterm #2 (closed book, closed notes, NO calculators allowed)

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

CSC 325 Algorithms & Advanced Data Structures

COS 126 MIDTERM 1, FALL

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

COS 226 Final Exam, Spring 2010

Sorting and Selection

Solutions to Exam Data structures (X and NV)

Final Exam. COS 226 Algorithms and Data Structures Fall 2015

CS 315 Data Structures Spring 2012 Final examination Total Points: 80

COP 3502 Spring 2018 Study Union Review

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1.

CSE 373 Autumn 2010: Midterm #2 (closed book, closed notes, NO calculators allowed)

COS 226 Algorithms and Data Structures Fall Final

Midterm 1: CS186, Spring I. Storage: Disk, Files, Buffers [11 points] cs186-

COS 226 Algorithms and Data Structures Spring Second Written Exam

Midterm 1 Written Exam

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

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

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

1. AVL Trees (10 Points)

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

Data Structures and Algorithms 2018

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4)

CSci 231 Final Review

Module 2: Classical Algorithm Design Techniques

Lecture 5: Sorting Part A

COS 126 Written Exam 2 (Spring 2015)

COMP Data Structures

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

CSC 325 Algorithms & Advanced Data Structures.

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

CSE 373 Sample Midterm #2 (closed book, closed notes, calculators o.k.)

EECS 492 Midterm #1. Example Questions. Note: Not a complete exam!

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

7. Sorting I. 7.1 Simple Sorting. Problem. Algorithm: IsSorted(A) 1 i j n. Simple Sorting

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

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

CSCE 2014 Final Exam Spring Version A

COS 226 Algorithms and Data Structures Fall Final Exam

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

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

Transcription:

NAME: login ID: Precept (circle one): P01 P01A P01B P02 P02A P03 COS 226 Midterm Exam, Spring 2011 This test is 9 questions, weighted as indicated. The exam is closed book, except that you are allowed to use a one page cheatsheet. No calculators or other electronic devices are permitted. Give your answers and show your work in the space provided. Put your name, login ID, and precept number on this page (now), and write out and sign the Honor Code pledge before turning in the test. You have 80 minutes to complete the test. "I pledge my honor that I have not violated the Honor Code during this examination." 1 /12 2 /10 3 /10 4 /10 5 /14 6 /10 7 /10 8 /14 9 /10 TOTAL /100 March 7, 2011

1. Partitioning (12 points). A. (4 points) Fill in the diagram below with the result of partitioning the array with standard quicksort partitioning (taking the E at the left as the partitioning item). Also give the number of exchanges. E V E R Y E Q U A L K E Y S T O P S I T Number of exchanges B. (3 points) Why does standard quicksort partitioning stop the partitioning scans on keys equal to the partitioning item? Circle your answer. a. It is a lazy algorithm. b. To avoid exchanging them. c. To avoid quadratic running time. d. To make the algorithm stable. e. None of the above. 2

C. (5 points) Fill in the diagram below with the result of partitioning the array with 3-way quicksort partitioning (again taking the E at the left as the partitioning item). Also give the number of exchanges. E V E R Y E Q U A L K E Y S T O P S I T Number of exchanges 3

2. Estimating order of growth (10 points). A. (5 points) Suppose that you observe that a program takes 30 seconds to complete on inputs of size 600 and 4.5 minutes to complete on inputs of size 1800. Develop a reasonable hypothesis for the order of growth of the running time. Hint: Use a tripling hypothesis. order of growth: B. (5 points) Suppose that you observe that a program takes x seconds to complete on inputs of size N and y seconds to complete on inputs of size 10N. Under the hypothesis that the order of growth of the running time is N to a power b, give a formula for b. b = 4

3. Sorting algorithms (10 points). Give the order of growth of the running times of the following sorting algorithms for arrays that are already in order and for arrays that are in reverse order. For quicksort, note that it randomizes, so give the expected order of growth. Write constant, N, N log N, N2, or? in each blank. Fill in all blanks and use exactly one question mark (in other words, there is one answer that we think is an open research question). sorted order reverse order a. Quicksort b. Heapsort c. Insertion sort d. Selection sort e. Shellsort (with increments 1, 4, 13, 40,...) 4. Tree height (10 points). Write constant, log N, log*n, or N in the blank following each of the following tree structures to best describe the order of growth of the height of an N-node tree in the best case and in the worst case. best case worst case a. BST b. Heap-ordered complete tree c. Left-leaning red-black tree d. quick-union with path compression e. weighted quick-union 5

5. LLRB insertion (14 points). The following diagram shows a left-leaning red-black BST Thick lines are red links. a. (5 points) Draw the left-leaning red-black BST that results after S is inserted. 6

b. (2 points) Which of the trees drawn below are legal left-leaning red-black BSTs? In the blank below, write the numbers corresponding to all legal LLRB BSTs. Do not include trees that might arise at intermediate stages of an insertion. Legal LLRB trees c. (7 points) Seven of the trees drawn above are intermediate stages when a new key is inserted into tree 0. In the blanks below, list the numbers corresponding to these trees (not including tree 0) in the order in which they occur during the insertion process. 7

6. Heap operations (10 points). Consider the following max-heap: a. (5 points) Draw the result of inserting S. b. (5 points) Draw the result of deleting the maximum from the original max-heap shown above (before S has been inserted). 8

7. Linear probing (10 points). A programmer building a symbol-table with single-character keys uses a bad hash function where keys in the first half of the alphabet (A through M) hash to the value 6 and keys in the second half of the alphabet (N through Z) hash to the value 9. A. (6 points) Fill in the diagram below to give the result of inserting the keys B A D F U N C T I O N into an initially empty table of size 11 with this hash function. B. (4 points) Suppose that the same programmer has the same problem with N keys (half the keys hash to the value 6 and the other half hash to the value 9). Answer the following questions about the order of growth of the running time for certain operations by filling in the blanks below with one of the words constant, linear, linearithmic, or quadratic. For linear probing assume the array size to be 2N; for separate chaining, assume the array size to be N/5. a. Average time for a search hit with separate chaining when searching for a random key b. Average time for a search hit with linear probing when searching for a random key c. Total time to build the table with linear probing d. Total time to build the table with separate chaining 9

8. 7 sorting algorithms (14 points). The leftmost column is the original input of strings to be sorted, and the rightmost column is the sorted result. The other columns are the contents at some intermediate step during one of the 7 sorting algorithms listed below. Match up each algorithm by writing its letter under the corresponding column. Use each letter exactly once. that from been good your been from have been with good from have with that have that from have have good been will good know that good this that have know this have that this have that been know from they from that will know will that that that want that that will that will know that that will know they with that your that that that that that this your that from your that that from that will from that they they they they that they will know they know will this your know will with that this that will want want that this your they want want want will will have want want been will been that your will been will been good will that this with this that with that that with good with will with good your good want your input result a. 3-way quicksort (with no random shuffle) b. Shellsort (13-4-1 increments) c. Insertion sort d. Quicksort (with no random shuffle) e. Selection sort f. Top-down mergesort g. Heapsort 10

9. Maximum difference (10 points). Consider the following code fragment which computes the maxdiff function for an array: the maximum value of the difference between an entry and an entry to its left. For example, the maxdiff of {3, 1, 4, 1, 5, 9, 2} is 8 because the difference between the 9 and the 1s to its left is 8 and no other difference between an entry and another entry to its left is greater. As another example the maxdiff of {9, 4, 6, 8, 2, 2} is 4. public static int slow(int[] a) { int max = a[1] - a[0]; for (int j = 2; j < a.length; j++) for (int i = 0; i < j; i++) if (a[j] - a[i] > max) max = a[j] - a[i]; return max; } An enterprising COS226 student figured out a faster way to solve the problem, with the following code: public static int fast(int[] a) { int max = a[1] - a[0]; int min = a[0]; for (int k = 1; k < a.length; k++) { // First missing line of code. // Second missing line of code. } return max; } A. (8 points) In the space below, write the two lines of code missing from fast(). A "line of code" is a statement ending with a semicolon. B. (2 points) What is the order of growth of the running time of the two methods? Write one of the following words in each of the blanks below: constant, linear, linearithmic, quadratic, cubic. slow() 11

fast() 12