Analysis of Algorithms. Introduction. Contents

Size: px
Start display at page:

Download "Analysis of Algorithms. Introduction. Contents"

Transcription

1 Itroductio The focus of this module is mathematical aspects of algorithms. Our mai focus is aalysis of algorithms, which meas evaluatig efficiecy of algorithms by aalytical ad mathematical methods. We start by some simple examples of worst-case ad average-case aalysis. We the discuss the formal defiitios for asymptotic complexity of algorithms, used to characterize algorithms ito differet classes. Ad we preset examples of asymptotic aalysis of algorithms. The ext module deals with recursive algorithms, their correctess proofs, aalysis of algorithms by recurrece equatios, ad algorithmic divide-ad-coquer techique. Cotets Worst-case ad Average-Case Aalysis: Itroductory Examples Sequetial Search Fidig Max ad Mi Defiitios of Asymptotic Complexities O( ), Ω ( ), ad Θ( ) Sum Rule ad Product Rule Example of Aalysis: A Nested Loop Isertio Sort Algorithm Worst-Case Aalysis of Isertio Sort Average-Case Aalysis of Isertio Sort 1

2 Worst-case ad Average-Case Aalysis: Itroductory Examples Sequetial Search Algorithm Suppose we have a array of elemets A[1: ], ad a key elemet, KEY. The followig program is a simple loop which goes through the array sequetially util it either fids the key, or determies that it is ot foud. (dtype is the type declaratio for the array.) it SequetialSearch (dtype A[ ], it, dtype KEY) { for i = 1 to { if (KEY == A[i]) retur (i); }; retur ( 1); //The for-loop eded ad the key was ot foud. } Let us aalyze the umber of key-comparisos (highlighted) i this algorithm. By coutig this domiat operatio, basically we are coutig the umber of times the loop is executed. There are two commo ways of doig the aalysis: Worst-case aalysis: This determies the maximum amout of time the algorithm would ever take. This aalysis is usually easier tha the average-case aalysis. At the same time, it is hoped that it is a good reflectio of overall performace. Average-case aalysis: This method determies the overall average performace. It cosiders all possible cases, assigs a probability to each case, ad computes the weighted average (called expected value) for the radom variable (i this case, the umber of key-comparisos). Worst-Case Aalysis of Sequetial Search The worst-case umber of key-compariso i this algorithm is obviously. This happes if the key is foud i the last positio of the array, or if it is ot foud aywhere. Sice each iteratio of the for-loop takes at most some costat amout of time, C, the the total worst-case time of the algorithm is T() C + D. (The costat D represets the maximum amout of time for all statemets that are executed oly oce, idepedet of the variable. ) This total time is characterized as order of, deoted as O(). (We will shortly see the formal defiitio for the order.)

3 Average-Case Aalysis of Sequetial Search Now let us compute the average umber of key-comparisos. As a first estimate, oe may thik that sice the worst-case umber is, ad the best-case is 1 (foud right away), the the average must be about /. Let us do a careful aalysis ad see how good this estimate is. First, as a quick review the expected value, suppose a radom variable has the possible values {1,,3} with the followig probabilities. Value of the radom variable r Probability P r The the expected value of r is =.7 We may also refer to this as the weighted average. Note that a straight average (whe there is o probability ivolved) would be simply ( )/3 =. Now, to compute the expected value of the umber of key-comparisos for the algorithm, let ad let P = Probability that the key is foud somewhere i the array P i = Probability that the key is foud i positio i of the array, 1 i. Assumig that the array is radom, a commo assumptio is that whe the key is foud, the it is equally likely that it is foud i ay of the positios. So, P i = P, i. Fially, the probability that the key is ot foud is Q = 1 P 3

4 So, the expected umber of key-comparisos i this algorithm is: f() = P i i + Q = P i + (1 P) = P i + (1 P) (Use arithmetic sum formula) = P ( + 1) + (1 P) = P (1 P) I the special case whe P = 1, the expected umber of comparisos is +1, which agrees with our iitial estimate. Otherwise, there is a additioal term that takes ito accout the additioal evet whe the key is ot foud aywhere i the array. Fidig Max ad Mi of a Array The followig pseudocode is a simple program loop that fids the maximum ad miimum elemets i a array of elemets, A[1: ]. (Max ad Mi are the retured parameters.) FidMaxMi (dtype A[ ], it, dtype Max, dtype Mi) { Max = A[1]; Mi = A[1]; for i = to { if (A[i] > Max) Max = A[i]; else if (A[i] < Mi) Mi = A[i]; } I iteratio i of the for-loop, A[i] is first compared agaist Max. If A[i] is greater, the Max is updated. Otherwise, a secod compariso is made agaist Mi, ad if A[i] is smaller, the Mi is updated. Let us aalyze the worst-case, best-case, ad average-case umber of keycomparisos. (The key comparisos are highlighted.) 4

5 Worst-Case ad Best-Case Aalysis I the worst-case, every iteratio of the loop makes two comparisos. (This happes if the first elemet of the array has the largest value.) So the worst-case umber of comparisos is ( 1). I the best-case, every iteratio makes oly oe compariso, so the best-case umber of comparisos is ( 1). This happes if the iput is i sorted order. Average-Case Aalysis The umber of comparisos i each iteratio of the loop is i the worst-case, ad 1 i the best-case. So is it a good estimate to figure that o the average, the umber is 1.5 per iteratio?! No, the average is ot always half-way betwee the worst ad the best. (If I buy a lottery ticket, do I have a chace of wiig the jackpot?!) We will prove that it is much more likely to make two comparisos per iteratio. As a result, the expected umber of comparisos is very close to the worst-case umber. Let us assume the array is radom ad the elemets are all distict. Iteratio i of the loop compares elemet A[i] agaist the curret Max ad possibly Mi. Let us defie the prefix sequece of A[i] as the sequece of elemets i the array startig with A[1] ad edig with A[i] itself. A[1], A[],, A[i] Sice the array is radom, elemet A[i] is equally likely to be the smallest i its prefix, or the secod smallest, or third smallest,, or the largest. So, the probability that A[i] is the largest i its prefix sequece is ad the probability that A[i] is ot the largest i its prefix sequece is 1 i i 1 i If A[i] is the largest i its prefix, iteratio i makes oly oe compariso. Otherwise, iteratio i makes two comparisos. Therefore, the expected umber of comparisos is f() = ( 1 i 1 + i 1 ) = ( 1 i i ) = ( 1) 1 i i= i= i= = 1 1 i The latter summatio is kow as the Harmoic series H, ad the value of the sum is approximately l. (l is the atural log.) 5

6 1 i H = l Therefore, f() 1 l. Sice the value of the log is egligible compared to, the expected umber of comparisos is ideed very close to the worst-case value, as stated earlier. For example, if = 1000, the expected umber of key-compariso is about 199, ad the worst-case umber ( ) is (Note: Homework problems explore a techique for fidig approximate value of a summatio by covertig the summatio ito itegral. This techique may be used to fid the approximate value for the Harmoic sum.) Defiitios of Asymptotic Complexity Whe we study the ruig time of a algorithm, our focus is o the performace whe the problem size gets large. This is because the performace for small problem sizes hardly matters sice the ruig time will be very small ayway. Suppose there are two algorithms for a problem of size with the ruig times, respectively T 1 () = 10, T () = Which oe of the two is faster (smaller) ruig time? Let s tabulate these two fuctios for some values of ,000 0,000 1,000 10,000,000,000 10, ,000 00,000, ,

7 We observe that iitially, for < 5, T 1 is larger tha T. The two equal at = 5. Ad after that, as gets larger, T gets much larger tha T 1. This may also be observed pictorially, by lookig at the graphs of these fuctios (time-versus-). Time T (quadratic) T 1 (Liear, with slope of 10) The quadratic fuctio T starts smaller tha the liear oe T 1. The two cross at = 5. After that, T starts growig much faster tha T 1. As gets larger ad larger, T gets much larger tha T 1. We say that T has a faster growth rate tha T 1, or that T is asymptotically larger tha T 1. The fact that T 1 has a slower growth rate tha T is due to the fact that T 1 is a liear fuctio ad T is a quadratic fuctio. The coefficiets (also called costat factors) are ot as critical i this compariso. For example, suppose we have a differet pair of coefficiets: T 1 () = 50, T () = The cross poit betwee the two fuctios ow is = 50, ad after that T starts growig much faster tha T 1 agai. So, the asymptotic complexity defiitios icorporate two issues: 1. Focus o large problem size (large ), ad igore small values of.. Igore the costat coefficiets (costat factors). We are ow ready to make the formal defiitio. Defiitio 1: O( ) Upper Boud Suppose there are positive costats C ad 0 such that T() C f(), 0 The we say T() is O(f()). The O( ) is read as order of, or big oh of. 7

8 Example: Prove the followig fuctio is O( ). T() = Proof: Ituitively, whe gets large, the total value of this polyomial is close to 5 because the remaiig terms become egligible i compariso. Now, let us formally prove that T() is O( ) by fidig costats C ad 0 such that T() C, 0. T() = () ( ), 1 115, 1 This satisfies the defiitio ad proves T() is O( ). (Here C = 115 ad 0 = 1. ) But, to satisfy our ituitio, how do we fid the costat C closer to 5? By pickig a larger 0. Let s arbitrarily pick 100, so ( 100 ) 1. T() = ( ) ( ), , 100. Example: Prove the followig polyomial is O( 3 ). T() = Proof: Let s arbitrarily pick 10, so that ( 10 ) 1. T() = (discard egative terms) , ( 10 ), , 10. Next, we make the followig defiitio for the lower boud, which is symmetrical to O( ). Defiitio : Ω( ) Lower Boud Suppose there are positive costats C ad 0 such that T() C f(), 0 The we say T() is Ω(f()). 8

9 Example: Prove the followig polyomial is Ω( 3 ). T() = Proof: We must show that T() C 3, 0 for some positive costats C, 0. Here, we eed to pick 0 carefully so that C becomes positive. T() = (discard smaller positive terms) ( 3 ) 100 ( ), , 100. Defiitio 3: Θ( ) Tight Boud Suppose there are positive costats C 1, C, 0 such that C 1 f() T() C f(), 0 That is, T() is both O(f()) ad Ω(f()). The, we say that T() is Θ(f()). Example: We proved the followig polyomial is both O( 3 )ad Ω( 3 ). Therefore, T() is Θ( 3 ). Example: Suppose T() = T() 5 I this case, T() is Ω() ad O( ). But this fuctio does ot have a tight boud. Example: Prove the followig summatio is Θ( ), without the use of arithmetic sum formula, but rather by maipulatig the terms to fid the eeded upper boud ad lower boud. S() = Prove O( ): S() =

10 . Prove Ω( ): I the above proof for the upper boud, we raised all terms to the largest term. If we try to mimic that approach ad lower all terms to the smallest term, we get S() =, which will ot give the desired lower boud. Istead, we will first discard the first half of the terms, ad the lower all terms to the smallest. S() = = i i i= i= 4 We proved 4 S(). Therefore, S() is Θ( ). Sum-Rule ad Product-Rule Sum Rule for O( ): Suppose T 1 () is O(f()) ad T () is O(g()). The, T 1 () + T () is O(f() + g()). Proof: we first express T 1 () ad T () i terms of the defiitios of O(): T 1 () C 1 f(), 1 T () C g(), For max { 1, }, the two iequalities will both hold. So, T 1 () + T () C 1 f() + C g(), max{ 1, } Cf() + Cg(), C = max{c 1, C ) C(f() + g()). (Note: The sum rule similarly applies to Ω ad to Θ. ) 10

11 Applicatio of sum rule: Suppose a program has two parts: Part 1, which is executed first, ad the Part. Part 1 : Time T 1 () suppose O() Part : Time T () suppose O( ) The, the total time is O( + ), which is O( ). Product Rule for O( ) If T 1 () is O(f()) ad T () is O(g()), the, T 1 () T () is O(f() g()). Proof: Similar to the above proof; left to the studet. (Note: The product rule similarly applies to Ω ad to Θ. ) A applicatio of the product rule is i ested loops, as i the followig example. Example of Aalysis: A Nested Loop Let s aalyze the ruig time of the followig program (ested loops). C = 0 for i = 1 to + 1 for j = i to 3 1 C = C + 1 Ier loop umber of times = (3 1) (i) + 1 = 3 i Method 1 (Detailed Aalysis): Let us fid the total umber of times the iermost statemet (C = C + 1) is executed. That is, fid the fial value for C. Let F() deote this fial cout. We fid this cout by the followig double summatio F() = 1 j=i 11

12 The ier summatio for j is , so we fid the cout by: Upper limit of summatio lower limit of summatio + 1 = (3 1) (i) + 1 = 3 i. Ad the outer summatio is arithmetic sum, so we apply the formula for it F() = 1 j=i +1 = (3 i) (This is arithmetic sum) = ( + 1) (5 ) = ( + 1) = (3 1) + (3 1) The total umber of times the iermost statemet is executed is O( ), which meas the total ruig time of the program is also O( ). Method (Loop Aalysis): I this method, we do t bother to fid the exact total umber of times the iermost statemet is executed. Rather, we aalyze the loops by usig the sum-rule ad product-rule. The ier loop is executed 3 i times. Sice the rage of i values is 1 to + 1, the we kow 3 i is O(). The outer loop is executed + 1 times, which is O(). Therefore, by the product rule, the total ruig time is O( ). 1

13 Isertio Sort Algorithm Suppose we have a array of elemets, A[0: 1]. Isertio sort starts by sortig the first two elemets. The the third elemet is iserted ito the sorted part, so that the first 3 elemets are sorted. The, the ext elemet is iserted ito the sorted portio, so that the first 4 elemets become sorted, ad so o. Let us first illustrate by a umerical example. [7] Sort the first two [5 7] Isert 6 ito [5 7] [5 6 7] 4 3 Isert ito [5 6 7] [ 5 6 7] 4 3 Isert 4 ito [ 5 6 7] [ ] 3 Isert 3 ito [ ] [ ] Let s look at the details of each isertio phase. For example, let us see how the last isertio is carried out. At the start of this phase, the sorted part is [ ] ad elemet 3 eeds to be iserted ito the sorted part. This is doe by a sequece of compare/swap operatios betwee pairs, startig at the ed with the pair [7 3] [7 3] Cm/Swp 4 5 [6 3] 7 Cm/Swp 4 [5 3] 6 7 Cm/Swp [4 3] Cm/Swp [ 3] Compare We preset the pseudocode ext, ad the aalyze both the worst-case ad averagecase time complexity. Isertio Sort (datatype A[ ], it ) { //Iput array is A[0: 1] for i = 1 to 1 {// Isert A[i]. Everythig to the left of A[i] is already sorted. j = i; while (j > 0 ad A[j] < A[j 1]) {swap(a[j], A[j 1]); j = j 1}; }; } 13

14 Worst-Case Aalysis of Isertio Sort Method 1 (Fid the worst-case Exact Number of Operatios): Oe way to aalyze a algorithm is i terms of some domiat operatio, i this case a key compariso. This is a compariso betwee a pair of elemets i the array, which is highlighted i the above algorithm. By coutig this operatio, we are basically coutig the umber of times the ier loop (while loop) is executed. So, let f() be the worst-case umber of key comparisos i this algorithm The worst-case umber of key comparisos i the while loop is exactly i, because the loop starts with j = i ad i the worst case goes dow to j = 1. (Whe j = 0, the compariso is skipped.) Therefore, the worst-case umber of key-comparisos is: 1 f() = i = ( 1) = (Arithmetic sum formula was used to fid the sum.) So, we coclude that the worstcase total time of the algorithm is O( ). Method (Aalyze the Loops): The worst-case time of the ier while-loop is O(i), thus O(). This is because the rage of i values is 1 to 1. The outer loop (for loop) is executed O() times. By the product rule, the total worst-case time of the algorithm becomes O( ). Average-Case Aalysis of Isertio Sort We carry out the average case aalysis i two ways, oe i terms of the umber of key comparisos, ad the other i terms of the umber of swaps. Expected Number of Key-Comparisos: Cosider the while loop, where elemet A[i] is iserted ito the sorted part. If we assume the array is radom, the A[i] has equal probability of beig the largest, secod largest, third largest, ad so o. There are i + 1 cases, as listed i the table below. The table also shows the umber of keycomparisos made by the while loop for each case. Note that the last two cases both make the worst-case umber of key comparisos, which is i. 14

15 Evet If elemet A[i] is: 1 Largest Secod largest 3 Third Largest i 1 Third smallest i Secod smallest i + 1 Smallest Number of key comparisos made by the while-loop 1 3 i 1 i i Sice these (i + 1) cases all have equal probabilities, the expected umber of key comparisos made by the while loop is: (Sice the value of last term is small, i(i + 1) ( i) + i = + i i + 1 i + 1 i i+1 = i + i i + 1 < 1, the expected umber of key comparisos made by the while loop is about i/, which is half of the worst-case.) Therefore, the expected umber of key-comparisos for the etire algorithm is 1 ( i + i i + 1 ) = i + i = i + 1 < ( 1) ( 1) 1 ( 1) i i + 1 (The upper boud for the summatio is a fairly good approximatio. For example, for = 100, the value of the summatio becomes 95.) Expected Number of Swaps I the above table, we saw the last two cases both have i comparisos. This ouiformity resulted i a slight complicatio i the aalysis. This complicatio is avoided by aalyzig the expected umber of swaps. Let us agai look at the table of possible evets. 99 i i+1 Evet If elemet A[i] is: 1 Largest Secod largest 3 Third Largest i 1 Third smallest i Secod smallest i + 1 Smallest Number of SWAPS made by the while-loop i 1 i 15

16 Sice all i + 1 evets have equal probability, the expected umber of swaps for the while loop is i i + 1 = i So the expected umber of swaps for the etire algorithm is 1 i = ( 1) Alterative Aalysis for the Expected Number of Swaps: Suppose the iput sequece is a radom orderig of itegers 1 to. This aalysis cosiders all! possible iput orderigs, cout the umber of swaps for each case, ad average it over all possible cases. (We hope this aalysis provides additioal isight o how the expected performace may be computed.) Defie a pair of elemets (A[i], A[j]) i the array to be iverted (or out-of-order) if (i < j) ad A[i] > A[j]. Ad defie the total umber of iversios i a array as the umber of iverted pairs. Oe way to cout the umber of iversios is: 1 Number of elemets to the left of A[i] which are greater tha A[i]. From this formulatio, it should be obvious that the umber of iversios i a sequece is exactly equal to the umber of swap operatios made by the isertio-sort algorithm for that iput sequece. Suppose there are k elemets i the origial iput sequece to the left of A[i] with values greater tha A[i]. The, at the start of the while loop for isertig A[i], these k elemets will all be o the rightmost part of the sorted part, immediately to the left of A[i], as depicted below. (Elemets < A[i]) followed by (k elemets > A[i]) Sorted Part A[i] Elemet to be iserted The A[i] has to hop over the k elemets i order to get to where it eeds to be i the sorted part, which meas exactly k swaps. 16

17 The followig table shows a example for = 3. There are! = 6 possible iput sequeces. The umber of iversios for each sequece is show, as well as the overall average umber of iversios. Iput Sequece Number of Iversios Overall Average = 9/6 = 1.5 The iput sequeces may be partitioed ito pairs, such that each pair of sequeces are reverse of each other. For example, the reverse of [1 3 ] is the sequece [ 3 1]. The followig table shows the pairig of the 6 iput sequeces. Pairs of iput sequeces which are reverse of each other Number of iversios Average umber of iversios for each pair Overall Average: 1.5 I geeral, if a pair of elemets is iverted i oe sequece, the the pair is ot iverted i the reverse sequece, ad vice versa. For example: I the sequece [1 3 ], the pair (3, ) is iverted I the reverse sequece, [ 3 1], the pair (, 3) is ot iverted. This meas that each pair of values is iverted i oly oe of the two sequeces. So each pair cotributes 1 to the sum of iversios i the two sequeces. Therefore, the sum of iversios i each pair of reverse sequeces is the umber of pairs i a sequece of elemets, which is ( 1). So, the average umber of iversios for each pair of sequeces is W() = ( 1) 4 17

18 The overall average umber of iversios is also W(). Therefore, the expected umber of swaps i the algorithm is this exact umber. Deducig the Expected Number of Comparisos It is iterestig to ote that from the expected umber of swaps, we may arrive at the expected umber of comparisos rather quickly. Every key-compariso made by the while loop is followed by a swap, except possibly the last compariso before the termiatio of the while loop. This happes if (j > 0 ad A[j] A[j 1]), which meas that the elemet beig iserted is ot the smallest i its prefix sequece. This has the probability i (i + 1), as idicted earlier. So, with this probability, there is a last compariso i the while loop which is ot followed by a swap. Therefore, the expected umber of comparisos is 1 W() + which is the same as earlier. i ( 1) = i i < i + 1 ( 1)

Advanced Course of Algorithm Design and Analysis

Advanced Course of Algorithm Design and Analysis Differet complexity measures Advaced Course of Algorithm Desig ad Aalysis Asymptotic complexity Big-Oh otatio Properties of O otatio Aalysis of simple algorithms A algorithm may may have differet executio

More information

Design and Analysis of ALGORITHM (Topic 2)

Design and Analysis of ALGORITHM (Topic 2) DR. Gatot F. Hertoo, MSc. Desig ad Aalysis of ALGORITHM (Topic 2) Algorithms + Data Structures = Programs Lessos Leared 1 Our Machie Model: Assumptios Geeric Radom Access Machie (RAM) Executes operatios

More information

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU.

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU. Sortig Algorithms Algorithms Kyuseo Shim SoEECS, SNU. Desigig Algorithms Icremetal approaches Divide-ad-Coquer approaches Dyamic programmig approaches Greedy approaches Radomized approaches You are ot

More information

CS / MCS 401 Homework 3 grader solutions

CS / MCS 401 Homework 3 grader solutions CS / MCS 401 Homework 3 grader solutios assigmet due July 6, 016 writte by Jāis Lazovskis maximum poits: 33 Some questios from CLRS. Questios marked with a asterisk were ot graded. 1 Use the defiitio of

More information

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

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia) 1 CS 332: Algorithms Liear-Time Sortig. Order statistics. Slide credit: David Luebke (Virgiia) Quicksort: Partitio I Words Partitio(A, p, r): Select a elemet to act as the pivot (which?) Grow two regios,

More information

Ch3. Asymptotic Notation

Ch3. Asymptotic Notation Ch. Asymptotic Notatio copyright 006 Preview of Chapters Chapter How to aalyze the space ad time complexities of program Chapter Review asymptotic otatios such as O, Ω, Θ, o for simplifyig the aalysis

More information

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

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2 Geeral remarks Week 2 1 Divide ad First we cosider a importat tool for the aalysis of algorithms: Big-Oh. The we itroduce a importat algorithmic paradigm:. We coclude by presetig ad aalysig two examples.

More information

6.3 Testing Series With Positive Terms

6.3 Testing Series With Positive Terms 6.3. TESTING SERIES WITH POSITIVE TERMS 307 6.3 Testig Series With Positive Terms 6.3. Review of what is kow up to ow I theory, testig a series a i for covergece amouts to fidig the i= sequece of partial

More information

Data Structures and Algorithm. Xiaoqing Zheng

Data Structures and Algorithm. Xiaoqing Zheng Data Structures ad Algorithm Xiaoqig Zheg zhegxq@fudaeduc What are algorithms? A sequece of computatioal steps that trasform the iput ito the output Sortig problem: Iput: A sequece of umbers

More information

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

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc) Classificatio of problem & problem solvig strategies classificatio of time complexities (liear, arithmic etc) Problem subdivisio Divide ad Coquer strategy. Asymptotic otatios, lower boud ad upper boud:

More information

The Growth of Functions. Theoretical Supplement

The Growth of Functions. Theoretical Supplement The Growth of Fuctios Theoretical Supplemet The Triagle Iequality The triagle iequality is a algebraic tool that is ofte useful i maipulatig absolute values of fuctios. The triagle iequality says that

More information

Recurrence Relations

Recurrence Relations Recurrece Relatios Aalysis of recursive algorithms, such as: it factorial (it ) { if (==0) retur ; else retur ( * factorial(-)); } Let t be the umber of multiplicatios eeded to calculate factorial(). The

More information

CS:3330 (Prof. Pemmaraju ): Assignment #1 Solutions. (b) For n = 3, we will have 3 men and 3 women with preferences as follows: m 1 : w 3 > w 1 > w 2

CS:3330 (Prof. Pemmaraju ): Assignment #1 Solutions. (b) For n = 3, we will have 3 men and 3 women with preferences as follows: m 1 : w 3 > w 1 > w 2 Shiyao Wag CS:3330 (Prof. Pemmaraju ): Assigmet #1 Solutios Problem 1 (a) Cosider iput with me m 1, m,..., m ad wome w 1, w,..., w with the followig prefereces: All me have the same prefereces for wome:

More information

Chapter 22 Developing Efficient Algorithms

Chapter 22 Developing Efficient Algorithms Chapter Developig Efficiet Algorithms 1 Executig Time Suppose two algorithms perform the same task such as search (liear search vs. biary search). Which oe is better? Oe possible approach to aswer this

More information

Examples: data compression, path-finding, game-playing, scheduling, bin packing

Examples: data compression, path-finding, game-playing, scheduling, bin packing Algorithms - Basic Cocepts Algorithms so what is a algorithm, ayway? The dictioary defiitio: A algorithm is a well-defied computatioal procedure that takes iput ad produces output. This class will deal

More information

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis Recursive Algorithms Recurreces Computer Sciece & Egieerig 35: Discrete Mathematics Christopher M Bourke cbourke@cseuledu A recursive algorithm is oe i which objects are defied i terms of other objects

More information

4.3 Growth Rates of Solutions to Recurrences

4.3 Growth Rates of Solutions to Recurrences 4.3. GROWTH RATES OF SOLUTIONS TO RECURRENCES 81 4.3 Growth Rates of Solutios to Recurreces 4.3.1 Divide ad Coquer Algorithms Oe of the most basic ad powerful algorithmic techiques is divide ad coquer.

More information

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

CSI 2101 Discrete Structures Winter Homework Assignment #4 (100 points, weight 5%) Due: Thursday, April 5, at 1:00pm (in lecture) CSI 101 Discrete Structures Witer 01 Prof. Lucia Moura Uiversity of Ottawa Homework Assigmet #4 (100 poits, weight %) Due: Thursday, April, at 1:00pm (i lecture) Program verificatio, Recurrece Relatios

More information

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

ITEC 360 Data Structures and Analysis of Algorithms Spring for n 1 ITEC 360 Data Structures ad Aalysis of Algorithms Sprig 006 1. Prove that f () = 60 + 5 + 1 is Θ ( ). 60 + 5 + 1 60 + 5 + = 66 for 1 Take C 1 = 66 f () = 60 + 5 + 1 is O( ) Sice 60 + 5 + 1 60 for 1 If

More information

COMP285 Midterm Exam Department of Mathematics

COMP285 Midterm Exam Department of Mathematics COMP85 Midterm Exam Departmet of Mathematics Fall 010/011 - November 8, 010 Name: Studet Number: Please fiish withi 90 miutes. All poits above 100 are cosidered as bous poit. You ca reach maximal 1 poits.

More information

CS161 Design and Analysis of Algorithms. Administrative

CS161 Design and Analysis of Algorithms. Administrative CS161 Desig ad Aalysis of Algorithms Da Boeh 1 Admiistrative Lecture 1, April 3, 1 Web page http://theory.staford.edu/~dabo/cs161» Hadouts» Aoucemets» Late breakig ews Gradig ad course requiremets» Midterm/fial/hw»

More information

Skip Lists. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 S 3 S S 1

Skip Lists. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 S 3 S S 1 Presetatio for use with the textbook, Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Skip Lists S 3 15 15 23 10 15 23 36 Skip Lists 1 What is a Skip List A skip list for

More information

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES Peter M. Maurer Why Hashig is θ(). As i biary search, hashig assumes that keys are stored i a array which is idexed by a iteger. However, hashig attempts to bypass

More information

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

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions CSE 09/09 Topics i ig Data Aalytics Sprig 2017; Homework 1 Solutios Note: Solutios to problems,, ad 6 are due to Marius Nicolae. 1. Cosider the followig algorithm: for i := 1 to α log e do Pick a radom

More information

Algorithm Analysis. Chapter 3

Algorithm Analysis. Chapter 3 Data Structures Dr Ahmed Rafat Abas Computer Sciece Dept, Faculty of Computer ad Iformatio, Zagazig Uiversity arabas@zu.edu.eg http://www.arsaliem.faculty.zu.edu.eg/ Algorithm Aalysis Chapter 3 3. Itroductio

More information

Infinite Sequences and Series

Infinite Sequences and Series Chapter 6 Ifiite Sequeces ad Series 6.1 Ifiite Sequeces 6.1.1 Elemetary Cocepts Simply speakig, a sequece is a ordered list of umbers writte: {a 1, a 2, a 3,...a, a +1,...} where the elemets a i represet

More information

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

w (1) ˆx w (1) x (1) /ρ and w (2) ˆx w (2) x (2) /ρ. 2 5. Weighted umber of late jobs 5.1. Release dates ad due dates: maximimizig the weight of o-time jobs Oce we add release dates, miimizig the umber of late jobs becomes a sigificatly harder problem. For

More information

Test One (Answer Key)

Test One (Answer Key) 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)

More information

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

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides CS583 Lecture 02 Jaa Kosecka some materials here are based o E. Demaie, D. Luebke slides Previously Sample algorithms Exact ruig time, pseudo-code Approximate ruig time Worst case aalysis Best case aalysis

More information

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN CSI 5163 (95.5703) ALGORITHM ANALYSIS AND DESIGN (3 cr.) (T) Topics of curret iterest i the desig ad aalysis of computer algorithms for graphtheoretical

More information

Math 113 Exam 3 Practice

Math 113 Exam 3 Practice Math Exam Practice Exam will cover.-.9. This sheet has three sectios. The first sectio will remid you about techiques ad formulas that you should kow. The secod gives a umber of practice questios for you

More information

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

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, February 4/Tuesday, February 5 CIS 11 Data Structures ad Algorithms with Java Sprig 019 Code Sippets ad Recurreces Moday, February 4/Tuesday, February 5 Learig Goals Practice provig asymptotic bouds with code sippets Practice solvig

More information

Bertrand s Postulate

Bertrand s Postulate Bertrad s Postulate Lola Thompso Ross Program July 3, 2009 Lola Thompso (Ross Program Bertrad s Postulate July 3, 2009 1 / 33 Bertrad s Postulate I ve said it oce ad I ll say it agai: There s always a

More information

Average-Case Analysis of QuickSort

Average-Case Analysis of QuickSort Average-Case Aalysis of QuickSort Comp 363 Fall Semester 003 October 3, 003 The purpose of this documet is to itroduce the idea of usig recurrece relatios to do average-case aalysis. The average-case ruig

More information

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

A recurrence equation is just a recursive function definition. It defines a function at one input in terms of its value on smaller inputs. CS23 Algorithms Hadout #6 Prof Ly Turbak September 8, 200 Wellesley College RECURRENCES This hadout summarizes highlights of CLRS Chapter 4 ad Appedix A (CLR Chapters 3 & 4) Two-Step Strategy for Aalyzig

More information

Seunghee Ye Ma 8: Week 5 Oct 28

Seunghee Ye Ma 8: Week 5 Oct 28 Week 5 Summary I Sectio, we go over the Mea Value Theorem ad its applicatios. I Sectio 2, we will recap what we have covered so far this term. Topics Page Mea Value Theorem. Applicatios of the Mea Value

More information

Analysis of Algorithms -Quicksort-

Analysis of Algorithms -Quicksort- Aalysis of Algorithms -- Adreas Ermedahl MRTC (Mälardales Real-Time Research Ceter) adreas.ermedahl@mdh.se Autum 2004 Proposed by C.A.R. Hoare i 962 Worst- case ruig time: Θ( 2 ) Expected ruig time: Θ(

More information

Math 155 (Lecture 3)

Math 155 (Lecture 3) Math 55 (Lecture 3) September 8, I this lecture, we ll cosider the aswer to oe of the most basic coutig problems i combiatorics Questio How may ways are there to choose a -elemet subset of the set {,,,

More information

Model of Computation and Runtime Analysis

Model of Computation and Runtime Analysis Model of Computatio ad Rutime Aalysis Model of Computatio Model of Computatio Specifies Set of operatios Cost of operatios (ot ecessarily time) Examples Turig Machie Radom Access Machie (RAM) PRAM Map

More information

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

Algorithm Analysis. Algorithms that are equally correct can vary in their utilization of computational resources Algorithm Aalysis Algorithms that are equally correct ca vary i their utilizatio of computatioal resources time ad memory a slow program it is likely ot to be used a program that demads too much memory

More information

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

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials. Divide-ad-coquer algorithms Divide & Coquer Strategy: Divide the problem ito smaller subproblems of the same type of problem Solve the subproblems recursively Combie the aswers to solve the origial problem

More information

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

This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2 This Lecture Divide-ad-coquer techique for algorithm desig. Example the merge sort. Writig ad solvig recurreces Divide ad Coquer Divide-ad-coquer method for algorithm desig: Divide: If the iput size is

More information

The Random Walk For Dummies

The Random Walk For Dummies The Radom Walk For Dummies Richard A Mote Abstract We look at the priciples goverig the oe-dimesioal discrete radom walk First we review five basic cocepts of probability theory The we cosider the Beroulli

More information

Math 475, Problem Set #12: Answers

Math 475, Problem Set #12: Answers Math 475, Problem Set #12: Aswers A. Chapter 8, problem 12, parts (b) ad (d). (b) S # (, 2) = 2 2, sice, from amog the 2 ways of puttig elemets ito 2 distiguishable boxes, exactly 2 of them result i oe

More information

SECTION 1.5 : SUMMATION NOTATION + WORK WITH SEQUENCES

SECTION 1.5 : SUMMATION NOTATION + WORK WITH SEQUENCES SECTION 1.5 : SUMMATION NOTATION + WORK WITH SEQUENCES Read Sectio 1.5 (pages 5 9) Overview I Sectio 1.5 we lear to work with summatio otatio ad formulas. We will also itroduce a brief overview of sequeces,

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Desig ad Aalysis of Algorithms CSE 53 Lecture 9 Media ad Order Statistics Juzhou Huag, Ph.D. Departmet of Computer Sciece ad Egieerig Dept. CSE, UT Arligto CSE53 Desig ad Aalysis of Algorithms Medias ad

More information

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary Recursive Algorithm for Geeratig Partitios of a Iteger Sug-Hyuk Cha Computer Sciece Departmet, Pace Uiversity 1 Pace Plaza, New York, NY 10038 USA scha@pace.edu Abstract. This article first reviews the

More information

INTEGRATION BY PARTS (TABLE METHOD)

INTEGRATION BY PARTS (TABLE METHOD) INTEGRATION BY PARTS (TABLE METHOD) Suppose you wat to evaluate cos d usig itegratio by parts. Usig the u dv otatio, we get So, u dv d cos du d v si cos d si si d or si si d We see that it is ecessary

More information

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

Sequences A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence Sequeces A sequece of umbers is a fuctio whose domai is the positive itegers. We ca see that the sequece 1, 1, 2, 2, 3, 3,... is a fuctio from the positive itegers whe we write the first sequece elemet

More information

1 Hash tables. 1.1 Implementation

1 Hash tables. 1.1 Implementation Lecture 8 Hash Tables, Uiversal Hash Fuctios, Balls ad Bis Scribes: Luke Johsto, Moses Charikar, G. Valiat Date: Oct 18, 2017 Adapted From Virgiia Williams lecture otes 1 Hash tables A hash table is a

More information

CSE 202 Homework 1 Matthias Springer, A Yes, there does always exist a perfect matching without a strong instability.

CSE 202 Homework 1 Matthias Springer, A Yes, there does always exist a perfect matching without a strong instability. CSE 0 Homework 1 Matthias Spriger, A9950078 1 Problem 1 Notatio a b meas that a is matched to b. a < b c meas that b likes c more tha a. Equality idicates a tie. Strog istability Yes, there does always

More information

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

CS161: Algorithm Design and Analysis Handout #10 Stanford University Wednesday, 10 February 2016 CS161: Algorithm Desig ad Aalysis Hadout #10 Staford Uiversity Wedesday, 10 February 2016 Lecture #11: Wedesday, 10 February 2016 Topics: Example midterm problems ad solutios from a log time ago Sprig

More information

Data Structures Lecture 9

Data Structures Lecture 9 Fall 2017 Fag Yu Software Security Lab. Dept. Maagemet Iformatio Systems, Natioal Chegchi Uiversity Data Structures Lecture 9 Midterm o Dec. 7 (9:10-12:00am, 106) Lec 1-9, TextBook Ch1-8, 11,12 How to

More information

MA131 - Analysis 1. Workbook 2 Sequences I

MA131 - Analysis 1. Workbook 2 Sequences I MA3 - Aalysis Workbook 2 Sequeces I Autum 203 Cotets 2 Sequeces I 2. Itroductio.............................. 2.2 Icreasig ad Decreasig Sequeces................ 2 2.3 Bouded Sequeces..........................

More information

Divide and Conquer. 1 Overview. 2 Multiplying Bit Strings. COMPSCI 330: Design and Analysis of Algorithms 1/19/2016 and 1/21/2016

Divide and Conquer. 1 Overview. 2 Multiplying Bit Strings. COMPSCI 330: Design and Analysis of Algorithms 1/19/2016 and 1/21/2016 COMPSCI 330: Desig ad Aalysis of Algorithms 1/19/2016 ad 1/21/2016 Lecturer: Debmalya Paigrahi Divide ad Coquer Scribe: Tiaqi Sog 1 Overview I this lecture, a importat algorithm desig techique called divide-ad-coquer

More information

Trial division, Pollard s p 1, Pollard s ρ, and Fermat s method. Christopher Koch 1. April 8, 2014

Trial division, Pollard s p 1, Pollard s ρ, and Fermat s method. Christopher Koch 1. April 8, 2014 Iteger Divisio Algorithm ad Cogruece Iteger Trial divisio,,, ad with itegers mod Iverses mod Multiplicatio ad GCD Iteger Christopher Koch 1 1 Departmet of Computer Sciece ad Egieerig CSE489/589 Algorithms

More information

An Introduction to Randomized Algorithms

An Introduction to Randomized Algorithms A Itroductio to Radomized Algorithms The focus of this lecture is to study a radomized algorithm for quick sort, aalyze it usig probabilistic recurrece relatios, ad also provide more geeral tools for aalysis

More information

Model of Computation and Runtime Analysis

Model of Computation and Runtime Analysis Model of Computatio ad Rutime Aalysis Model of Computatio Model of Computatio Specifies Set of operatios Cost of operatios (ot ecessarily time) Examples Turig Machie Radom Access Machie (RAM) PRAM Map

More information

Random Models. Tusheng Zhang. February 14, 2013

Random Models. Tusheng Zhang. February 14, 2013 Radom Models Tusheg Zhag February 14, 013 1 Radom Walks Let me describe the model. Radom walks are used to describe the motio of a movig particle (object). Suppose that a particle (object) moves alog the

More information

The Binomial Theorem

The Binomial Theorem The Biomial Theorem Robert Marti Itroductio The Biomial Theorem is used to expad biomials, that is, brackets cosistig of two distict terms The formula for the Biomial Theorem is as follows: (a + b ( k

More information

COMPUTING SUMS AND THE AVERAGE VALUE OF THE DIVISOR FUNCTION (x 1) + x = n = n.

COMPUTING SUMS AND THE AVERAGE VALUE OF THE DIVISOR FUNCTION (x 1) + x = n = n. COMPUTING SUMS AND THE AVERAGE VALUE OF THE DIVISOR FUNCTION Abstract. We itroduce a method for computig sums of the form f( where f( is ice. We apply this method to study the average value of d(, where

More information

Lecture 3: Asymptotic Analysis + Recurrences

Lecture 3: Asymptotic Analysis + Recurrences Lecture 3: Asymptotic Aalysis + Recurreces Data Structures ad Algorithms CSE 373 SU 18 BEN JONES 1 Warmup Write a model ad fid Big-O for (it i = 0; i < ; i++) { for (it j = 0; j < i; j++) { System.out.pritl(

More information

NICK DUFRESNE. 1 1 p(x). To determine some formulas for the generating function of the Schröder numbers, r(x) = a(x) =

NICK DUFRESNE. 1 1 p(x). To determine some formulas for the generating function of the Schröder numbers, r(x) = a(x) = AN INTRODUCTION TO SCHRÖDER AND UNKNOWN NUMBERS NICK DUFRESNE Abstract. I this article we will itroduce two types of lattice paths, Schröder paths ad Ukow paths. We will examie differet properties of each,

More information

Lecture 2: April 3, 2013

Lecture 2: April 3, 2013 TTIC/CMSC 350 Mathematical Toolkit Sprig 203 Madhur Tulsiai Lecture 2: April 3, 203 Scribe: Shubhedu Trivedi Coi tosses cotiued We retur to the coi tossig example from the last lecture agai: Example. Give,

More information

Math 61CM - Solutions to homework 3

Math 61CM - Solutions to homework 3 Math 6CM - Solutios to homework 3 Cédric De Groote October 2 th, 208 Problem : Let F be a field, m 0 a fixed oegative iteger ad let V = {a 0 + a x + + a m x m a 0,, a m F} be the vector space cosistig

More information

Notes for Lecture 5. 1 Grover Search. 1.1 The Setting. 1.2 Motivation. Lecture 5 (September 26, 2018)

Notes for Lecture 5. 1 Grover Search. 1.1 The Setting. 1.2 Motivation. Lecture 5 (September 26, 2018) COS 597A: Quatum Cryptography Lecture 5 (September 6, 08) Lecturer: Mark Zhadry Priceto Uiversity Scribe: Fermi Ma Notes for Lecture 5 Today we ll move o from the slightly cotrived applicatios of quatum

More information

Sums, products and sequences

Sums, products and sequences Sums, products ad sequeces How to write log sums, e.g., 1+2+ (-1)+ cocisely? i=1 Sum otatio ( sum from 1 to ): i 3 = 1 + 2 + + If =3, i=1 i = 1+2+3=6. The ame ii does ot matter. Could use aother letter

More information

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

A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence Sequeces A sequece of umbers is a fuctio whose domai is the positive itegers. We ca see that the sequece,, 2, 2, 3, 3,... is a fuctio from the positive itegers whe we write the first sequece elemet as

More information

INFINITE SEQUENCES AND SERIES

INFINITE SEQUENCES AND SERIES 11 INFINITE SEQUENCES AND SERIES INFINITE SEQUENCES AND SERIES 11.4 The Compariso Tests I this sectio, we will lear: How to fid the value of a series by comparig it with a kow series. COMPARISON TESTS

More information

Math 2784 (or 2794W) University of Connecticut

Math 2784 (or 2794W) University of Connecticut ORDERS OF GROWTH PAT SMITH Math 2784 (or 2794W) Uiversity of Coecticut Date: Mar. 2, 22. ORDERS OF GROWTH. Itroductio Gaiig a ituitive feel for the relative growth of fuctios is importat if you really

More information

Axioms of Measure Theory

Axioms of Measure Theory MATH 532 Axioms of Measure Theory Dr. Neal, WKU I. The Space Throughout the course, we shall let X deote a geeric o-empty set. I geeral, we shall ot assume that ay algebraic structure exists o X so that

More information

Physics 116A Solutions to Homework Set #1 Winter Boas, problem Use equation 1.8 to find a fraction describing

Physics 116A Solutions to Homework Set #1 Winter Boas, problem Use equation 1.8 to find a fraction describing Physics 6A Solutios to Homework Set # Witer 0. Boas, problem. 8 Use equatio.8 to fid a fractio describig 0.694444444... Start with the formula S = a, ad otice that we ca remove ay umber of r fiite decimals

More information

Disjoint set (Union-Find)

Disjoint set (Union-Find) CS124 Lecture 7 Fall 2018 Disjoit set (Uio-Fid) For Kruskal s algorithm for the miimum spaig tree problem, we foud that we eeded a data structure for maitaiig a collectio of disjoit sets. That is, we eed

More information

CS161 Handout 05 Summer 2013 July 10, 2013 Mathematical Terms and Identities

CS161 Handout 05 Summer 2013 July 10, 2013 Mathematical Terms and Identities CS161 Hadout 05 Summer 2013 July 10, 2013 Mathematical Terms ad Idetities Thaks to Ady Nguye ad Julie Tibshirai for their advice o this hadout. This hadout covers mathematical otatio ad idetities that

More information

Chapter 6. Advanced Counting Techniques

Chapter 6. Advanced Counting Techniques Chapter 6 Advaced Coutig Techiques 6.: Recurrece Relatios Defiitio: A recurrece relatio for the sequece {a } is a equatio expressig a i terms of oe or more of the previous terms of the sequece: a,a2,a3,,a

More information

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

Sequences, Mathematical Induction, and Recursion. CSE 2353 Discrete Computational Structures Spring 2018 CSE 353 Discrete Computatioal Structures Sprig 08 Sequeces, Mathematical Iductio, ad Recursio (Chapter 5, Epp) Note: some course slides adopted from publisher-provided material Overview May mathematical

More information

CS 332: Algorithms. Quicksort

CS 332: Algorithms. Quicksort CS 33: Aorithms Quicsort David Luebe //03 Homewor Assiged today, due ext Wedesday Will be o web page shortly after class Go over ow David Luebe //03 Review: Quicsort Sorts i place Sorts O( ) i the average

More information

Sequences I. Chapter Introduction

Sequences I. Chapter Introduction Chapter 2 Sequeces I 2. Itroductio A sequece is a list of umbers i a defiite order so that we kow which umber is i the first place, which umber is i the secod place ad, for ay atural umber, we kow which

More information

Chapter 10: Power Series

Chapter 10: Power Series Chapter : Power Series 57 Chapter Overview: Power Series The reaso series are part of a Calculus course is that there are fuctios which caot be itegrated. All power series, though, ca be itegrated because

More information

CS 330 Discussion - Probability

CS 330 Discussion - Probability CS 330 Discussio - Probability March 24 2017 1 Fudametals of Probability 11 Radom Variables ad Evets A radom variable X is oe whose value is o-determiistic For example, suppose we flip a coi ad set X =

More information

CHAPTER 10 INFINITE SEQUENCES AND SERIES

CHAPTER 10 INFINITE SEQUENCES AND SERIES CHAPTER 10 INFINITE SEQUENCES AND SERIES 10.1 Sequeces 10.2 Ifiite Series 10.3 The Itegral Tests 10.4 Compariso Tests 10.5 The Ratio ad Root Tests 10.6 Alteratig Series: Absolute ad Coditioal Covergece

More information

Optimization Methods: Linear Programming Applications Assignment Problem 1. Module 4 Lecture Notes 3. Assignment Problem

Optimization Methods: Linear Programming Applications Assignment Problem 1. Module 4 Lecture Notes 3. Assignment Problem Optimizatio Methods: Liear Programmig Applicatios Assigmet Problem Itroductio Module 4 Lecture Notes 3 Assigmet Problem I the previous lecture, we discussed about oe of the bech mark problems called trasportatio

More information

ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER / Statistics

ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER / Statistics ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER 1 018/019 DR. ANTHONY BROWN 8. Statistics 8.1. Measures of Cetre: Mea, Media ad Mode. If we have a series of umbers the

More information

Mathematical Foundation. CSE 6331 Algorithms Steve Lai

Mathematical Foundation. CSE 6331 Algorithms Steve Lai Mathematical Foudatio CSE 6331 Algorithms Steve Lai Complexity of Algorithms Aalysis of algorithm: to predict the ruig time required by a algorithm. Elemetary operatios: arithmetic & boolea operatios:

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Desig ad Aalysis of Algorithms Probabilistic aalysis ad Radomized algorithms Referece: CLRS Chapter 5 Topics: Hirig problem Idicatio radom variables Radomized algorithms Huo Hogwei 1 The hirig problem

More information

(b) What is the probability that a particle reaches the upper boundary n before the lower boundary m?

(b) What is the probability that a particle reaches the upper boundary n before the lower boundary m? MATH 529 The Boudary Problem The drukard s walk (or boudary problem) is oe of the most famous problems i the theory of radom walks. Oe versio of the problem is described as follows: Suppose a particle

More information

Math 113, Calculus II Winter 2007 Final Exam Solutions

Math 113, Calculus II Winter 2007 Final Exam Solutions Math, Calculus II Witer 7 Fial Exam Solutios (5 poits) Use the limit defiitio of the defiite itegral ad the sum formulas to compute x x + dx The check your aswer usig the Evaluatio Theorem Solutio: I this

More information

Discrete Mathematics for CS Spring 2007 Luca Trevisan Lecture 22

Discrete Mathematics for CS Spring 2007 Luca Trevisan Lecture 22 CS 70 Discrete Mathematics for CS Sprig 2007 Luca Trevisa Lecture 22 Aother Importat Distributio The Geometric Distributio Questio: A biased coi with Heads probability p is tossed repeatedly util the first

More information

Complex Numbers Solutions

Complex Numbers Solutions Complex Numbers Solutios Joseph Zoller February 7, 06 Solutios. (009 AIME I Problem ) There is a complex umber with imagiary part 64 ad a positive iteger such that Fid. [Solutio: 697] 4i + + 4i. 4i 4i

More information

In algebra one spends much time finding common denominators and thus simplifying rational expressions. For example:

In algebra one spends much time finding common denominators and thus simplifying rational expressions. For example: 74 The Method of Partial Fractios I algebra oe speds much time fidig commo deomiators ad thus simplifyig ratioal epressios For eample: + + + 6 5 + = + = = + + + + + ( )( ) 5 It may the seem odd to be watig

More information

THE SOLUTION OF NONLINEAR EQUATIONS f( x ) = 0.

THE SOLUTION OF NONLINEAR EQUATIONS f( x ) = 0. THE SOLUTION OF NONLINEAR EQUATIONS f( ) = 0. Noliear Equatio Solvers Bracketig. Graphical. Aalytical Ope Methods Bisectio False Positio (Regula-Falsi) Fied poit iteratio Newto Raphso Secat The root of

More information

Introduction to Machine Learning DIS10

Introduction to Machine Learning DIS10 CS 189 Fall 017 Itroductio to Machie Learig DIS10 1 Fu with Lagrage Multipliers (a) Miimize the fuctio such that f (x,y) = x + y x + y = 3. Solutio: The Lagragia is: L(x,y,λ) = x + y + λ(x + y 3) Takig

More information

On a Smarandache problem concerning the prime gaps

On a Smarandache problem concerning the prime gaps O a Smaradache problem cocerig the prime gaps Felice Russo Via A. Ifate 7 6705 Avezzao (Aq) Italy felice.russo@katamail.com Abstract I this paper, a problem posed i [] by Smaradache cocerig the prime gaps

More information

COMP26120: Introducing Complexity Analysis (2018/19) Lucas Cordeiro

COMP26120: Introducing Complexity Analysis (2018/19) Lucas Cordeiro COMP60: Itroduig Complexity Aalysis (08/9) Luas Cordeiro luas.ordeiro@mahester.a.uk Itroduig Complexity Aalysis Textbook: Algorithm Desig ad Appliatios, Goodrih, Mihael T. ad Roberto Tamassia (hapter )

More information

Math 116 Second Midterm November 13, 2017

Math 116 Second Midterm November 13, 2017 Math 6 Secod Midterm November 3, 7 EXAM SOLUTIONS. Do ot ope this exam util you are told to do so.. Do ot write your ame aywhere o this exam. 3. This exam has pages icludig this cover. There are problems.

More information

Problem Set 2 Solutions

Problem Set 2 Solutions CS271 Radomess & Computatio, Sprig 2018 Problem Set 2 Solutios Poit totals are i the margi; the maximum total umber of poits was 52. 1. Probabilistic method for domiatig sets 6pts Pick a radom subset S

More information

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

Randomized Algorithms I, Spring 2018, Department of Computer Science, University of Helsinki Homework 1: Solutions (Discussed January 25, 2018) Radomized Algorithms I, Sprig 08, Departmet of Computer Sciece, Uiversity of Helsiki Homework : Solutios Discussed Jauary 5, 08). Exercise.: Cosider the followig balls-ad-bi game. We start with oe black

More information

September 2012 C1 Note. C1 Notes (Edexcel) Copyright - For AS, A2 notes and IGCSE / GCSE worksheets 1

September 2012 C1 Note. C1 Notes (Edexcel) Copyright   - For AS, A2 notes and IGCSE / GCSE worksheets 1 September 0 s (Edecel) Copyright www.pgmaths.co.uk - For AS, A otes ad IGCSE / GCSE worksheets September 0 Copyright www.pgmaths.co.uk - For AS, A otes ad IGCSE / GCSE worksheets September 0 Copyright

More information

Optimally Sparse SVMs

Optimally Sparse SVMs A. Proof of Lemma 3. We here prove a lower boud o the umber of support vectors to achieve geeralizatio bouds of the form which we cosider. Importatly, this result holds ot oly for liear classifiers, but

More information

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

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply: Departmet of Iformatics Prof. Dr. Michael Böhle Bizmühlestrasse 14 8050 Zurich Phoe: +41 44 635 4333 Email: boehle@ifi.uzh.ch AlgoDat Midterm1 Sprig 016 08.04.016 Name: Matriculatio umber: Advice You have

More information