CS/SE 2C03. Sample solutions to the assignment 1.

Size: px
Start display at page:

Download "CS/SE 2C03. Sample solutions to the assignment 1."

Transcription

1 CS/SE 2C03. Sample solutions to the assignment 1. Total of this assignment is 131pts, but 100% = 111pts. There are 21 bonus points. Each assignment is worth 7%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right, and resubmit to me during class, office hours, or just slip under the door to my office. The deadline for a complaint is 2 weeks after the assignment is marked and returned. 1.[10] Using only definition of O(f(n)) prove that the following statements are true: a.[2] (23n n 2 log n + 15)/2 n +105= O(1) Let c=144. Let n 1 be the solution for n 1200 = 2 n, then, when n n 1, n n. Let n 2 be the solution for n 2 log n = 2 n, then, when n n 2, n 2 log n 2 n. Let n 3 = 4, then, when n n 3, 15 2 n. Let n 0 = max(n 1, n 2, n 3 ), then, n n, n 2 log n 2 n, 15 2 n. Therefore, (23n n 2 log n + 15)/2 n hold. b.[2] 5n 3 2 n + n3 n = O(4 n ) Let c=6, n 0 =16=2 4. First n 3 = 2 3logn, and n 2 = (4/3) (2/(log4/3))logn (check it by apply logarithm for both side) For all n 16, 5n 3 2 n = 5*2 3logn 2 n 5*2 n 2 n = 5*4 n n 2 3 n = (4/3) (2/(log4/3))logn * 3 n (4/3) n * 3 n = 4 n Then, 5*n 3 2 n + n 2 3 n 6*4 n hold. c.[2] max(n(log n) 2,n(n-1)/6)=O(n 2 ) Let c=1, n 0 =128 = 2 7, for all n 2 7, First, We can show by induction, for all m=7, m 2 2 m-1 For all n n 0, 2 m-1 n 2 m-1, for some m, and m > 7. Therefore, (log n) 2 m 2 2 m-1 n log n n 1/2 n(logn) 2 n*n = n 2. n(n-1)/6 n(n-1) n*n = n 2. Then, max(n(logn) 2, n(n-1)/6) n 2 hold. d.[2] nlog n 8 + n 3/2 = O(n 3/2 ) Let c=9, n 0 =128 = 2 7, for all n 2 7, From part (c), (log n) 2 n log n n 1/2 Hence, nlog n 8 + n 3/2 = 8*nlog n + n 3/2 8*n*n 1/2 + n 3/2 = 9*n 3/2 e.[2] 5nlog n + n 3/2 = O(n 2 ) Let c=6, n 0 =2. For all n 2, log n n, and n 1/2 n. Then, 5nlog n + n 3/2 6*n 2 hold. 1

2 2.[10] Using only definition of O(f(n)) prove that the following statements are false: a.[2] (n 2 + 2n +3)/(log n + 1) = O(n) For all c 0, take n 0 = c 2. For all n c, (n 2 + 2n +3)/(log n + 1) c*n 3/2 /(log n + 1) c*n*n 1/2 /(log n+1) c*n hold. b.[2] n /(1500n 1/3 + 56)=O(1) For all c 0, take n 0 = (2000c) 3/2. For all n n 0, n /(1500n 1/3 + 56) = n 1/3 *n 2/3 /(1500n 1/3 + 56) = 2000c* n 1/3 /(1500n 1/3 + 56) c hold c.[2] max(n 3 +n+1,10nlog n)=o(n 2 ) For all c 0, take n 0 = 10c. For all n 10c, n 3 10c*n 2 10nlog n Then, max(n 3 +n+1,10nlog n) = n 3 +n+1 10c*n 2 c*n 2 hold. d.[2] log n 2 + n 1/3 = O(1) For all c 0, take n 0 = c 3. For all n n 0, log n 2 + n 1/3 log n 2 + (c 3 ) 1/3 = log c + c c hold. e.[2] (log n + n 1/4 )/5 = O(log n) For all c 0, take n 0 = (5c) 8. For all n n 0, log n + n 1/4 log n + n 1/8 *n 1/8 log n + 5c*n 1/8 5c*log n hold. 3.[3] Suppose the function f(n) satisfy the following, there is n 0 such that for each n > n 0, f(n) f(n+1). Prove that f(n) = O(1). Let c = f(n 0 ). Clearly, for all n > n 0, f(n) c by the condition given above. 4.[5] Show that n! = O(n n ) but n! O(2 n ). [2] Let c=1, n 0 =1. For all n 1, n! = n*(n-1)*(n-2) *1 n*n*n *n= n n. So, n! = O(n n ). [3] For all c 0, take n 0 = 4c. For all n 4c, n = n*(n-1) 3*2*1 4c*(n-1) 3*2*1 c*2*(n-1) *3*2*2 c*2*2 *2*2*2 = c*2 n hold So, n! O(2 n ). 5.[6] Solve the following recurrences where T(1)=1 and T(n) for n 2 satisfies: a. T(n)=4T(n/2)+n b. T(n)=4T(n/2)+n 2 c. T(n)=4T(n/2)+n 3 We will use Master Theorem. In all cases a=4, b=2. Let α=log 2 4 = 2. a.[2] Case 1 with ε = 1, as f(n)=n = n α-1. Hence T(n) = ϴ(n α ) = ϴ(n 2 ). b.[2] Case 2, as f(n)=n 2 = n α. Hence T(n) = ϴ(n α logn) = ϴ(n 2 logn). 2

3 c.[2] Case 3 with ε = 1, as f(n)=n 3 = n α+1, and af(n/b) = 4(n 3 /2 3 )= 0.5n 3 <cn 3 =cf(n) for any c>1. Hence T(n) = ϴ(f(n)) = ϴ(n 3 ). 6.[4] Solve the following recurrences where T(1)=1 and T(n) for n 2 satisfies: a. T(n)=5T(n/3)+log n b. T(n)=9T(n/3)+n 2 We will use Master Theorem. a[2] a=5, b=3. Let α=log 3 5 = Here f(n) = log n, so for ε = 0.4, we have f(n) = log n < n < n α-ε = n By Case 1, T(n) = ϴ(n α ) = ϴ(n ). b[2] a=9, b=3, α=log 3 9 = 2, f(n) = n 2, so Case 2, i.e. T(n) = ϴ(n α logn) = ϴ(n 2 logn). 7.[7] Solve the following recurrence where T(1)=1 and T(n) for n 2 satisfies T(n) = 2T(n/2)+nlogn Hint. Master Theorem does not work here, see Lecture Notes. We can use expansion. T(n) = 2T(n/2)+nlogn = 2(2T(n/4)+(n/2)log(n/2)) + nlog n = 4T(n/4) + 2n/2 log(n/2) + nlog n = 4T(n/4) + n(log(n/2)+log n)=. = 2 k T(n/(2 k )) +n (log (n/(2 k )) + log (n/(2 k-1 )) + + log (n/2)+log n) For k=log n we have T(n/(2 k )) = 1 and the expansion stops. Since 2 log k = k log 2 = k, we have 2 k T(n/(2 k )) + n (log (n/(2 k )) + log (n/(2 k-1 )) + + log (n/2)+log n) = k + n (log (n/(2 k )) + log (n/(2 k-1 )) + + log (n/2)+log n) < k + n k log n = log n + nlog 2 n < cnlog 2 n, for any c 1. Hence T(n) = O(n log 2 n). Bonus [4]. We can also show that T(n)=Ω(n log 2 n), T(n)=ϴ(n log 2 n). We have: k + n (log (n/(2 k )) + log (n/(2 k-1 )) + + log (n/2)+log n) > k + n k log(n/(2 k )) = {since k=log n and 2 log k = k log 2 = k} log n + n log n log (n/k) = log n + n log 2 n n log n log(log n). Since for example for n>36, log(log n) < 0.5 log n, we have: log n + n log 2 n n log n log(log n) > log n + n log 2 n 0.5 n log 2 n = log n n log 2 n > 0.5 n log 2 n, so T(n)=Ω(n log 2 n). 8.[8] Solve the following recurrences where T(1)=1 and T(n) for n 2 satisfies: a. T(n)=T(n-1)+ n 2 b. T(n)=2T(n-1)+1 We will use expansion. a.[3] T(n) = T(n-1) + n 2 = T(n-2) + 2 n 2 = T(n-3) + 3 n 2 =. = T(n-k) + k n 2 For k = n-1, T(n-k) = T(1) = 1 and the expansion stops. Hence: T(n-k) + k n 2 = T(1) + (n-1) n 2 = 1 + n 3 n 2 < 2n 3, so O(n 3 ). Bonus[2]. For n>2, 0.5n 3 > n 2, hence 1 + n 3 n 2 > n 3 > 0.5n 3, so Ω(n 3 ), i.e. ϴ(n 3 ). 3

4 b.[5] T(n)=2T(n-1)+1 = 2 (T(n)=2(2T(n-2)+1)+1 = 4 T(n-2) = 4(2T(n-3)+1) = 8 T(n-3) =...= 2 k T(n-k) + 2 k + 2 k Since 2 k + 2 k = 2 k+1-1, we have: 2 k T(n-k) + 2 k + 2 k = 2 k T(n-k) + 2 k+1-1 The expansion stops when k=n-1 as T(1)=1, and then we have: 2 k T(n-k) + 2 k+1-1 = 2 n-1 T(1) + 2 n = 2 n n -1 < 2 2 n, so O(2 n ) This is not so important in this case as the following: T(n)=2 n n -1>2 n, so Ω(2 n ), i.e. ϴ(2 n ). 9.[18] Give, using big O notation, the worst case running times of the following procedures as a function of n. Provide some calculation/justification. Just a formula only is not sufficient. a.[3] procedure P1(n:integer); var i,j,k : integer; for i:=1 to n do if ( n<>n/3 and n<>(n+1)/2) then for j:=1 to n do C[i,j]:=0; for k:=n/2+2 to n do C[i,j]:=C[i,j]*A[i,k]; for k:=1 to n do C[i,j]:=C[i,j] + A[i,k]*B[k,j]; for k:=1 to (n-1)/2 do C[i,j]:=C[i,j]*A[i,k]; else C[i,j]:=A[i,j]; for k:=n/3 to n/2 do C[i,j]:=C[i,j]*A[i,k]; The solutions do not need to be so precise s these below! T(n) = n i=1 max(t1,t2) = n i=1 max( n j=1t3, C1+T4) = n i=1 max( n j=1 (C2+( 2 k=n/2 C3) + ( n k=1 C4) +( n/2 k=1 C5)), C1+( n/2 k=n/3 C6)) = n i=1 max( n j=1 (C2+ O(n)+ O(n)+O(n)), C1+O(n)) = n i=1 max(o(n 2 ), O(n)) = n i=1o(n 2 ) = O(n 3 ) b.[3] procedure P2(n:integer); var i,j,k,l : integer; for i:=5 to 5*n do 4

5 for j:=i-1 to do for k:=j/2 to n*n do for l:=i to n*j {some statement requiring O(1) time} T(n) = 5n i=5t = 5n i=5( j=i-1t ) = 5n i=5( j=i-1( n*n k=j/2t )) = 5n i=5( j=i-1( n*n k=j/2( n*j l=io(1)))) = 5n i=5( j=i-1( n*n k=j/2o(n*j-i))) = 5n i=5( j=i-1o((n 2 -j/2)*(n*j-i))) = 5n i=5o(n 2 *(n-i)) = O(n 4 ) But, by a more careful analysis, for the out most loop, when i is from 1 to , T is O(n 3 ); but, when i is from to 10n, T should be O(1), which is for the evaluation of the predicate if i is greater than So, T(n) = 5n i=5t = (5n-5)(1) = O(n) c.[4] function F(n:integer):integer; if n<=1 then return(1) else return(f(n div 3)+2*F(n div 2)) T(n) = C + T(n div 3) +T(n div 2) T 1 (n) = C + 2*T 1 (n div 3) = (1+2)C +2 2 T 1 (n div 3 2 ) = ( )C +2 3 T 1 (n div 3 2 ). = ( m )C +2 m T 1 (1) where m ~ logn/log3 = (2 m -1)C + 2 m C = O(2 m ) = O(2 logn/log3 ) = O(n 1/log3 ) T 2 (n) = C + 2*T 2 (n div 2) = (1+2)C +2 2 T 2 (n div 2 2 ) = ( )C +2 3 T 2 (n div 2 2 ). = ( (m-1) )C +2 m T 1 (1) where m~logn = (2 m -1)C + 2 m C = O(2 m ) =O(n) So, T 1 (n) T(n) T 2 (n), and T(n)=O(T 2 (n))= O(n) d.[4] function G(n:integer):integer; if n<=1 then return(1) else return(g(n div 3)+G(n div 2)+G(n div 2)) T(n) = C + T(n div 3) +2*T(n div 2) T 1 (n) = C + 3*T 1 (n div 3) = (1+3)C +3 2 T 1 (n div 3 2 ) = ( )C +3 3 T 1 (n div 3 3 ). 5

6 = ( m-1 )C +3 m T 1 (1) where m ~ logn/log3 = (3 m -1)C + 3 m C = O(3 m ) = O(3 logn/log3 ) = O(n) T 2 (n) = C + 3*T 2 (n div 2) = (1+3)C T 2 (n div 2 2 ) = ( )C +3 3 T 3 (n div 2 2 ). = ( (m-1) )C +3 m T 1 (1) where m~logn = (3 m -1)C/2 + 3 m C = O(3 m ) =O(n log3 ) So, T 1 (n) T(n) T 2 (n), and T(n)=O(T 2 (n))= O(n log3 ) e.[4] Below the function F(n) is the function from (c) above and G(x) is the function from d above procedure P3(n:integer); var i,j,x,y : integer; for i:=1 to n do if i mod 3 = 1 then for j:=i to n do x:=x+1; for j:=20000 downto n do x:=x+y; for j:=1 to i do F(n)+G(n) T(n) = n i=1t1 = n i=1 1/3 *(T2+T3+T4) = n i=1 1/3 *( n j=io(1) j=no(1)+ i j=1(o(n) + O(n log3 ))) = n i=1 1/3 *(O(n-i) +O(1)+ O(n log3 * i)) = O(n 2+log3 ) 10.[25] Do Problem 4 on page 23 of Kleinberg and Tardos. It is a variation of the perfect stable matching problem. Solution: The basic strategy is to let every free student s apply for hospitals in order of his/her preference. If the hospital h he/she is applying for has positions available than h takes s. Or if all the positions are taken but h prefer s than at least one of its currently accepted students, then h will replace the least preferable student s with s, and s will be free. This process will continue until all free students have applied for all hospitals. Let S be a linked list of all free students and H an array of hospitals of length m. Each hospital h has a linked list employee[h] of students representing the current students it has accepted. Each student s has a linked list of hospitals employer[s] representing the hospitals that he/she has not applied for. Pseudo-code: Initialization: every student s is free and employer[s] is all the hospitals sorted in order of s s preference. For every hospital, employee[h] is empty. While there is any free student s such that employer[s] is not empty 6

7 for every such student s let h1 be the first element in employer[h] (highest rank hospital in s s list). if h1 still has positions available then add s into proper position of employee[h1], keep employee[h1] sorted in order of h1 s preference. else if Rank(s) > Rank(tail) add s into proper position of employee[h], delete tail (lowest rank student) from list. Delete h from employer[tail]. Tail becomes free student. else delete h1 from employer[s] The algorithm given above always terminates and produces a stable matching. Termination: Proof. In each loop, either an empty position is taken by a free student s, or a hospital is deleted from a student s (either s or tail) hospital list. There is a finite number of empty positions and there are finite number of hospitals in students lists. Note that neither empty positions nor students hospital lists increase. Therefore eventually all free students will have an empty hospital list. Then the program will terminate. Stability: The matching produced by this program is stable. Proof. Let s consider the first case of instability. Suppose when the program terminates, s in hospital h has lower rank than a free student s. Since s is free and applied for all hospitals, it is not assigned to h because of two possible reasons: either s was rejected when applying for h, or he/she was replaced by some other student s whose rank of preference is higher than s. In either of these two cases, all students assigned to h at the time have higher rank than s. And the rank is only going higher in the future. Therefore a student s with lower rank cannot stay in h when the program terminates, a contradiction! The second case of instability. Suppose when the program terminates, s in hospital h has lower rank of preference than a student s in hospital h, and s prefers h to h. Since s must have applied for h before applying to h, he/she was not assigned to h because of two possible reasons: either s was rejected when applying for h, or it was replaced by some other student s whose rank is higher than s. In either case all students assigned to h at that time have higher rank than s. And the rank is going to be higher in the future. Therefore a student s with lower rank cannot stay in h when the program terminates, a contradiction again! Hence the matching is stable. 11.[14] Do Problem 5 on page 24 of Kleinberg and Tardos. a.[8] Strong instability. The following algorithm guarantee a perfect matching with no strong instability. Let Pref 1 be a given set of both men and women preferences that involve ties. We replace all ties by arbitrary total order extensions, for example a preference with ties {3,4} {1,5,6} {2,7} could be replaced by , or by , etc. We do such changes 7

8 for all rankings with ties. Let Pref 2 be this new set of preferences. Since Pref 2 keeps all preferences of Pref 1, only indifferences are changed into arbitrary preferences, a strong instability of Pref 1 implies standard instability of Pref 2. We then apply a standard Gale- Shapley algorithm for the set of preferences Pref 2. The outcome is a perfect stable matching, it does not contain any standard instability, so it does not contain any strong instability with respect to Pref 1 either. Hence the strong instability can be avoided. b.[6] Weak instability. It may happen. Suppose that one ger is absolutely indifferent to the other. For example for all women all men are indifferent, no woman has any preference, all men all tied on all lists. Suppose we have two men m and m, and two women w and w, and both women have no preference, i.e. w {m,m }, w {m,m }. Men however have the following identical preferences: m w,w, m w,w. We have then two perfect matchings { m w, m w } and { m w, m w }. The former has a weak instability (w is indifferent to both m and m, while m prefers w), and the latter has also a weak instability (w is indifferent to both m and m, while m prefers w). 12.[15] Bonus question. Write the most efficient program (in pseudo code) to compute f(n) f(n), where f(n)=n n. Hint. Do you know that n n can be implemented with O(log n) complexity? The idea is based on the following scheme: n^n(n: :non-negative-integer) if n<0 then write(error) else if n=1 or n=0 then n^n 1 else if n is even and n>0 then n^n:=n^n(n/2) 2 else n^n n^n( n/2 ) 2 n where a is the biggest integer smaller or equal to a, for example 3.7 = 3. Here we have T n^n (n) = T n^n (n/2)+ c, T n^n (1)=1, so by Master Theorem T n^n (n) = ϴ(logn). We calculate n^n(n) first, and let a = n^n(n) = n n. Then we call n^n(a), and now the outcome is f(n) f(n). Formally: F(n: : non-negative-integer) a n^n(n); F n^n(a) The complexity is T n^n (n)+t n^n (n n ), and T n^n (n n ) is a dominating factor. But log n n = n log n, so T F (n) = ϴ(n log n). 8

Data structures Exercise 1 solution. Question 1. Let s start by writing all the functions in big O notation:

Data structures Exercise 1 solution. Question 1. Let s start by writing all the functions in big O notation: Data structures Exercise 1 solution Question 1 Let s start by writing all the functions in big O notation: f 1 (n) = 2017 = O(1), f 2 (n) = 2 log 2 n = O(n 2 ), f 3 (n) = 2 n = O(2 n ), f 4 (n) = 1 = O

More information

Omega notation. Transitivity etc.

Omega notation. Transitivity etc. Omega notation Big-Omega: Lecture 2, Sept. 25, 2014 f () n (()) g n const cn, s.t. n n : cg() n f () n Small-omega: 0 0 0 f () n (()) g n const c, n s.t. n n : cg() n f () n 0 0 0 Intuition (works most

More information

1 Substitution method

1 Substitution method Recurrence Relations we have discussed asymptotic analysis of algorithms and various properties associated with asymptotic notation. As many algorithms are recursive in nature, it is natural to analyze

More information

Divide and Conquer. Andreas Klappenecker

Divide and Conquer. Andreas Klappenecker Divide and Conquer Andreas Klappenecker The Divide and Conquer Paradigm The divide and conquer paradigm is important general technique for designing algorithms. In general, it follows the steps: - divide

More information

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2 1 Faculty of Mathematics Waterloo, Ontario Centre for Education in Mathematics and Computing Grade 11/12 Math Circles Fall 2014 - Nov. 5 Recurrences, Part 2 Running time of algorithms In computer science,

More information

Practical Session #3 - Recursions

Practical Session #3 - Recursions Practical Session #3 - Recursions Substitution method Guess the form of the solution and prove it by induction Iteration Method Convert the recurrence into a summation and solve it Tightly bound a recurrence

More information

Objective. - mathematical induction, recursive definitions - arithmetic manipulations, series, products

Objective. - mathematical induction, recursive definitions - arithmetic manipulations, series, products Recurrences Objective running time as recursive function solve recurrence for order of growth method: substitution method: iteration/recursion tree method: MASTER method prerequisite: - mathematical induction,

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 2.1 Notes Homework 1 will be released today, and is due a week from today by the beginning

More information

CIS 121. Analysis of Algorithms & Computational Complexity. Slides based on materials provided by Mary Wootters (Stanford University)

CIS 121. Analysis of Algorithms & Computational Complexity. Slides based on materials provided by Mary Wootters (Stanford University) CIS 121 Analysis of Algorithms & Computational Complexity Slides based on materials provided by Mary Wootters (Stanford University) Today Sorting: InsertionSort vs MergeSort Analyzing the correctness of

More information

i=1 i B[i] B[i] + A[i, j]; c n for j n downto i + 1 do c n i=1 (n i) C[i] C[i] + A[i, j]; c n

i=1 i B[i] B[i] + A[i, j]; c n for j n downto i + 1 do c n i=1 (n i) C[i] C[i] + A[i, j]; c n Fundamental Algorithms Homework #1 Set on June 25, 2009 Due on July 2, 2009 Problem 1. [15 pts] Analyze the worst-case time complexity of the following algorithms,and give tight bounds using the Theta

More information

Design and Analysis of Algorithms Recurrence. Prof. Chuhua Xian School of Computer Science and Engineering

Design and Analysis of Algorithms Recurrence. Prof. Chuhua Xian   School of Computer Science and Engineering Design and Analysis of Algorithms Recurrence Prof. Chuhua Xian Email: chhxian@scut.edu.cn School of Computer Science and Engineering Course Information Instructor: Chuhua Xian ( 冼楚华 ) Email: chhxian@scut.edu.cn

More information

Computational Complexity - Pseudocode and Recursions

Computational Complexity - Pseudocode and Recursions Computational Complexity - Pseudocode and Recursions Nicholas Mainardi 1 Dipartimento di Elettronica e Informazione Politecnico di Milano nicholas.mainardi@polimi.it June 6, 2018 1 Partly Based on Alessandro

More information

Review Asympto&c Bounds

Review Asympto&c Bounds Objec&ves Review: Asympto&c running &mes Classes of running &mes Implemen&ng Gale-Shapley algorithm Office hours: Today, 2:35-2:55, 5-5:50 p.m. Thursday: 1 5 p.m. Faculty Candidate Talk - Today at 4 p.m.

More information

Divide & Conquer. CS 320, Fall Dr. Geri Georg, Instructor CS320 Div&Conq 1

Divide & Conquer. CS 320, Fall Dr. Geri Georg, Instructor CS320 Div&Conq 1 Divide & Conquer CS 320, Fall 2017 Dr. Geri Georg, Instructor georg@colostate.edu CS320 Div&Conq 1 Strategy 1. Divide the problem up into equal sized sub problems 2. Solve the sub problems recursively

More information

Chapter 4 Divide-and-Conquer

Chapter 4 Divide-and-Conquer Chapter 4 Divide-and-Conquer 1 About this lecture (1) Recall the divide-and-conquer paradigm, which we used for merge sort: Divide the problem into a number of subproblems that are smaller instances of

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 2 Analysis of Algorithms Stable matching problem Asymptotic growth Adam Smith Stable Matching Problem Unstable pair: man m and woman w are unstable if m prefers w

More information

Analysis of Algorithms - Using Asymptotic Bounds -

Analysis of Algorithms - Using Asymptotic Bounds - Analysis of Algorithms - Using Asymptotic Bounds - Andreas Ermedahl MRTC (Mälardalens Real-Time Research Center) andreas.ermedahl@mdh.se Autumn 004 Rehersal: Asymptotic bounds Gives running time bounds

More information

Asymptotic Notation. such that t(n) cf(n) for all n n 0. for some positive real constant c and integer threshold n 0

Asymptotic Notation. such that t(n) cf(n) for all n n 0. for some positive real constant c and integer threshold n 0 Asymptotic Notation Asymptotic notation deals with the behaviour of a function in the limit, that is, for sufficiently large values of its parameter. Often, when analysing the run time of an algorithm,

More information

Lecture 3. Big-O notation, more recurrences!!

Lecture 3. Big-O notation, more recurrences!! Lecture 3 Big-O notation, more recurrences!! Announcements! HW1 is posted! (Due Friday) See Piazza for a list of HW clarifications First recitation section was this morning, there s another tomorrow (same

More information

Consider a complete bipartite graph with sets A and B, each with n vertices.

Consider a complete bipartite graph with sets A and B, each with n vertices. When DFS discovers a non-tree edge, check if its two vertices have the same color (red or black). If all non-tree edges join vertices of different color then the graph is bipartite. (Note that all tree

More information

CSCI 3110 Assignment 6 Solutions

CSCI 3110 Assignment 6 Solutions CSCI 3110 Assignment 6 Solutions December 5, 2012 2.4 (4 pts) Suppose you are choosing between the following three algorithms: 1. Algorithm A solves problems by dividing them into five subproblems of half

More information

Topic 17. Analysis of Algorithms

Topic 17. Analysis of Algorithms Topic 17 Analysis of Algorithms Analysis of Algorithms- Review Efficiency of an algorithm can be measured in terms of : Time complexity: a measure of the amount of time required to execute an algorithm

More information

Asymptotic Analysis and Recurrences

Asymptotic Analysis and Recurrences Appendix A Asymptotic Analysis and Recurrences A.1 Overview We discuss the notion of asymptotic analysis and introduce O, Ω, Θ, and o notation. We then turn to the topic of recurrences, discussing several

More information

Algorithms: COMP3121/3821/9101/9801

Algorithms: COMP3121/3821/9101/9801 Algorithms: COMP311/381/9101/9801 Aleks Ignjatović, ignjat@cse.unsw.edu.au office: 504 (CSE building); phone: 5-6659 Course Admin: Amin Malekpour, a.malekpour@unsw.edu.au School of Computer Science and

More information

Analysis of Algorithms Fall Some Representative Problems Stable Matching

Analysis of Algorithms Fall Some Representative Problems Stable Matching Analysis of Algorithms Fall 2017 Some Representative Problems Stable Matching Mohammad Ashiqur Rahman Department of Computer Science College of Engineering Tennessee Tech University Matching Med-school

More information

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation: CS 124 Section #1 Big-Oh, the Master Theorem, and MergeSort 1/29/2018 1 Big-Oh Notation 1.1 Definition Big-Oh notation is a way to describe the rate of growth of functions. In CS, we use it to describe

More information

Approximation and Randomized Algorithms (ARA) Lecture 1, September 3, 2012

Approximation and Randomized Algorithms (ARA) Lecture 1, September 3, 2012 Approximation and Randomized Algorithms (ARA) Lecture 1, September 3, 2012 Practicalities Code: 456314.0 intermediate and optional course Previous knowledge 456305.0 Datastrukturer II (Algoritmer) Period

More information

MIDTERM I CMPS Winter 2013 Warmuth

MIDTERM I CMPS Winter 2013 Warmuth test I 1 MIDTERM I CMPS 101 - Winter 2013 Warmuth With Solutions NAME: Student ID: This exam is closed book, notes, computer and cell phone. Show partial solutions to get partial credit. Make sure you

More information

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch] Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch] Divide and Conquer Paradigm An important general technique for designing algorithms: divide problem into subproblems recursively

More information

EECS 477: Introduction to algorithms. Lecture 5

EECS 477: Introduction to algorithms. Lecture 5 EECS 477: Introduction to algorithms. Lecture 5 Prof. Igor Guskov guskov@eecs.umich.edu September 19, 2002 1 Lecture outline Asymptotic notation: applies to worst, best, average case performance, amortized

More information

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2 In-Class Soln 1 Let f(n) be an always positive function and let g(n) = f(n) log n. Show that f(n) = o(g(n)) CS 361, Lecture 4 Jared Saia University of New Mexico For any positive constant c, we want to

More information

Analysis of Algorithms

Analysis of Algorithms September 29, 2017 Analysis of Algorithms CS 141, Fall 2017 1 Analysis of Algorithms: Issues Correctness/Optimality Running time ( time complexity ) Memory requirements ( space complexity ) Power I/O utilization

More information

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation: CS 124 Section #1 Big-Oh, the Master Theorem, and MergeSort 1/29/2018 1 Big-Oh Notation 1.1 Definition Big-Oh notation is a way to describe the rate of growth of functions. In CS, we use it to describe

More information

Asymptotic Algorithm Analysis & Sorting

Asymptotic Algorithm Analysis & Sorting Asymptotic Algorithm Analysis & Sorting (Version of 5th March 2010) (Based on original slides by John Hamer and Yves Deville) We can analyse an algorithm without needing to run it, and in so doing we can

More information

CS473 - Algorithms I

CS473 - Algorithms I CS473 - Algorithms I Lecture 2 Asymptotic Notation 1 O-notation: Asymptotic upper bound f(n) = O(g(n)) if positive constants c, n 0 such that 0 f(n) cg(n), n n 0 f(n) = O(g(n)) cg(n) f(n) Asymptotic running

More information

CS 161 Summer 2009 Homework #2 Sample Solutions

CS 161 Summer 2009 Homework #2 Sample Solutions CS 161 Summer 2009 Homework #2 Sample Solutions Regrade Policy: If you believe an error has been made in the grading of your homework, you may resubmit it for a regrade. If the error consists of more than

More information

Data Structures and Algorithms Chapter 3

Data Structures and Algorithms Chapter 3 Data Structures and Algorithms Chapter 3 1. Divide and conquer 2. Merge sort, repeated substitutions 3. Tiling 4. Recurrences Recurrences Running times of algorithms with recursive calls can be described

More information

More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018

More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018 CS 61B More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018 Here is a review of some formulas that you will find useful when doing asymptotic analysis. ˆ N i=1 i = 1 + 2 + 3 + 4 + + N = N(N+1)

More information

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013 /4/3 Administrative Big O David Kauchak cs3 Spring 3 l Assignment : how d it go? l Assignment : out soon l CLRS code? l Videos Insertion-sort Insertion-sort Does it terminate? /4/3 Insertion-sort Loop

More information

Algorithms Design & Analysis. Analysis of Algorithm

Algorithms Design & Analysis. Analysis of Algorithm Algorithms Design & Analysis Analysis of Algorithm Review Internship Stable Matching Algorithm 2 Outline Time complexity Computation model Asymptotic notions Recurrence Master theorem 3 The problem of

More information

Algorithm. Executing the Max algorithm. Algorithm and Growth of Functions Benchaporn Jantarakongkul. (algorithm) ก ก. : ก {a i }=a 1,,a n a i N,

Algorithm. Executing the Max algorithm. Algorithm and Growth of Functions Benchaporn Jantarakongkul. (algorithm) ก ก. : ก {a i }=a 1,,a n a i N, Algorithm and Growth of Functions Benchaporn Jantarakongkul 1 Algorithm (algorithm) ก ก ก ก ก : ก {a i }=a 1,,a n a i N, ก ก : 1. ก v ( v ก ก ก ก ) ก ก a 1 2. ก a i 3. a i >v, ก v ก a i 4. 2. 3. ก ก ก

More information

CSCI Honor seminar in algorithms Homework 2 Solution

CSCI Honor seminar in algorithms Homework 2 Solution CSCI 493.55 Honor seminar in algorithms Homework 2 Solution Saad Mneimneh Visiting Professor Hunter College of CUNY Problem 1: Rabin-Karp string matching Consider a binary string s of length n and another

More information

Computational Complexity

Computational Complexity Computational Complexity S. V. N. Vishwanathan, Pinar Yanardag January 8, 016 1 Computational Complexity: What, Why, and How? Intuitively an algorithm is a well defined computational procedure that takes

More information

data structures and algorithms lecture 2

data structures and algorithms lecture 2 data structures and algorithms 2018 09 06 lecture 2 recall: insertion sort Algorithm insertionsort(a, n): for j := 2 to n do key := A[j] i := j 1 while i 1 and A[i] > key do A[i + 1] := A[i] i := i 1 A[i

More information

Principles of Algorithm Analysis

Principles of Algorithm Analysis C H A P T E R 3 Principles of Algorithm Analysis 3.1 Computer Programs The design of computer programs requires:- 1. An algorithm that is easy to understand, code and debug. This is the concern of software

More information

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt Lecture 3 The Analysis of Recursive Algorithm Efficiency What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency

More information

An analogy from Calculus: limits

An analogy from Calculus: limits COMP 250 Fall 2018 35 - big O Nov. 30, 2018 We have seen several algorithms in the course, and we have loosely characterized their runtimes in terms of the size n of the input. We say that the algorithm

More information

Module 1: Analyzing the Efficiency of Algorithms

Module 1: Analyzing the Efficiency of Algorithms Module 1: Analyzing the Efficiency of Algorithms Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Based

More information

Asymptotic Analysis. Thomas A. Anastasio. January 7, 2004

Asymptotic Analysis. Thomas A. Anastasio. January 7, 2004 Asymptotic Analysis Thomas A. Anastasio January 7, 004 1 Introduction As a programmer, you often have a choice of data structures and algorithms. Choosing the best one for a particular job involves, among

More information

CPSC 320 Sample Final Examination December 2013

CPSC 320 Sample Final Examination December 2013 CPSC 320 Sample Final Examination December 2013 [10] 1. Answer each of the following questions with true or false. Give a short justification for each of your answers. [5] a. 6 n O(5 n ) lim n + This is

More information

Design Patterns for Data Structures. Chapter 3. Recursive Algorithms

Design Patterns for Data Structures. Chapter 3. Recursive Algorithms Chapter 3 Recursive Algorithms Writing recurrences + Writing recurrences To determine the statement execution count is a two-step problem. Write down the recurrence from the recursive code for the algorithm.

More information

Methods for solving recurrences

Methods for solving recurrences Methods for solving recurrences Analyzing the complexity of mergesort The merge function Consider the following implementation: 1 int merge ( int v1, int n1, int v, int n ) { 3 int r = malloc ( ( n1+n

More information

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2 MA008 p.1/36 MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2 Dr. Markus Hagenbuchner markus@uow.edu.au. MA008 p.2/36 Content of lecture 2 Examples Review data structures Data types vs. data

More information

Matching Residents to Hospitals

Matching Residents to Hospitals Midterm Review Matching Residents to Hospitals Goal. Given a set of preferences among hospitals and medical school students, design a self-reinforcing admissions process. Unstable pair: applicant x and

More information

Cpt S 223. School of EECS, WSU

Cpt S 223. School of EECS, WSU Algorithm Analysis 1 Purpose Why bother analyzing code; isn t getting it to work enough? Estimate time and memory in the average case and worst case Identify bottlenecks, i.e., where to reduce time Compare

More information

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

MIDTERM Fundamental Algorithms, Spring 2008, Professor Yap March 10, 2008 INSTRUCTIONS: MIDTERM Fundamental Algorithms, Spring 2008, Professor Yap March 10, 2008 0. This is a closed book exam, with one 8 x11 (2-sided) cheat sheet. 1. Please answer ALL questions (there is ONE

More information

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example Recurrence Relations Chapter 2 Divide and Conquer Equation or an inequality that describes a function by its values on smaller inputs. Recurrence relations arise when we analyze the running time of iterative

More information

Module 1: Analyzing the Efficiency of Algorithms

Module 1: Analyzing the Efficiency of Algorithms Module 1: Analyzing the Efficiency of Algorithms Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu What is an Algorithm?

More information

Problem Set 1. CSE 373 Spring Out: February 9, 2016

Problem Set 1. CSE 373 Spring Out: February 9, 2016 Problem Set 1 CSE 373 Spring 2016 Out: February 9, 2016 1 Big-O Notation Prove each of the following using the definition of big-o notation (find constants c and n 0 such that f(n) c g(n) for n > n o.

More information

CSE 421: Intro Algorithms. 2: Analysis. Winter 2012 Larry Ruzzo

CSE 421: Intro Algorithms. 2: Analysis. Winter 2012 Larry Ruzzo CSE 421: Intro Algorithms 2: Analysis Winter 2012 Larry Ruzzo 1 Efficiency Our correct TSP algorithm was incredibly slow Basically slow no matter what computer you have We want a general theory of efficiency

More information

Data Structures and Algorithms. Asymptotic notation

Data Structures and Algorithms. Asymptotic notation Data Structures and Algorithms Asymptotic notation Estimating Running Time Algorithm arraymax executes 7n 1 primitive operations in the worst case. Define: a = Time taken by the fastest primitive operation

More information

Analysis of Multithreaded Algorithms

Analysis of Multithreaded Algorithms Analysis of Multithreaded Algorithms Marc Moreno Maza University of Western Ontario, London, Ontario (Canada) CS 4435 - CS 9624 (Moreno Maza) Analysis of Multithreaded Algorithms CS 4435 - CS 9624 1 /

More information

3.1 Asymptotic notation

3.1 Asymptotic notation 3.1 Asymptotic notation The notations we use to describe the asymptotic running time of an algorithm are defined in terms of functions whose domains are the set of natural numbers N = {0, 1, 2,... Such

More information

Asymptotic Running Time of Algorithms

Asymptotic Running Time of Algorithms Asymptotic Complexity: leading term analysis Asymptotic Running Time of Algorithms Comparing searching and sorting algorithms so far: Count worst-case of comparisons as function of array size. Drop lower-order

More information

The Time Complexity of an Algorithm

The Time Complexity of an Algorithm CSE 3101Z Design and Analysis of Algorithms The Time Complexity of an Algorithm Specifies how the running time depends on the size of the input. Purpose To estimate how long a program will run. To estimate

More information

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 3. Θ Notation. Comparing Algorithms

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 3. Θ Notation. Comparing Algorithms Taking Stock IE170: Algorithms in Systems Engineering: Lecture 3 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University January 19, 2007 Last Time Lots of funky math Playing

More information

Please give details of your answer. A direct answer without explanation is not counted.

Please give details of your answer. A direct answer without explanation is not counted. Please give details of your answer. A direct answer without explanation is not counted. Your answers must be in English. Please carefully read problem statements. During the exam you are not allowed to

More information

Asymptotic Analysis 1

Asymptotic Analysis 1 Asymptotic Analysis 1 Last week, we discussed how to present algorithms using pseudocode. For example, we looked at an algorithm for singing the annoying song 99 Bottles of Beer on the Wall for arbitrary

More information

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: The maximum-subarray problem Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: Brute force algorithm: At best, θ(n 2 ) time complexity 129 Can we do divide

More information

CSE 531 Homework 1 Solution. Jiayi Xian

CSE 531 Homework 1 Solution. Jiayi Xian CSE 53 Homework Solution Jiayi Xian Fall 08 . (a) True. Since f(n) O(f(n)), clearly we have O(f(n)) O(O(f(n))). For the opposite, suppose g(n) O(O(f(n))), that is c > 0, h(n) O(f(n)), s.t g(n) c h(n) as

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2019 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

1 Definitions and Things You Know

1 Definitions and Things You Know We will discuss an algorithm for finding stable matchings (not the one you re probably familiar with). The Instability Chaining Algorithm is the most similar algorithm in the literature to the one actually

More information

CS Non-recursive and Recursive Algorithm Analysis

CS Non-recursive and Recursive Algorithm Analysis CS483-04 Non-recursive and Recursive Algorithm Analysis Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 4:30pm - 5:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/

More information

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Xi Chen Columbia University We continue with two more asymptotic notation: o( ) and ω( ). Let f (n) and g(n) are functions that map

More information

Lecture 3: Big-O and Big-Θ

Lecture 3: Big-O and Big-Θ Lecture 3: Big-O and Big-Θ COSC4: Algorithms and Data Structures Brendan McCane Department of Computer Science, University of Otago Landmark functions We saw that the amount of work done by Insertion Sort,

More information

Data Structures and Algorithms CMPSC 465

Data Structures and Algorithms CMPSC 465 Data Structures and Algorithms CMPSC 465 LECTURE 9 Solving recurrences Substitution method Adam Smith S. Raskhodnikova and A. Smith; based on slides by E. Demaine and C. Leiserson Review question Draw

More information

Game Theory: Lecture #5

Game Theory: Lecture #5 Game Theory: Lecture #5 Outline: Stable Matchings The Gale-Shapley Algorithm Optimality Uniqueness Stable Matchings Example: The Roommate Problem Potential Roommates: {A, B, C, D} Goal: Divide into two

More information

Defining Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 421: Intro Algorithms. Summer 2007 Larry Ruzzo

Defining Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 421: Intro Algorithms. Summer 2007 Larry Ruzzo CSE 421: Intro Algorithms 2: Analysis Summer 2007 Larry Ruzzo Defining Efficiency Runs fast on typical real problem instances Pro: sensible, bottom-line-oriented Con: moving target (diff computers, compilers,

More information

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency Lecture 2 Fundamentals of the Analysis of Algorithm Efficiency 1 Lecture Contents 1. Analysis Framework 2. Asymptotic Notations and Basic Efficiency Classes 3. Mathematical Analysis of Nonrecursive Algorithms

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 2 Analysis of Stable Matching Asymptotic Notation Adam Smith Stable Matching Problem Goal: Given n men and n women, find a "suitable" matching. Participants rate members

More information

Matching Theory and the Allocation of Kidney Transplantations

Matching Theory and the Allocation of Kidney Transplantations University of Utrecht Bachelor Thesis Matching Theory and the Allocation of Kidney Transplantations Kim de Bakker Supervised by Dr. M. Ruijgrok 14 June 2016 Introduction Matching Theory has been around

More information

Divide and Conquer. Recurrence Relations

Divide and Conquer. Recurrence Relations Divide and Conquer Recurrence Relations Divide-and-Conquer Strategy: Break up problem into parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. 2 MergeSort Mergesort.

More information

Computer Algorithms CISC4080 CIS, Fordham Univ. Outline. Last class. Instructor: X. Zhang Lecture 2

Computer Algorithms CISC4080 CIS, Fordham Univ. Outline. Last class. Instructor: X. Zhang Lecture 2 Computer Algorithms CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Lecture 2 Outline Introduction to algorithm analysis: fibonacci seq calculation counting number of computer steps recursive formula

More information

Computer Algorithms CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Lecture 2

Computer Algorithms CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Lecture 2 Computer Algorithms CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Lecture 2 Outline Introduction to algorithm analysis: fibonacci seq calculation counting number of computer steps recursive formula

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Algorithm runtime analysis and computational tractability Time Complexity of an Algorithm How do we measure the complexity (time, space requirements) of an algorithm. 1 microsecond? Units of time As soon

More information

Algorithms and Their Complexity

Algorithms and Their Complexity CSCE 222 Discrete Structures for Computing David Kebo Houngninou Algorithms and Their Complexity Chapter 3 Algorithm An algorithm is a finite sequence of steps that solves a problem. Computational complexity

More information

CS F-01 Algorithm Analysis 1

CS F-01 Algorithm Analysis 1 CS673-016F-01 Algorithm Analysis 1 01-0: Syllabus Office Hours Course Text Prerequisites Test Dates & Testing Policies Try to combine tests Grading Policies 01-1: How to Succeed Come to class. Pay attention.

More information

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d CS161, Lecture 4 Median, Selection, and the Substitution Method Scribe: Albert Chen and Juliana Cook (2015), Sam Kim (2016), Gregory Valiant (2017) Date: January 23, 2017 1 Introduction Last lecture, we

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2018 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

Growth of Functions (CLRS 2.3,3)

Growth of Functions (CLRS 2.3,3) Growth of Functions (CLRS 2.3,3) 1 Review Last time we discussed running time of algorithms and introduced the RAM model of computation. Best-case running time: the shortest running time for any input

More information

CIS 121 Data Structures and Algorithms with Java Spring Big-Oh Notation Monday, January 22/Tuesday, January 23

CIS 121 Data Structures and Algorithms with Java Spring Big-Oh Notation Monday, January 22/Tuesday, January 23 CIS 11 Data Structures and Algorithms with Java Spring 018 Big-Oh Notation Monday, January /Tuesday, January 3 Learning Goals Review Big-Oh and learn big/small omega/theta notations Discuss running time

More information

COMPUTER ALGORITHMS. Athasit Surarerks.

COMPUTER ALGORITHMS. Athasit Surarerks. COMPUTER ALGORITHMS Athasit Surarerks. Introduction EUCLID s GAME Two players move in turn. On each move, a player has to write on the board a positive integer equal to the different from two numbers already

More information

Solving Recurrences. 1. Express the running time (or use of some other resource) as a recurrence.

Solving Recurrences. 1. Express the running time (or use of some other resource) as a recurrence. 1 Recurrences and Recursive Code Solving Recurrences Many (perhaps most) recursive algorithms fall into one of two categories: tail recursion and divide-andconquer recursion. We would like to develop some

More information

The Time Complexity of an Algorithm

The Time Complexity of an Algorithm Analysis of Algorithms The Time Complexity of an Algorithm Specifies how the running time depends on the size of the input. Purpose To estimate how long a program will run. To estimate the largest input

More information

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms. Solving recurrences Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms Example: Merge-Sort(A, p, r) 1: if p < r then 2: q (p + r)/2 3: Merge-Sort(A,

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2018 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010 Announcements CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Dan Grossman Spring 2010 Project 1 posted Section materials on using Eclipse will be very useful if you have never used

More information

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc.

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc. Algorithms Analysis Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc. Algorithms analysis tends to focus on time: Techniques for measuring

More information

CS 5321: Advanced Algorithms - Recurrence. Acknowledgement. Outline. Ali Ebnenasir Department of Computer Science Michigan Technological University

CS 5321: Advanced Algorithms - Recurrence. Acknowledgement. Outline. Ali Ebnenasir Department of Computer Science Michigan Technological University CS 5321: Advanced Algorithms - Recurrence Ali Ebnenasir Department of Computer Science Michigan Technological University Acknowledgement Eric Torng Moon Jung Chung Charles Ofria Outline Motivating example:

More information