CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

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

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

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

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

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

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

(Refer Slide Time: 01.26)

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 548: Analysis of Algorithms. Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps )

COS 226 Algorithms and Data Structures Fall Midterm

CSE373 Fall 2013, Midterm Examination October 18, 2013

Midterm 2. Read all of the following information before starting the exam:

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

Sorting and Selection

COS 226 Algorithms and Data Structures Fall Midterm

: Fundamental Data Structures and Algorithms. June 06, 2011 SOLUTIONS

Problem Set 5 Due: Friday, November 2

CSE 247 Data Structures and Algorithms Fall Exam I

l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are:

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

Midterm solutions. n f 3 (n) = 3

Week - 03 Lecture - 18 Recursion. For the last lecture of this week, we will look at recursive functions. (Refer Slide Time: 00:05)

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible.

Advanced Algorithms and Data Structures

CSE 241 Algorithms and Data Structures Fall Semester, Midterm Exam

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

COS 226 Midterm Exam, Spring 2009

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

CS 411 Analysis of Algorithms, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Wednesday, October 17, 2012.

Lecture 11. Lecture 11: External Sorting

COMP 352 FALL Tutorial 10

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

Searching Algorithms/Time Analysis

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

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

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

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough.

EXAM ELEMENTARY MATH FOR GMT: ALGORITHM ANALYSIS NOVEMBER 7, 2013, 13:15-16:15, RUPPERT D

ECE250: Algorithms and Data Structures Final Review Course

Problem Set 6 Due: 11:59 Sunday, April 29

k-selection Yufei Tao Department of Computer Science and Engineering Chinese University of Hong Kong

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Spring Midterm

The Limits of Sorting Divide-and-Conquer Comparison Sorts II

Data Structures and Algorithms 2018

Course Review. Cpt S 223 Fall 2009

Recursion: The Beginning

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2017

Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

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

CSE100. Advanced Data Structures. Lecture 8. (Based on Paul Kube course materials)

CSE 332, Spring 2010, Midterm Examination 30 April 2010

CSE332 Summer 2010: Final Exam

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

COS 226 Algorithms and Data Structures Spring Midterm

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Lecture Notes on Hash Tables

CS 4349 Lecture October 18th, 2017

Merge Sort. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong

Announcements. Recursion and why study it. Recursive programming. Recursion basic idea

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

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

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

Question Score Points Out Of 25


Practice Midterm Exam Solutions

Advanced Algorithms and Data Structures

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

CS171 Midterm Exam. October 29, Name:

CS 261 Spring 2013 Midterm

COS 226 Algorithms and Data Structures Fall Final

Problem Pts Score Grader Problem Pts Score Grader

Binary Search Trees Treesort

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

Prelim 2 Solution. CS 2110, April 26, 2016, 7:30 PM

Recursion: The Beginning

Lecture 5. Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs

COS 126 General Computer Science Fall Exam 1

Quiz 2 CS 3510 October 22, 2004

Randomized Algorithms, Hash Functions

Examination Questions Midterm 2

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.

Final Exam in Algorithms and Data Structures 1 (1DL210)

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

Lower Bound on Comparison-based Sorting

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

ECE242 Data Structures and Algorithms Fall 2008

We've tried to include the common errors and grading standard for every question.

ECE 250 Algorithms and Data Structures

CMPT 126: Introduction to Computing Science and Programming Fall 2007, Harbour Centre

Recursion. Chapter 7. Copyright 2012 by Pearson Education, Inc. All rights reserved

Cpt S 223 Course Overview. Cpt S 223, Fall 2007 Copyright: Washington State University

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

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

ECE250: Algorithms and Data Structures Midterm Review

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Course Review. Cpt S 223 Fall 2010

Divide and Conquer Algorithms

Transcription:

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16 In-Class Midterm ( 11:35 AM 12:50 PM : 75 Minutes ) This exam will account for either 15% or 30% of your overall grade depending on your relative performance in the midterm and the final. The higher of the two scores (midterm and final) will be worth 30% of your grade, and the lower one 15%. There are three (3) questions, worth 75 points in total. Please answer all of them in the spaces provided. There are 12 pages including four (4) blank pages. Please use the blank pages if you need additional space for your answers. The exam is open slides. So you can consult the lecture slides during the exam. No additional cheatsheets are allowed. Good Luck! Question Score Maximum 1. Pairing Numbers 20 2. Tower of Hanoi 25 3. Binomial Arrays 30 Total 75 Name: 1

Question 1. [ 20 Points ] Pairing Numbers. Suppose you are given two sets of numbers, say, A and B. For some integer n > 0, each set contains Θ (n) integers between 0 and n (inclusive), and no number occurs more than once in the set. Let C(m) denote the number of distinct pairs a, b with a A and b B such that a + b = m. For example, if A = {1, 7, 3} and B = {2, 1, 6} then C(9) = 2 as only the pairs 7, 2 and 3, 6 produce the sum 9, and C(6) = 0 as no two a A and b B sum up to 6. 1(a) [ 5 Points ] For any given integer m [0, 2n], show that the computation of C(m) requires Θ (n) time. 2

1(b) [ 15 Points ] Show that for 0 m 2n, one can compute all C(m) values simultaneously in O (n log n) time. 3

Use this page if you need additional space for your answers. 4

Question 2. [ 25 Points ] Tower of Hanoi. The following recurrences arise while trying to compute the minimum number of moves needed to solve the Tower of Hanoi problem with n discs when all moves must be clockwise 1. Let Q n and R n be the minimum number of moves required to transfer all n discs under the given restriction from the source pole to the target pole and from the target pole to the source pole, respectively. Then it can be shown that { 0 if n = 0, Q n = 2R n 1 + 1 otherwise; { 0 if n = 0, R n = Q n + Q n 1 + 1 otherwise. 2(a) [ 5 Points ] Show that one can rewrite the first recurrence as follows. 0 if n = 0, Q n = 1 if n = 1, 2 (Q n 1 + Q n 2 ) + 3 otherwise. 1 If A is the source pole, B is the target pole, and C is the intermediate pole, then each move must be either A B or B C or C A. 5

2(b) [ 20 Points ] Solve the recurrences to show that Q n = 1 2 3 [ ( 1 + n+1 ( 3) 1 ) ] n+1 3 1 and R n = 1 4 3 [ ( 1 + n+2 ( 3) 1 ) ] n+2 3 1. 6

Use this page if you need additional space for your answers. 7

Question 3. [ 30 Points ] Binomial Arrays. Searching for a given number in an array of n sorted numbers takes O (log n) time using binary search, but inserting a new number into this array can take Θ (n) time in the worst case. On the other hand, a new number can be inserted into an array of n unsorted numbers in Θ (1) time 2, but searching for a number in this unsorted array can take up to Θ (n) time. In this problem we will analyze a very simple data structure that can support both insert and search operations very efficiently 3. We will call the new data structure a binomial array which is nothing but a simple modification of the binomial heap data structure we saw in the class. If we replace each binomial tree B k of a binomial heap with an array A k of size 2 k containing all items of B k in sorted order, we get a binomial array (see Figure below). Note that though each individual array is sorted there is no particular relationship between elements of two different arrays. While a Link operation on a binomial heap links two binomial trees of the same size (say, two B k s) in Θ (1) time, the same operation on a binomial array merges two sorted arrays 4 of the same size, say two A k s, in Θ ( 2 k+1) time into another sorted array A k+1 of size 2 k+1. A binomial array supports only the following two operations: (i) Insert( x ) that inserts x into the data structure, and (ii) Search( x ) that returns True if x appears in the data structure, and False otherwise. An Insert operation is implemented in exactly the same way as in a binomial heap except that each Link operation now merges two arrays instead of linking two binomial trees. We start with an empty data structure, and perform Insert and Search operations on it in arbitrary order. 2 assuming the array has at least one empty space that can be located in Θ (1) time 3 not as efficiently as balanced binary search trees though, but they are very complicated 4 two sorted arrays of size n 1 and n 2 can be merged into a sorted array of size n 1 + n 2 in Θ (n 1 + n 2) time 8

3(a) [ 5 Points ] Show that an Insert operation on a binomial array containing n numbers can take Θ (n) time in the worst case. 3(b) [ 5 Points ] Show how to perform a Search operation on a binomial array containing n numbers in Θ ( log 2 n ) worst-case time. 9

3(c) [ 10 Points ] Define a potential function Φ in order to analyze the amortized complexity of Insert and Search operations assuming that we insert n numbers into the data structure. Remember to show that Φ (D 0 ) = 0 and Φ (D i ) 0 for all i > 0, where D i is the state of the data structure after the i th operation. 3(d) [ 10 Points ] Use your potential function from part 3(c) to argue that the amortized time complexity of Insert is O (log n) and that of Search is O ( log 2 n ). 10

Use this page if you need additional space for your answers. 11

Use this page if you need additional space for your answers. 12