Test One (Answer Key)

Similar documents
Recurrence Relations

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

Mathematical Foundation. CSE 6331 Algorithms Steve Lai

CS / MCS 401 Homework 3 grader solutions

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions

Read carefully the instructions on the answer book and make sure that the particulars required are entered on each answer book.

4.3 Growth Rates of Solutions to Recurrences

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply:

Sums, products and sequences

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides

MATH 324 Summer 2006 Elementary Number Theory Solutions to Assignment 2 Due: Thursday July 27, 2006

ITEC 360 Data Structures and Analysis of Algorithms Spring for n 1

COMP285 Midterm Exam Department of Mathematics

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

and each factor on the right is clearly greater than 1. which is a contradiction, so n must be prime.

Data Structures and Algorithm. Xiaoqing Zheng

Math 475, Problem Set #12: Answers

CSI 2101 Discrete Structures Winter Homework Assignment #4 (100 points, weight 5%) Due: Thursday, April 5, at 1:00pm (in lecture)

Department of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse Zurich Phone:

Infinite Sequences and Series

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials.

6.3 Testing Series With Positive Terms

Homework 9. (n + 1)! = 1 1

This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2

Optimally Sparse SVMs

Analysis of Algorithms. Introduction. Contents

Lecture 3: Asymptotic Analysis + Recurrences

Ch3. Asymptotic Notation

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc)

Algorithms and Data Structures Lecture IV

Math 113 Exam 4 Practice

Lesson 10: Limits and Continuity

CHAPTER I: Vector Spaces

Sequences, Mathematical Induction, and Recursion. CSE 2353 Discrete Computational Structures Spring 2018

Dynamic Programming. Sequence Of Decisions

Dynamic Programming. Sequence Of Decisions. 0/1 Knapsack Problem. Sequence Of Decisions

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, February 4/Tuesday, February 5

A recurrence equation is just a recursive function definition. It defines a function at one input in terms of its value on smaller inputs.

Math 140A Elementary Analysis Homework Questions 1

Algorithm Analysis. Algorithms that are equally correct can vary in their utilization of computational resources

6 Integers Modulo n. integer k can be written as k = qn + r, with q,r, 0 r b. So any integer.

Sequences A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence

1. By using truth tables prove that, for all statements P and Q, the statement

SCORE. Exam 2. MA 114 Exam 2 Fall 2016

Real Variables II Homework Set #5

62. Power series Definition 16. (Power series) Given a sequence {c n }, the series. c n x n = c 0 + c 1 x + c 2 x 2 + c 3 x 3 +

Math 113 Exam 3 Practice

Math 10A final exam, December 16, 2016

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia)

Advanced Course of Algorithm Design and Analysis

Chapter 22 Developing Efficient Algorithms

MATH 304: MIDTERM EXAM SOLUTIONS

Lecture Notes for CS 313H, Fall 2011

CS161: Algorithm Design and Analysis Handout #10 Stanford University Wednesday, 10 February 2016

Mathematics review for CSCI 303 Spring Department of Computer Science College of William & Mary Robert Michael Lewis

A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence

10.1 Sequences. n term. We will deal a. a n or a n n. ( 1) n ( 1) n 1 2 ( 1) a =, 0 0,,,,, ln n. n an 2. n term.

Chapter 4. Fourier Series

CS 336. of n 1 objects with order unimportant but repetition allowed.

SCORE. Exam 2. MA 114 Exam 2 Fall 2017

Math F215: Induction April 7, 2013

Math 113 Exam 3 Practice

Mathematical Induction

Exam 2 CMSC 203 Fall 2009 Name SOLUTION KEY Show All Work! 1. (16 points) Circle T if the corresponding statement is True or F if it is False.

Math 140A Elementary Analysis Homework Questions 3-1

MA131 - Analysis 1. Workbook 3 Sequences II

CHAPTER 1 SEQUENCES AND INFINITE SERIES

Math 155 (Lecture 3)

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN

MA131 - Analysis 1. Workbook 2 Sequences I

Model of Computation and Runtime Analysis

MAT1026 Calculus II Basic Convergence Tests for Series

sin(n) + 2 cos(2n) n 3/2 3 sin(n) 2cos(2n) n 3/2 a n =

In number theory we will generally be working with integers, though occasionally fractions and irrationals will come into play.

Fundamental Algorithms

CSE 1400 Applied Discrete Mathematics Number Theory and Proofs

NATIONAL UNIVERSITY OF SINGAPORE FACULTY OF SCIENCE SEMESTER 1 EXAMINATION ADVANCED CALCULUS II. November 2003 Time allowed :

MATH 10550, EXAM 3 SOLUTIONS

Basic Sets. Functions. MTH299 - Examples. Example 1. Let S = {1, {2, 3}, 4}. Indicate whether each statement is true or false. (a) S = 4. (e) 2 S.

Model Theory 2016, Exercises, Second batch, covering Weeks 5-7, with Solutions

The Discrete Fourier Transform

Please do NOT write in this box. Multiple Choice. Total

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU.

MATH301 Real Analysis (2008 Fall) Tutorial Note #7. k=1 f k (x) converges pointwise to S(x) on E if and

HOMEWORK 2 SOLUTIONS

3.2 Properties of Division 3.3 Zeros of Polynomials 3.4 Complex and Rational Zeros of Polynomials

Zeros of Polynomials

University of Colorado Denver Dept. Math. & Stat. Sciences Applied Analysis Preliminary Exam 13 January 2012, 10:00 am 2:00 pm. Good luck!

STAT Homework 1 - Solutions

Solutions to Final Exam

Randomized Algorithms I, Spring 2018, Department of Computer Science, University of Helsinki Homework 1: Solutions (Discussed January 25, 2018)

V. Adamchik 1. Recursions. Victor Adamchik Fall of x n1. x n 2. Here are a few first values of the above sequence (coded in Mathematica)

It is often useful to approximate complicated functions using simpler ones. We consider the task of approximating a function by a polynomial.

w (1) ˆx w (1) x (1) /ρ and w (2) ˆx w (2) x (2) /ρ.

Sequences and Series of Functions

Chapter 6. Advanced Counting Techniques

Fundamental Theorem of Algebra. Yvonne Lai March 2010

Problems with Solutions in the Analysis of Algorithms. Minko Markov

Chapter 0. Review of set theory. 0.1 Sets

Transcription:

CS395/Ma395 (Sprig 2005) Test Oe Name: Page 1 Test Oe (Aswer Key) CS395/Ma395: Aalysis of Algorithms This is a closed book, closed otes, 70 miute examiatio. It is worth 100 poits. There are twelve (12) questios o five (5) pages. Please put your ame o each page of this examiatio. Aswer Some of these aswers have far more detail tha was required from the test questio. For example, there are questios that ask for oly the recurrece, but the aswer has a full solutio. This is to help yo use this aswer key to prepare for future exams.

CS395/Ma395 (Sprig 2005) Test Oe Name: Page 2 Questio 1 [6 poits] Prove or disprove each of the followig: 1. log Ω( 2 ) 2. 3 Θ(2 ) ( + 2) 2 O( 4 ) Aswer 1. 2. log lim 2 log = lim = lim 1 = 0 (by simple maipulatios ad L Hôpitals rule) ad so log O( 2 ), but log Ω( 2 ). 3 ( ) 3 lim 2 = lim = 2 So 2 O(3 ), but 2 Ω(3 ) ad hece 3 Θ(2 ). ( + 2) 2 = 2 + 4 + 4 By the max rule, this is i O( 2 ), ad O( 2 ) O( 4 ) sice lim 2 1 lim = 0. 2 So ( + 2) 2 O( 4 ), but ( + 2) 2 Ω( 4 ). 4 = Questio 2 [5 poits] Show that the fuctio f() = 2 is 2-smooth. Aswer We eed to show that f() is evetually o-decreasig, ad that f(2) O(f()), where f() = 2. f() = 2 2 + 2 + 1 = ( + 1) 2 = f( + 1) for all 0, so f is clearly evetually odecreasig. Also, f(2) = (2) 2 = 4 2 O( 2 ) sice oe ca igore the costat factor of 4.

CS395/Ma395 (Sprig 2005) Test Oe Name: Page 3 Questio 3 [10 poits] Suppose algorithm Foo() has 2 istaces of size (for ay ) ad it requires steps for 2 1 of them, ad 2 + steps for the oe remaiig istace. What is the average case complexity of Foo()? Aswer It is the average umber of steps required for all istaces of size, which is ( (2 1)) + (2 + ) = 2 + 2 = + 1 2 2 So the umber of steps i the average case, assumig all iput istaces equally likely, is Θ() far better tha the worst case behavior of Θ(2 ). Questio 4 [10 poits] Suppose that algorithm Bar() uses at most Θ(2 ) i the worst case, but that k repetitios of Bar() always requires Θ(3k) time. What is the worst case ad amortized complexity of Foo()? Aswer Worst case is, by defiitio, Θ(2 ). But amortized complexity is Θ(3k/k) = Θ(1), per ivocatio. Questio 5 [5 poits] Suppose the algorithm MyAlg is O( 2 is a power of 2). What ca you say about the complexity of MyAlg, give the results of questio 2? Aswer We eed to show that f(2) O(f()), where f() = 2. But f(2) = (2) 2 = 4 2 O( 2 ) sice oe ca igore the costat factor of 4.

CS395/Ma395 (Sprig 2005) Test Oe Name: Page 4 Questio 6 [10 poits] Express the complexity of the followig algorithm as a recurrece relatio (do ot solve the recurrece!) Procedure fu(); { if ( > 0) { LoadsOfFu = 0; for i = 1 to { LoadsOfFu++; } retur (fu(/2) + fu(/2) + LoadsOfFu); // / is iteger divisio } else retur 1; } Aswer Let T () be the time for this algorithm i iput. The the time required is T () = + 2T (/2) + c This is the time for the loop, ad for the two recursive calls. It assumes that additio ad multiplicatio are elemetary operatios, ad that the istaces sizes are the values of. Questio 7 [4 poits] Suppose you test algorithm Foo o all iputs up to size = 10, ad it requires time as follows: 1 2 3 4 5 6 7 8 9 10 Time 2 5 9 17 33 65 129 257 513 1025 Ca you coclude that Foo is i Θ(2 )? Why or why ot? Aswer No, you caot. Asymptotic otatio is expressed i terms of behavior for sufficietly large. We have o assurace that = 10 is large eough these could all be special cases for the algorithm. Besides, you caot aalyze a algorithm from empirical behavior, that is aalyzig a process, ot a algorithm.

CS395/Ma395 (Sprig 2005) Test Oe Name: Page 5 Questio 8 [10 poits] Aalyze the worst case complexity of the followig algorithm. Procedure Foo(); { for i = 1 to do { for j = 1 to do { for k = j to do { cout << "Hello!"; } } } } Aswer The barometer will be the umber of Hello messages prited, ad we assume all operatios are uit time. The cout << will execute oce for every selectio of i,j,k, regardless of their order (sice oly oe order, amely i < j < k is relevat). There are O( ( ) 3 ) = O( 3 ) ways for this to happe. Or, otice that the two ier loops produce + ( 1) + + 2 + 1 = i=1 = ( + 1)/2 couts. These two loops get executed times, so the total umber of couts is ( + 1)/2 = ( 3 + 2 )/2 Θ( 3 ) total. Alteratively, make a table of the possible values for the three idex variables: i j k 1 1 1 2 2 2 3 3.. 2 1 1 2 2 2 3 3.. 3 1 1... 1 1..

CS395/Ma395 (Sprig 2005) Test Oe Name: Page 6 Questio 9 [10 poits] What is the characteristic polyomial for the followig recurrece? Aswer This yields t = 6t 1 9t 2 + 2 t 6t 1 + 9t 2 = 2 The characteristic polyomial for this recurrece is (x 2 6x + 9)(x 2) 2 = (x 3) 2 (x 2) 2 Questio 10 [10 poits] The recurrece t +1 5t +6 = 2 has a characteristic polyomial of (x 3)(x 2) 3 What is the closed form for this recurrece? Aswer This has root 3 with multiplicity 1 ad root 2 with multiplicity 3, so the closed form solutio is t = c 0 3 + c 1 2 + c 2 2 + c 3 2 2 for some costats c 0, c 1, c 2, ad c 3. This is clearly O(3 ).

CS395/Ma395 (Sprig 2005) Test Oe Name: Page 7 Questio 11 [10 poits] prove that the ith biomial tree, B i, has 2 i odes. Aswer The proof is by recursio o i. Base case (i = 0). B 0 has 1 ode by defiitio, ad 1 = 2 0. Assume the ith biomial tree has 2 i odes for 0 i k, ad prove that B k+1 has 2 k+1 odes. The umber of odes i B k+1 is oe, for the root, plus oe for each subtree of the root. By defiitio, these subtrees are B 0, B 1... B k. So, usig the iductive assumptio, B k+1 has 1+2 0 +2 1 + +2 k = 1+(2 k+1 1) = 2 k+1 odes, which was to be show. May people oticed that is is possible to defie biomial trees a differet way. Our defiitio i class was: B 0 is a sigle ode, B i+1 is a root ode with each of B 0... B i as a subtree. The above proof follows that defiitio. Alteratively, oe ca defie biomial trees as follows: B 0 is a sigle ode, B i+1 is B i with a copy of B i added as a subtree to the root of the first B i. Note that these are differet defiitios, but they defie the same objects (the proof of that fact is a good exercise, do t just take it for grated! The proof is by iductio.) Give this secod defiitio, oe ca prove that B i has 2 i odes as follows: Base case (i = 0). B 0 has a sigle ode by defiitio, ad 1 = 2 0. Assume the ith biomial tree has 2 k odes, ad prove that B k+1 has 2 k+1 odes. The umber of odes i B k+1 by defiitio is 2 2 k, usig the iductive assumptio, sice B k+1 comprises two copies of B k. But 2 2 k = 2 k+1, which was to be show. This ca also be prove, rather cleverly, by expressig the size of B i as a recurrece: s(0) = 1 ad s(i + 1) = 2s(i). Oe ca the solve this recurrece. The characteristic polyomial is: x 2 = 0, which has a closed form of c 1 2 + c 2 = 0. Solvig for the costats, give the iitial coditio (which is ecessary i this case) gives that c 2 = 0 ad c 1 = 1. So, the closed form for the recurrece is s(i) = 2 i, which was to be show! Note: bioomial trees are ot the same thig as biary trees. Several of you cofused the two, eve though I aouced durig the exam that the questio was ideed about the former!

CS395/Ma395 (Sprig 2005) Test Oe Name: Page 8 Questio 12 [10 poits] Why is the isert operatio for regular heaps (ot biomial heaps) a O(log ) operatio, whe the heap has elemets i it? Aswer Because regular heaps are essetially complete biary trees, ad so the height of the data structure is O(log ). The height of the structure is the maximum umber of data exchages required to move a elemet from the ext available slot to where it belogs, i order to restore the heap property. I gave extra credit for provig that the height of a full biary tree is log.