Design and Analysis of Algorithms March 12, 2015 Massachusetts Institute of Technology Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Quiz 1

Similar documents
Design and Analysis of Algorithms April 16, 2015 Massachusetts Institute of Technology Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Quiz 2

Introduction to Algorithms March 10, 2010 Massachusetts Institute of Technology Spring 2010 Professors Piotr Indyk and David Karger Quiz 1

Design and Analysis of Algorithms May 12, 2011 Massachusetts Institute of Technology. Practice Final Exam. Problem Title Points Parts Grade Initials

Fall 2016 Test 1 with Solutions

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt): Name of Neighbor to your right (1 pt):

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts)

CPSC 320 (Intermediate Algorithm Design and Analysis). Summer Instructor: Dr. Lior Malka Final Examination, July 24th, 2009

University of New Mexico Department of Computer Science. Final Examination. CS 561 Data Structures and Algorithms Fall, 2006

Midterm II. Introduction to Artificial Intelligence. CS 188 Spring ˆ You have approximately 1 hour and 50 minutes.

University of New Mexico Department of Computer Science. Final Examination. CS 561 Data Structures and Algorithms Fall, 2013

Lecture 18 April 26, 2012

CS 170 Algorithms Fall 2014 David Wagner MT2

Randomized Sorting Algorithms Quick sort can be converted to a randomized algorithm by picking the pivot element randomly. In this case we can show th

GOOD LUCK! 2. a b c d e 12. a b c d e. 3. a b c d e 13. a b c d e. 4. a b c d e 14. a b c d e. 5. a b c d e 15. a b c d e. 6. a b c d e 16.

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

Quiz 1 Solutions. (a) f 1 (n) = 8 n, f 2 (n) = , f 3 (n) = ( 3) lg n. f 2 (n), f 1 (n), f 3 (n) Solution: (b)

CS 170 Algorithms Spring 2009 David Wagner Final

CSE 421 Introduction to Algorithms Final Exam Winter 2005

GOOD LUCK! 2. a b c d e 12. a b c d e. 3. a b c d e 13. a b c d e. 4. a b c d e 14. a b c d e. 5. a b c d e 15. a b c d e. 6. a b c d e 16.

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

CPSC 320 Sample Final Examination December 2013

CS Data Structures and Algorithm Analysis

MASSACHUSETTS INSTITUTE OF TECHNOLOGY DEPARTMENT OF MECHANICAL ENGINEERING 2.06 Fluid Dynamics, Spring 2013

Algorithms Exam TIN093 /DIT602

Math 106: Calculus I, Spring 2018: Midterm Exam II Monday, April Give your name, TA and section number:

Introduction to Algorithms 6.046J/18.401J

6.041/6.431 Spring 2009 Quiz 1 Wednesday, March 11, 7:30-9:30 PM. SOLUTIONS

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3

Quiz 1. Adrian Georgi Josh Karen Lee Min Nikos Tina. There are five (5) problems totaling 100 points. Total time is 110 minutes.

CS 161 Summer 2009 Homework #2 Sample Solutions

Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010

Algorithms and Data Structures 2016 Week 5 solutions (Tues 9th - Fri 12th February)

Design and Analysis of Algorithms

Recap & Interval Scheduling

Bucket-Sort. Have seen lower bound of Ω(nlog n) for comparisonbased. Some cheating algorithms achieve O(n), given certain assumptions re input

6.041/6.431 Fall 2010 Final Exam Wednesday, December 15, 9:00AM - 12:00noon.

Test 2. Monday, November 12, 2018

6.042/18.062J Mathematics for Computer Science March 9, 2005 Srini Devadas and Eric Lehman. Quiz 1. Ishan Christos Grant

Midterm II. Introduction to Artificial Intelligence. CS 188 Spring ˆ You have approximately 1 hour and 50 minutes.

CS361 Homework #3 Solutions

MIDTERM Fundamental Algorithms, Spring 2008, Professor Yap March 10, 2008

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science

6.003 (Fall 2011) Quiz #3 November 16, 2011

An analogy from Calculus: limits

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

Quick Sort Notes , Spring 2010

Data Structures and Algorithms Winter Semester

MTH 132 Solutions to Exam 2 November 21st, Without fully opening the exam, check that you have pages 1 through 11.

Quarter 2 400, , , , , , ,000 50,000

Solutions. Problem 1: Suppose a polynomial in n of degree d has the form

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n

18.06 Quiz 2 April 7, 2010 Professor Strang

Euclid Contest Wednesday, April 7, 2010

N/4 + N/2 + N = 2N 2.

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

Midterm 1 for CS 170

Midterm 1. Your Exam Room: Name of Person Sitting on Your Left: Name of Person Sitting on Your Right: Name of Person Sitting in Front of You:

8. Limit Laws. lim(f g)(x) = lim f(x) lim g(x), (x) = lim x a f(x) g lim x a g(x)

University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016

Algorithm Design and Analysis (NTU CSIE, Fall 2017) Homework #3. Homework #3. Due Time: 2017/12/14 (Thu.) 17:20 Contact TAs:

University of New Mexico Department of Computer Science. Midterm Examination. CS 361 Data Structures and Algorithms Spring, 2003

1 Terminology and setup

CS 188 Introduction to Fall 2007 Artificial Intelligence Midterm

Solutions to Quiz 1. Problem 1 (20 points). Suppose S(n) is a predicate on natural numbers, n, and suppose. k N S(k) S(k + 2). (1)

CSE548, AMS542: Analysis of Algorithms, Fall 2016 Date: Nov 30. Final In-Class Exam. ( 7:05 PM 8:20 PM : 75 Minutes )

Without fully opening the exam, check that you have pages 1 through 10.

GRADE 7 MATH LEARNING GUIDE. Lesson 26: Solving Linear Equations and Inequalities in One Variable Using

Exam 1. March 12th, CS525 - Midterm Exam Solutions

Exam EDAF May Thore Husfeldt

Problem Set 1. MIT students: This problem set is due in lecture on Wednesday, September 19.

Math 391: Midterm 1.0 Spring 2016

Lecture 4: Divide and Conquer: van Emde Boas Trees

CSCI Honor seminar in algorithms Homework 2 Solution

Concrete models and tight upper/lower bounds

1 Divide and Conquer (September 3)

CS 350 Algorithms and Complexity

Paradox and Infinity Problem Set 6: Ordinal Arithmetic

MATH UN Midterm 2 November 10, 2016 (75 minutes)

Average Case Analysis. October 11, 2011

Solutions. Prelim 2[Solutions]

Calculator Exam 2009 University of Houston Math Contest. Name: School: There is no penalty for guessing.

Math 51 Midterm 1 July 6, 2016

Calculus is Cool. Math 160 Calculus for Physical Scientists I Exam 1 September 18, 2014, 5:00-6:50 pm. NAME: Instructor: Time your class meets:

Optimization Methods in Management Science

Divide-and-conquer: Order Statistics. Curs: Fall 2017

Data Structures and Algorithms

MATH 1553, SPRING 2018 SAMPLE MIDTERM 1: THROUGH SECTION 1.5

DEPARTMENT OF EECS MASSACHUSETTS INSTITUTE OF TECHNOLOGY. 6.02: Digital Communication Systems, Fall Quiz I. October 11, 2012

MTH 132 Exam 2 November 21st, Without fully opening the exam, check that you have pages 1 through 11.

NAME: Be clear and concise. You may use the number of points assigned toeach problem as a rough

Algorithms, Probability, and Computing Fall 2010 Exam

Introduction to Algorithms 6.046J/18.401J/SMA5503

CSCI 3110 Assignment 6 Solutions

Prelim 2[Solutions] Solutions. 1. Short Answer [18 pts]

CS161: Algorithm Design and Analysis Recitation Section 3 Stanford University Week of 29 January, Problem 3-1.

Name: Exam 2 Solutions. March 13, 2017

CS246 Final Exam, Winter 2011

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Midterm Exam 2 Solutions

Transcription:

Design and Analysis of Algorithms March 12, 2015 Massachusetts Institute of Technology 6.046J/18.410J Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Quiz 1 Quiz 1 Do not open this quiz booklet until you are directed to do so. Read all the instructions first. The quiz contains 7 problems, with multiple parts. You have 120 minutes to earn 120 points. This quiz booklet contains 12 pages, including this one. "" This quiz is closed book. You may use one double-sided letter (8 1 11 "" ) or A4 crib sheet. 2 No calculators or programmable devices are permitted. Cell phones must be put away. Do not waste time deriving facts that we have studied. Just cite results from class. When we ask you to give an algorithm in this quiz, describe your algorithm in English or pseudocode, and provide a short argument for correctness and running time. You do not need to provide a diagram or example unless it helps make your explanation clearer. Do not spend too much time on any one problem. Generally, a problem s point value is an indication of how many minutes to spend on it. Show your work, as partial credit will be given. You will be graded not only on the correctness of your answer, but also on the clarity with which you express it. Please be neat. Good luck! Problem Title Points Parts Grade Initials 1 True or False 40 10 2 Fast Fourier Transform 5 1 3 Yellow Brick Road 10 1 4 Amortized Analysis 15 1 5 Verifying Polynomial Multiplication 15 4 6 Dynamic Programming 15 2 7 Median of Sorted Arrays 20 3 Total 120 :

2 Problem 1. True or False. [40 points] (10 parts) Circle T or F for each of the following statements to indicate whether the statement is true or false and briefly explain why. (a) T F [4 points] With all equal-sized intervals, a greedy algorithm based on earliest start time will always select the maximum number of compatible intervals. (b) T F [4 points] The problem of weighted interval scheduling can be solved in O(n log n) time using dynamic programming. (c) T F [4 points] If we divide an array into groups of 3, find the median of each group, recursively find the median of those medians, partition, and recurse, then we can obtain a linear-time median-finding algorithm. (d) T F [4 points] If we used the obvious Θ(n 2 ) merge algorithm in the divide-andconquer convex-hull algorithm, the overall time complexity would be Θ(n 2 log n). (e) T F [4 points] Van Emde Boas sort (where we insert all numbers, find the min, and then repeatedly call SUCCESSOR) can be used to sort n = lg u numbers in O(lg u lg lg lg u) time.

3 (f) T F [4 points] Van Emde Boas on n integers between 0 and u 1 supports successor queries in O(lg lg u) worst-case time using O(n) space. (g) T F [4 points] In the potential method for amortized analysis, the potential energy should never go negative. (h) T F [4 points] The quicksort algorithm that uses linear-time median finding to run in worst-case O(n log n) time requires Θ(n) auxiliary space. (i) T F [4 points] Searching in a skip list takes Θ(log n) time with high probability, but could take Ω(2 n ) time with nonzero probability. (j) T F [3 points] The following collection H = {h 1, h 2, h 3 } of hash functions is universal, where each hash function maps the universe U = {A, B, C, D} of keys into the range {0, 1, 2} according to the following table: x A B C D h 1 (x) 1 0 1 1 h 2 (x) 0 1 0 1 h 3 (x) 2 2 1 0

4 Problem 2. Fast Fourier Transform (FFT). [5 points] (1 part) Ben Bitdiddle is trying to multiply two polynomials using the FFT. In his trivial example, Ben sets a = (0, 1) and b = (0, 1), both representing 0 + x, and calculates: A = F(a) = B = F(b) = (1, 1), C = A B = (1, 1), c = F 1 (C) = (1, 0). So c represents 1 + 0 x, which is clearly wrong. Point out Ben s mistake in one sentence; no calculation needed. (Ben swears he has calculated FFT F and inverse FFT F 1 correctly.)

5 Problem 3. Yellow Brick Road. [10 points] (1 part) Prof. Gale is developing a new Facebook app called Yellow Brick Road for maintaining a user s timeline, here represented as a time-ordered list e 0, e 1,..., e n 1 of n (unchanging) events. (In Facebook, events can never be deleted, and for the purposes of this problem, don t worry about insertions either.) The app allows the user to mark an event e i as yellow (important) or grey (unimportant); initially all events are grey. The app also allows the user to jump to the next yellow event that comes after the event e i currently on the screen (which may be yellow or grey). More formally, you must support the following operations: 1. MARK-YELLOW(i): Mark e i yellow. 2. MARK-GREY(i): Mark e i grey. 3. NEXT-YELLOW(i): Find the smallest j > i such that e j is yellow. Give the fastest data structure you can for this problem, measured according to worst-case time. The faster your data structure, the better. Hint: Use a data structure you have seen in either 6.006 or 6.046 as a building block.

6 Problem 4. Amortized Analysis. [15 points] (1 part) Design a data structure to maintain a set S of n distinct integers that supports the following two operations: 1. INSERT(x, S): insert integer x into S. 2. REMOVE-BOTTOM-HALF(S): remove the smallest n 2 integers from S. Describe your algorithm and give the worse-case time complexity of the two operations. Then carry out an amortized analysis to make INSERT(x, S) run in amortized O(1) time, and REMOVE BOTTOM-HALF(S) run in amortized 0 time.

7 Problem 5. Verifying Polynomial Multiplication. [15 points] (4 parts) This problem will explore how to check the product of two polynomials. Specifically, we are given three polynomials: n n 1 p(x) = a n x + a n 1 x + + a 0, n n 1 q(x) = b n x + b n 1 x + + b 0, 2n 2n 1 r(x) = c 2n x + c 2n 1 x + + c 0. We want to check whether p(x) q(x) = r(x) (for all values x). Via FFT, we could simply compute p(x) q(x) and check in O(n log n) time. Instead, we aim to achieve O(n) time via randomization. (a) [5 points] Describe an O(n)-time randomized algorithm for testing whether p(x) q(x) = r(x) that satisfies the following properties: 1. If the two sides are equal, the algorithm outputs YES. 2. If the two sides are unequal, the algorithm outputs NO with probability at least 1. 2 (b) [2 points] Prove that your algorithm satisfies Property 1.

8 (c) [3 points] Prove that your algorithm satisfies Property 2. Hint: Recall the Fundamental Theorem of Algebra: A degree-d polynomial has (at most) d roots. (d) [5 points] Design a randomized algorithm to check whether p(x) q(x) = r(x) that is correct with probability at least 1 ε. Analyze your algorithm in terms of n and 1/ε.

9 Problem 6. Dynamic Programming. [15 points] (2 parts) Prof. Child is cooking from her garden, which is arranged in grid with n rows and m columns. Each cell (i, j) (1 i n, 1 j m) has an ingredient growing in it, with tastiness given by a positive value T i,j. Prof. Child doesn t like cooking by the book. To prepare dinner, she will stand at a cell (i, j) and pick one ingredient from each quadrant relative to that cell. The tastiness of her dish is the product of the tastiness of the four ingredients she chooses. Help Prof. Child find an O(nm) dynamic programming algorithm to maximize the tastiness of her dish. Here the four quadrants relative to a cell (i, j) are defined as follows: top-left = {all cells (a, b) a < i, b < j}, bottom-left = {all cells (a, b) a > i, b < j}, top-right = {all cells (a, b) a < i, b > j}, bottom-right = {all cells (a, b) a > i, b > j}. Because Prof. Child needs all four quadrants to be non-empty, she can only stand on cells (i, j) where 1 < i < n and 1 < j < m. (a) [10 points] Define TL i,j to be maximum tastiness value in the top-left quadrant of cell (i, j): TL i,j = max{t a,b 1 a i, 1 b j}. Find a dynamic programming algorithm to compute TL i,j, for all 1 < i < n and 1 < j < m, in O(nm) time.

10 (b) [5 points] Use the idea in part (a) to obtain an O(nm) algorithm to find the tastiest dish.

11 Problem 7. Median of two sorted arrays. [20 points] (3 parts) Finding the median of a sorted array is easy: return the middle element. But what if you are given two sorted arrays A and B, of size m and n respectively, and you want to find the median of all the numbers in A and B? You may assume that A and B are disjoint. (a) [3 points] Give a naïve algorithm running in Θ(m + n) time. (b) [10 points] If m = n, give an algorithm that runs in Θ(lg n) time.

12 (c) [7 points] Give an algorithm that runs in O(lg(min{m, n})) time, for any m and n. Don t spend too much time on this question!

MIT OpenCourseWare http://ocw.mit.edu 6.046J / 18.410J Design and Analysis of Algorithms Spring 2015 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.