Data Structures and Algorithm. Xiaoqing Zheng
|
|
- Drusilla Hines
- 6 years ago
- Views:
Transcription
1 Data Structures ad Algorithm Xiaoqig Zheg
2 What are algorithms? A sequece of computatioal steps that trasform the iput ito the output Sortig problem: Iput: A sequece of umbers <a 1, a,, a > Output: A permutatio (reorderig) <a' 1, a',, a' > such that a' 1 a' a' Istace of sortig problem: Iput: <3, 45, 64, 8, 45, 58> Output: <8, 3, 45, 45, 58, 64>
3 Example of isert sort doe
4 Isertio sort INSERTION-SORT(A) 1 for j to legth[a] do key A[j] 3 // Isert A[j] ito the sorted sequece A[1 j 1] 4 i j 1 5 while i > 0 ad A[i] > key 6 do A[i + 1] A[i] 7 i i 1 8 A[i + 1] key A: 1 i j Sorted key
5 Ruig time The ruig time depeds o the iput: a already sorted sequece is easier to sort Parameterize the ruig time by the size of the iput, sice short sequeces are easier to sort tha log oes Geerally, we seek upper bouds o the ruig time, because everybody likes a guaratee
6 Kids of aalyses Worst-case: (usually) T() = maximum time of algorithm o ay iput of size Average-case: (sometimes) T() = expected time of algorithm over all iputs of size Need assumptio of statistical distributio of iputs Best-case: (bogus) Cheat with a slow algorithm that works fast o some iput
7 Aalysis of isertio sort INSERTION-SORT(A) 1 for j to legth[a] do key A[j] 3 // Isert A[j] ito the sorted sequece A[1 j 1] 4 i j 1 5 while i > 0 ad A[i] > key 6 do A[i + 1] A[i] 7 i i 1 8 A[i + 1] key cost c 1 c 0 c 4 c 5 c 6 c 7 c 8 times j = j= j= t 1 j ( t 1) j ( t 1) j T( ) = c+ c ( 1) + c ( 1) + c t + c ( t 1) + c ( t 1) + c ( 1) j= j 6 j= j 7 j= j 8
8 Aalysis of isertio sort: best ad worst T( ) = c+ c ( 1) + c ( 1) + c t + c ( t 1) + c ( t 1) + c ( 1) j= j 6 j= j 7 j= j 8 Best case: The best case occurs if the array is already sorted T( ) = c+ c ( 1) + c ( 1) + c ( 1) + c ( 1) = ( c + c + c + c + c ) ( c + c + c + c ) a + b (liear fuctio) Worst case: The worst case occurs if the array is i reverse sorted order ( + 1) ( 1) ( 1) T( ) = c 1 + c( 1) + c4( 1) + c5( 1) + c6( ) + c7( ) + c8( 1) c c c c c c = ( + + ) + ( c c + c4 + + c8) ( c + c4 + c5 + c8) a + b + c (quadratic fuctio)
9 Machie-idepedet time What is isertio sort's worst-case? It depeds o the speed of our computer: Relative speed (o the same machie), Absolute speed (o differet machies) BIG IDEA: Igore machie-depedet costats Look at growth of T() as "Asymptotic Aalysis"
10 Θ-otatio Math: Θ(g()) = { f() : there exist positive costats c 1, c, ad 0 such that 0 c 1 g() f() c g() for all 0 } Egieerig: Drop low-order terms; igore leadig costats Example: = Θ( 3 )
11 Asymptotic performace Whe gets large eough, a Θ( ) algorithm always beats a Θ( 3 ) algorithm T() 0
12 Merge sort MERGE-SORT A[1 ] 1 If = 1, doe Recursively sort A[1 / ] ad A[ / + 1 ] 3 "Merge" the sorted lists Key subroutie: MERGE
13 Mergig two sorted arrays ,, 7, 9, 11, 1, 13, 0 Time = Θ() to merge a total of elemets (liear time)
14 Operatio of merge sort sorted sequece merge merge merge merge merge merge merge iitial sequece
15 Aalyzig merge sort T() Θ(1) T(/) Θ() MERGE-SORT A[1 ] 1 If = 1, doe Recursively sort A[1 / ] ad A[ / + 1 ] 3 "Merge" the sorted lists Sloppiess: Should be T( / ) + T( / ), but it turs out ot to matter asymptotically
16 Recurrece for merge sort T ( ) Θ (1) if = 1, = T ( /) + Θ ( ) if > 1
17 Recurrece for merge sort Θ (1) if = 1, T ( ) = T ( /) + Θ ( ) if > 1 Solve T() = T(/) + c, where c > 0 is costat
18 Recurrece for merge sort Θ (1) if = 1, T ( ) = T ( /) + Θ ( ) if > 1 Solve T() = T(/) + c, where c > 0 is costat T()
19 Recurrece for merge sort Θ (1) if = 1, T ( ) = T ( /) + Θ ( ) if > 1 Solve T() = T(/) + c, where c > 0 is costat c T(c/) T(c/)
20 Recurrece for merge sort Θ (1) if = 1, T ( ) = T ( /) + Θ ( ) if > 1 Solve T() = T(/) + c, where c > 0 is costat c c/ c/ T(c/4) T(c/4) T(c/4) T(c/4)
21 Recurrece for merge sort Θ (1) if = 1, T ( ) = T ( /) + Θ ( ) if > 1 Solve T() = T(/) + c, where c > 0 is costat c c/ c/ c/4 c/4 c/4 c/4 c c c c c c c
22 Recurrece for merge sort Θ (1) if = 1, T ( ) = T ( /) + Θ ( ) if > 1 Solve T() = T(/) + c, where c > 0 is costat c c c/ c/ c h = lg c/4 c/4 c/4 c/4 c c c c c c c c c Total: c lg + c
23 Isertio sort ad merge sort Isertio sort: c 1 Computer A executes oe billio istructios per secod Merge sort: c lg Computer B executes te millio istructios per secod c 1 = c = 50 Isertio sort: Merge sort: 50lg To sort oe millio umbers: (10 6 ) istructios 10 9 istructios/secod = 000 secods (te millio, 3 day) To sort oe millio umbers: lg10 6 istructios 10 7 istructios/secod 100 secods (te millio, 0 miutes)
24 Aalysis of algorithms The theoretical study of computer-program performace ad resource usage What's more importat tha performace? Modularity Correctess Maitaiability Fuctioality Robustess User-friedliess Programmer time Simplicity Extesibility Reliability
25 Compariso of ruig times For each fuctio f() ad time t i the followig table, determie the largest size of a problem that ca be solved i time t, assumig that the algorithm to solve the problem takes f() microsecods 1 secod 1 miute 1 hour 1 day 1 moth 1 year 1 cetury lg 1/ lg 3!
26 Asymptotically tight boud Θ(g()) = { f() : there exist positive costats c 1, c, ad 0 such that 0 c 1 g() f() c g() for all 0 } c g() f() c 1 g() f() = Θ(g()) 0
27 Asymptotically upper boud O(g()) = { f() : there exist positive costats c ad 0 such that 0 f() cg() for all 0 } cg() f() f() = O(g()) 0
28 Asymptotically upper boud Ω(g()) = { f() : there exist positive costats c ad 0 such that 0 cg() f() for all 0 } f() cg() f() = Ω(g()) 0
29 Asymptotic otatios A aalogy betwee the asymptotic compariso of two fuctios f ad g the compariso of two real umbers a ad b: f() = O(g()) a b, f() = Ω(g()) a b, f() = Θ(g()) a = b Θ(g()) = O(g()) Ω(g())
30 Recurreces Substitutio method Recursio-tree method Master method
31 Substitutio method The most geeral method: 1 Guess the form of the solutio Verify by iductio 3 Solve for costats EXAMPLE: T() = 4T(/) + [Assume that T(1) = Θ(1)] Guess O( 3 ) Assume that T(k) ck 3 for k < Prove T() c 3 by iductio
32 Example of substitutio T() = 4T(/) + 4c(/) 3 + = (c/) 3 + = c 3 ((c/) 3 ) desired residual c 3 desired wheever (c/) 3 0, for example, if c ad 1 residual
33 Example of substitutio (cotiued) We must also hadle the iitial coditios, that is, groud the iductio with base cases Base: T() = Θ(1) for all < 0, where 0 is a suitable costat For 1 < 0, we have "Θ(1)" c 3, if we pick c big eough This boud is ot tight!
34 A tighter upper boud? We shall prove that T() = O( ) Assume that T(k) ck for k < : T() = 4T(/) + 4c(/) + = c + = O( ) Wrog! = c ( ) [desired residual] c for o choice of c > 0 Lose! We must prove the iductive hypothesis
35 A tighter upper boud! IDEA: Stregthe the iductive hypothesis Subtract a low-order term Iductive hypothesis: T(k) c 1 k c k for k < T() = 4T(/) + 4c 1 (/) 4c (/) + = c 1 c + = c 1 c (c ) c 1 c if c 1 Pick c 1 big eough to hadle the iitial coditios
36 Substitutio: chagig variables T() = T( ) + lg Reamig m = lg yields T( m ) = T( m/ ) + m Reame S(m) = T( m ) to produce the ew recurrece S(m) = S(m/) + m S(m) = O(mlgm) Chagig back from S(m) to T() T() = T( m ) = S(m) = O(mlgm) = O(lg lglg)
37 Recursio-tree method A recursio tree models the costs (time) of a recursive executio of a algorithm The recursio-tree method promotes ituitio The recursio tree method is good for geeratig guesses for the substitutio method
38 Example of recursio tree Solve T() = 3T( /4 ) + T() = 3T(/4) +
39 Example of recursio tree Solve T() = 3T( /4 ) + T() = 3T(/4) + T()
40 Example of recursio tree Solve T() = 3T( /4 ) + T() = 3T(/4) + c T ( ) T ( ) T ( ) 4 4 4
41 Example of recursio tree Solve T() = 3T( /4 ) + T() = 3T(/4) + c c( ) 4 c( ) 4 c( ) 4 T ( ) T ( ) T ( ) T ( ) T ( ) T ( ) T ( ) T ( ) T ( )
42 Example of recursio tree Solve T() = 3T( /4 ) + T() = 3T(/4) + c c c( ) 4 c( ) 4 c( ) c lg 4 c( ) 16 c( ) 16 c( ) 16 c( ) 16 c( ) 16 c( ) 16 c( ) 16 c( ) 16 c( ) 16 3 ( ) 16 c T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) Θ log4 3 ( ) log4 3 Total: O( )
43 Cost for the etire tree T = c + c + c + + c +Θ log4 1 3 i log4 3 = ( ) c +Θ( ) i= i log 4 < ( ) c +Θ( 3 ) i= log4 3 = c +Θ( ) 1 (3/16) 16 log4 3 = c +Θ( ) 13 log 4 1 log 4 ( ) ( ) ( ) ( 3 ) = O ( )
44 Substitutio method to verify T T 3 T( /4 ) + c ( ) = 3 ( /4 ) +Θ( ) 3 d /4 + c 3 d ( /4) + c 3 = d + c 16 d Where the last step holds as log as d (16 /13) c
45 The master method The master method applies to recurreces of the form T() = at(/b) + f (), where a 1, b > 1, ad f is asymptotically positive
46 Three commo cases Compare f() with log b a
47 Three commo cases Compare f() with log b a ε > 0 log 1 f() = O( b a ε ) for some costat f() grows polyomially slower tha log b a (by a factor) ε T logb ( ) =Θ( a ) Solutio: ε
48 Three commo cases Compare f() with log b a ε > 0 log 1 f() = O( b a ε ) for some costat f() grows polyomially slower tha log b a (by a factor) ε T logb ( ) =Θ( a ) Solutio: log lg f() = O( ) b a log f() ad b a grow at similar rates logb T ( ) =Θ( a lg ) Solutio: ε
49 Three commo cases (cotiued) Compare f() with log b a logb ( a +ε Ω ) ε > 0 3 f() = for some costat f() grows polyomially faster tha log b a +ε (by a factor) ε ad f() satisfies the regularity coditio that af(/b) cf() for some costat c < 1 T ( ) = Θ( f ( )) Solutio:
50 Idea of master theorem lg b f ( ) b f ( ) b f ( ) b f ( ) b f() a f ( ) b f ( ) b a a a f ( ) b f ( ) b f ( ) b f ( ) b f ( ) b a a a a a a a a a f ( ) b T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) f() af ( / b) a f( / b ) Θ logb ( a ) log b a Total: Θ logb 1 logb a j j ( ) a f( / b ) + j= 0
51 Examples EX T() = 4T(/) + a =4, b = log b a = ; f() =
52 Examples EX T() = 4T(/) + a =4, b = log b a = ; f() = CASE 1: f( ) = O( ε ) for ε = 1 T ( ) =Θ( )
53 Examples EX T() = 4T(/) + a =4, b = log b a = ; f() = CASE 1: f( ) = O( ε ) for ε = 1 T ( ) =Θ( ) EX T() = 4T(/) + a =4, b = log b a = ; f() =
54 Examples EX T() = 4T(/) + a =4, b = log b a = ; f() = CASE 1: f( ) = O( ε ) for ε = 1 T ( ) =Θ( ) EX T() = 4T(/) + a =4, b = log b a = ; f() = CASE : f ( ) =Θ( ) T ( ) =Θ( lg )
55 Examples EX T() = 4T(/) + 3 a =4, b = log b a = ; f() = 3
56 Examples EX T() = 4T(/) + 3 a =4, b = log b a = ; f() = 3 CASE 3: f( ) =Ω( + ε ) for ε = 1 ad 4(/) 3 c 3 (reg cod) for c = 1/ 3 T ( ) =Θ( )
57 Examples EX T() = 4T(/) + 3 a =4, b = log b a = ; f() = 3 CASE 3: f( ) =Ω( + ε ) for ε = 1 ad 4(/) 3 c 3 (reg cod) for c = 1/ 3 T ( ) =Θ( ) EX T() = 4T(/) + /lg a =4, b = log b a = ; f() = /lg
58 Examples EX T() = 4T(/) + 3 a =4, b = log b a = ; f() = 3 CASE 3: f( ) =Ω( + ε ) for ε = 1 ad 4(/) 3 c 3 (reg cod) for c = 1/ 3 T ( ) =Θ( ) EX T() = 4T(/) + /lg a =4, b = log b a = ; f() = /lg Master method does ot apply
59 Ay questio? Xiaoqig Zheg Fuda Uiversity
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 informationThis 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 informationDesign 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 informationAlgorithms and Data Structures Lecture IV
Algorithms ad Data Structures Lecture IV Simoas Šalteis Aalborg Uiversity simas@cs.auc.dk September 5, 00 1 This Lecture Aalyzig the ruig time of recursive algorithms (such as divide-ad-coquer) Writig
More informationModel 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 informationCS 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 informationModel 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 informationAnalysis 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 informationA 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 informationAlgorithm 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 informationCS 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 informationCSI 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 informationAnalysis of Algorithms. Introduction. Contents
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
More informationTest 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 informationChapter 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 informationAdvanced 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 informationOPTIMAL 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 informationFundamental Algorithms
Fudametal Algorithms Chapter 2b: Recurreces Michael Bader Witer 2014/15 Chapter 2b: Recurreces, Witer 2014/15 1 Recurreces Defiitio A recurrece is a (i-equality that defies (or characterizes a fuctio i
More informationClassification 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 informationCSE 5311 Notes 1: Mathematical Preliminaries
Chapter 1 - Algorithms Computig CSE 5311 Notes 1: Mathematical Prelimiaries Last updated 1/20/18 12:56 PM) Relatioship betwee complexity classes, eg log,, log, 2, 2, etc Chapter 2 - Gettig Started Loop
More informationSorting 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 informationCS / 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 informationRecursive 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 informationCS161 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 informationAlgorithms. Elementary Sorting. Dong Kyue Kim Hanyang University
Algorithms Elemetary Sortig Dog Kyue Kim Hayag Uiversity dqkim@hayag.a.kr Cotets Sortig problem Elemetary sortig algorithms Isertio sort Merge sort Seletio sort Bubble sort Sortig problem Iput A sequee
More informationSums, 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 informationIntroduction to Algorithms
Itroductio to Algorithms 6.046J/8.40J/SMA5503 Lecture 9 Pro. Charles E. Leiserso Biary-search-tree sort T Create a empty BST or i to do TREE-INSERT(T, A[i]) Perorm a iorder tree wal o T. Eample: A [3 8
More informationExamples: 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 informationSimilar idea to multiplication in N, C. Divide and conquer approach provides unexpected improvements. Naïve matrix multiplication
Next. Covered bsics of simple desig techique (Divided-coquer) Ch. of the text.. Next, Strsse s lgorithm. Lter: more desig d coquer lgorithms: MergeSort. Solvig recurreces d the Mster Theorem. Similr ide
More informationData 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 informationDesign 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 informationRecurrence 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 information4.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 informationCS 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 informationAlgorithm 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 informationDepartment of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse Zurich Phone:
Departmet of Iformatics Prof. Dr. Michael Böhle Bizmühlestrasse 14 8050 Zurich Phoe: +41 44 635 4333 Email: boehle@ifi.uzh.ch Iformatik II Midterm1 Sprig 018 3.03.018 Advice You have 90 miutes to complete
More informationIntroduction to Algorithms
Itroductio to Algorithms 6.046J/8.40J LECTURE 9 Radomly built biary search trees Epected ode depth Aalyzig height Coveity lemma Jese s iequality Epoetial height Post mortem Pro. Eri Demaie October 7, 2005
More information2. ALGORITHM ANALYSIS
2. ALGORITHM ANALYSIS computatioal tractability survey of commo ruig times 2. ALGORITHM ANALYSIS computatioal tractability survey of commo ruig times Lecture slides by Kevi Waye Copyright 2005 Pearso-Addiso
More informationMatriculation 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 informationCIS 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 informationCOMP285 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 informationITEC 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 informationCS161: 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 informationChapter 2. Asymptotic Notation
Asyptotic Notatio 3 Chapter Asyptotic Notatio Goal : To siplify the aalysis of ruig tie by gettig rid of details which ay be affected by specific ipleetatio ad hardware. [1] The Big Oh (O-Notatio) : It
More informationCOMP26120: 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 informationHand Out: Analysis of Algorithms. September 8, Bud Mishra. In general, there can be several algorithms to solve a problem; and one is faced
Had Out Aalysis of Algorithms September 8, 998 Bud Mishra c Mishra, February 9, 986 Itroductio I geeral, there ca be several algorithms to solve a problem; ad oe is faced with the problem of choosig a
More informationWhat 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 informationAlgorithms Design & Analysis. Divide & Conquer
Algorithms Desig & Aalysis Divide & Coquer Recap Direct-accessible table Hash tables Hash fuctios Uiversal hashig Perfect Hashig Ope addressig 2 Today s topics The divide-ad-coquer desig paradigm Revised
More informationCSI 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 informationSequences, 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 informationCOMP26120: More on the Complexity of Recursive Programs (2018/19) Lucas Cordeiro
COMP26120: More o the Complexity of Recursive Programs (2018/19) Lucas Cordeiro lucas.cordeiro@machester.ac.uk Divide-ad-Coquer (Recurrece) Textbook: Algorithm Desig ad Applicatios, Goodrich, Michael T.
More informationAlgorithms 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 informationData Structures and Algorithms
Data Structures ad Algorithms Autum 2017-2018 Outlie 1 Sortig Algorithms (cotd) Outlie Sortig Algorithms (cotd) 1 Sortig Algorithms (cotd) Heapsort Sortig Algorithms (cotd) Have see that we ca build a
More informationData 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 informationIntroduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and conquer Binary search Powering a number Fibonacci numbers Matrix multiplication
Itroductio to Algorithms 6.046J/8.40J LECTURE 3 Divide ad coquer Biary search Powerig a umber Fiboacci umbers Matrix multiplicatio Strasse s algorithm VLSI tree layout Prof. Charles E. Leiserso The divide-ad-coquer
More informationMerge and Quick Sort
Merge ad Quick Sort Merge Sort Merge Sort Tree Implemetatio Quick Sort Pivot Item Radomized Quick Sort Adapted from: Goodrich ad Tamassia, Data Structures ad Algorithms i Java, Joh Wiley & So (1998). Ruig
More informationCh3. 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 informationMathematics review for CSCI 303 Spring Department of Computer Science College of William & Mary Robert Michael Lewis
Mathematics review for CSCI 303 Sprig 019 Departmet of Computer Sciece College of William & Mary Robert Michael Lewis Copyright 018 019 Robert Michael Lewis Versio geerated: 13 : 00 Jauary 17, 019 Cotets
More informationCS 253: Algorithms. Syllabus. Chapter 1. Appendix A
CS 5: Algorithms Syllabus Chapter Appedi A Syllabus Istructor : Firet Ercal - Office: CS 4 Phoe: 4-4857 E-mail & URL : ercal@mst.edu http://web.mst.edu/~ercal/ide.html Meetig Times : :50 pm. M W F Office
More informationMathematical 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 informationCSE Introduction to Parallel Processing. Chapter 3. Parallel Algorithm Complexity
Dr. Izadi CSE-40533 Itroductio to Parallel Processig Chapter 3 Parallel Algorithm Complexity Review algorithm complexity ad various complexity classes Itroduce the otios of time ad time-cost optimality
More informationProblems with Solutions in the Analysis of Algorithms. Minko Markov
Problems with Solutios i the Aalysis of Algorithms Miko Markov Draft date November 13, 014 Copyright c 010 014 Miko Markov All rights reserved. Maple is a trademark of Waterloo Maple Ic. Cotets I Backgroud
More informationLecture 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 informationDivide & 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 informationMath 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 informationRead carefully the instructions on the answer book and make sure that the particulars required are entered on each answer book.
THE UNIVERSITY OF WARWICK FIRST YEAR EXAMINATION: Jauary 2009 Aalysis I Time Allowed:.5 hours Read carefully the istructios o the aswer book ad make sure that the particulars required are etered o each
More informationw (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 informationCSE 1400 Applied Discrete Mathematics Number Theory and Proofs
CSE 1400 Applied Discrete Mathematics Number Theory ad Proofs Departmet of Computer Scieces College of Egieerig Florida Tech Sprig 01 Problems for Number Theory Backgroud Number theory is the brach of
More informationProblem Set 1 Solutions
V R N N N R f ] R S Itroductio to Algorithms September 12, 2003 Massachusetts Istitute of echology 6046J/18410J rofessors Shafi Goldwasser ad Silvio Micali Hadout 7 roblem Set 1 Solutios roblem 1-1 Recurrece
More informationAnalysis of Algorithms. Growth of Functions
Aalysis of Algorithms Growth of Fuctios Growth of Fuctios Asymptotic Notatio : Ο, Ω, Θ, ο, ω Asymptotic Notatio Properties Growth of Fuctios Growth Rates 2-7 2 2 0.5 + 3 log Liear lim f () / g() = Growth
More informationMath 25 Solutions to practice problems
Math 5: Advaced Calculus UC Davis, Sprig 0 Math 5 Solutios to practice problems Questio For = 0,,, 3,... ad 0 k defie umbers C k C k =! k!( k)! (for k = 0 ad k = we defie C 0 = C = ). by = ( )... ( k +
More information62. Power series Definition 16. (Power series) Given a sequence {c n }, the series. c n x n = c 0 + c 1 x + c 2 x 2 + c 3 x 3 +
62. Power series Defiitio 16. (Power series) Give a sequece {c }, the series c x = c 0 + c 1 x + c 2 x 2 + c 3 x 3 + is called a power series i the variable x. The umbers c are called the coefficiets of
More informationChapter 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+ au n+1 + bu n = 0.)
Lecture 6 Recurreces - kth order: u +k + a u +k +... a k u k 0 where a... a k are give costats, u 0... u k are startig coditios. (Simple case: u + au + + bu 0.) How to solve explicitly - first, write characteristic
More informationCS: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 informationThe 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 informationCSE 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 informationSequences 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) n. ALG 1.3 Deterministic Selection and Sorting: Problem P size n. Examples: 1st lecture's mult M(n) = 3 M ( È
Algorithms Professor Joh Reif ALG 1.3 Determiistic Selectio ad Sortig: (a) Selectio Algorithms ad Lower Bouds (b) Sortig Algorithms ad Lower Bouds Problem P size fi divide ito subproblems size 1,..., k
More informationAppendix: The Laplace Transform
Appedix: The Laplace Trasform The Laplace trasform is a powerful method that ca be used to solve differetial equatio, ad other mathematical problems. Its stregth lies i the fact that it allows the trasformatio
More informationMath 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 information5. Solving recurrences
5. Solvig recurreces Time Complexity Alysis of Merge Sort T( ) 0 if 1 2T ( / 2) otherwise sortig oth hlves mergig Q. How to prove tht the ru-time of merge sort is O( )? A. 2 Time Complexity Alysis of Merge
More informationFLOOR AND ROOF FUNCTION ANALOGS OF THE BELL NUMBERS. H. W. Gould Department of Mathematics, West Virginia University, Morgantown, WV 26506, USA
INTEGERS: ELECTRONIC JOURNAL OF COMBINATORIAL NUMBER THEORY 7 (2007), #A58 FLOOR AND ROOF FUNCTION ANALOGS OF THE BELL NUMBERS H. W. Gould Departmet of Mathematics, West Virgiia Uiversity, Morgatow, WV
More information1 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 informationAn 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 informationMath 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 informationAlgorithms 演算法. Multi-threaded Algorithms
演算法 Multi-threaded Professor Chie-Mo James Li 李建模 Graduate Istitute of Electroics Egieerig Natioal aiwa Uiversity Outlie Multithreaded, CH7 7. Basics 7. Matrix Multiplicatio 7.3 Merge sort Leoardo Fiboacci
More informationApply change-of-basis formula to rewrite x as a linear combination of eigenvectors v j.
Eigevalue-Eigevector Istructor: Nam Su Wag eigemcd Ay vector i real Euclidea space of dimesio ca be uiquely epressed as a liear combiatio of liearly idepedet vectors (ie, basis) g j, j,,, α g α g α g α
More informationMathematical Induction
Mathematical Iductio Itroductio Mathematical iductio, or just iductio, is a proof techique. Suppose that for every atural umber, P() is a statemet. We wish to show that all statemets P() are true. I a
More informationA 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 informationCSE 332. Data Structures and Parallelism
Aam Blak Lecture 6a Witer 2017 CSE 332 Data Structures a Parallelism CSE 332: Data Structures a Parallelism More Recurreces T () T (/2) T (/2) T (/4) T (/4) T (/4) T (/4) P1 De-Brief 1 You i somethig substatial!
More informationMAT1026 Calculus II Basic Convergence Tests for Series
MAT026 Calculus II Basic Covergece Tests for Series Egi MERMUT 202.03.08 Dokuz Eylül Uiversity Faculty of Sciece Departmet of Mathematics İzmir/TURKEY Cotets Mootoe Covergece Theorem 2 2 Series of Real
More informationECE250: Algorithms and Data Structures Analyzing and Designing Algorithms
ECE50: Algorithms and Data Structures Analyzing and Designing Algorithms Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng.
More informationA New Method to Order Functions by Asymptotic Growth Rates Charlie Obimbo Dept. of Computing and Information Science University of Guelph
A New Method to Order Fuctios by Asymptotic Growth Rates Charlie Obimbo Dept. of Computig ad Iformatio Sciece Uiversity of Guelph ABSTRACT A ew method is described to determie the complexity classes of
More informationRecurrences: Methods and Examples
Reurrees: Methods ad Examples CSE 30 Algorithms ad Data Strutures Alexadra Stefa Uiversity of exas at Arligto Updated: 308 Summatios Review Review slides o Summatios Reurrees Reursive algorithms It may
More informationIn general, we need to describe how much time or memory will be required with respect to one or more variables. The most common variables include:
2.3 Asymptotic Aalysis It has already bee described qualitatively that if we ited to store othig but objects, that this ca be doe quickly usig a hash table; however, if we wish to store relatioships ad
More information2.4 - Sequences and Series
2.4 - Sequeces ad Series Sequeces A sequece is a ordered list of elemets. Defiitio 1 A sequece is a fuctio from a subset of the set of itegers (usually either the set 80, 1, 2, 3,... < or the set 81, 2,
More informationHashing. Algorithm : Design & Analysis [09]
Hashig Algorithm : Desig & Aalysis [09] I the last class Implemetig Dictioary ADT Defiitio of red-black tree Black height Isertio ito a red-black tree Deletio from a red-black tree Hashig Hashig Collisio
More informationInfinite 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 informationPell and Lucas primes
Notes o Number Theory ad Discrete Mathematics ISSN 30 532 Vol. 2, 205, No. 3, 64 69 Pell ad Lucas primes J. V. Leyedekkers ad A. G. Shao 2 Faculty of Sciece, The Uiversity of Sydey NSW 2006, Australia
More information