Performance Analysis. Space Complexity. Instruction Space. Data Structures and Programming 資料結構與程式設計. Topic 2 Complexity Analysis.

Size: px
Start display at page:

Download "Performance Analysis. Space Complexity. Instruction Space. Data Structures and Programming 資料結構與程式設計. Topic 2 Complexity Analysis."

Transcription

1 Performace Aalysis Data Structures ad Programmig 資料結構與程式設計 Topic 2 Complexity Aalysis 課程編號 : EE 3011 科目名稱 : 資料結構與程式設計授課教師 : 黃鼎偉時間地點 : 一 678 電機二館 229 Performace of a Program Performace aalysis by aalytical methods Performace measuremet by experimet Complexity of a Program Space (Memory) complexity Importat for multiuser system, memory allocatio, selectig suitable compiler, ad estimatio of the largest problem that the program ca solve Time complexity Importat for systems with time limit, programs which require real-time respose, ad selectig amog differet programs that ca solve the same problem. 2 Space Complexity Istructio Space Space Complexity Istructio space Deped o the compiler, compiler optios, ad target computer Data space Number of bytes of differet data types Eviromet stack space Retur address Values of local variables ad formal parameters for recursive fuctios. 01 LOAD a 02 ADD b 03 STORE t1 04 LOAD b 05 MUL c 06 STORE t2 07 LOAD t1 08 ADD t2 09 STORE t3 10 LOAD a 11 ADD b 12 SUB c 13 STORE t4 14 LOAD a 15 ADD b 16 STORE t5 17 LOAD t4 18 DIV t5 19 STORE t6 20 LOAD t3 21 ADD t6 22 ADD 4 01 LOAD a 02 ADD b 03 STORE t1 04 SUB c 05 DIV t1 06 STORE t2 07 LOAD b 08 MUL c 09 STORE t3 10 LOAD t1 11 ADD t3 12 ADD t2 13 ADD 4 01 LOAD a 02 ADD b 03 STORE t1 04 SUB c 05 DIV t1 06 STORE t2 07 LOAD b 08 MUL c 09 ADD t2 10 ADD t1 11 ADD 4 (a+b)+(b*c)+(a+b c)/(a+b)+4 3 4

2 Data Space Space Allocated to C++ Data Types o a 32-bit/word Computer Type bool char usiged char short usiged short log usiged log it usiged it float double log double poiter poiter Space (bytes) double a[100]; it maze[rows][cols]; Rage {true, false} [ 127, 128] [0, 255] [ 32767, 32768] [0, 65535] [ 2 31, ] [0, ] [ 2 31, ] [0, ] ±3.4E±38 (7 digits) ±1.7E±308 (15 digits) ±1.2E±4932 (19 digits) (ear, _cs, _ds, _es, _ss poiters) (far, huge poiters) 800 bytes 4*rows*cols bytes 5 Eviromet Stack Space Eviromet stack space is geerally idepedet of the istace characteristics uless recursive fuctios are i use. 08 template<class T> 09 T rsum(t a[], it ) 10 {// Retur sum of umbers a[0: 1]. 11 if ( > 0) 12 retur rsum(a, 1) + a[ 1]; 13 retur 0; 14 } rsum(a,) rsum(a, 1) rsum(a, 2)... rsum(a,1) rsum(a,0) Note: The istace characteristics is usually defied as the size of the data ivolved i the program. rsum.cpp 6 Eviromet Stack Space The amout of stack space eeded by recursive fuctios is called the Recursive Stack Space: A fixed part that is idepedet of the istace characteristics. A variable part that cosists of dyamically allocated space. c + S P (istace characteristics) Example 2.1 abcit 03 #iclude<iostream> usig amespace std; it abc(it a, it b, it c) 08 { 09 retur a + b * c; 10 } it mai() 13 { 14 cout << abc(2,3,4) << edl; 15 retur 0; 16 } S abc (istace characteristics) = 0. c = 4 (a, b, c, &abc) 7 abcit.cpp 8

3 Example 2.2 sequetialsearch Example 2.3 sum 08 template<class T> 09 it sequetialsearch(t a[], it, cost T& x) 10 {// Search the uordered list a[0: 1] for x. 11 // Retur positio if foud; retur 1 otherwise. 12 it i; 13 for (i = 0; i < && a[i]!= x; i++); 14 if (i == ) retur 1; 15 else retur i; 16 } S sequetialsearch () = 0. c = 4 (a,, &x, &sequetialsearch) 07 template<class T> 08 T sum(t a[], it ) 09 {// Retur sum of the umbers a[0: 1]. 10 T thesum = 0; 11 for (it i = 0; i < ; i++) 12 thesum += a[i]; 13 retur thesum; 14 } S sum () = 0. c = 5 (a,, thesum, i, &sum) sequetialsearch1.cpp 9 sum.cpp 10 Example 2.4 rsum Example 2.5 factorial 08 template<class T> 09 T rsum(t a[], it ) 10 {// Retur sum of umbers a[0: 1]. 11 if ( > 0) 12 retur rsum(a, 1) + a[ 1]; 13 retur 0; 14 } a, : it (4 bytes) Retur address: far poiter (4 bytes) S rsum () = 12(+1). rsum(a,) rsum(a, 1) rsum(a, 2)... rsum(a,1) rsum(a,0) 07 it factorial(it ) 08 {// Compute! 09 if ( <= 1) retur 1; 10 else retur * factorial( 1); 11 } : it (4 bytes) Retur address: far poiter (4 bytes) S factorial () = 8*max(,1). factorial() factorial( 1) factorial( 1)... factorial(1) rsum.cpp 11 factorial.cpp 12

4 Exercise: rsequectialserach 10 it rsequetialsearch(t a[], it, cost T& x) 11 {// Search the uordered list a[0: 1] for x. 12 // Retur positio if foud; retur 1 otherwise. 13 if ( < 1) retur 1; 14 if (a[ 1] == x) retur 1; 15 retur rsequetialsearch(a, 1, x); 16 } S rsequetialsearch () =? Time Complexity Operatio Couts Step Couts Asymptotic complexity Compoets of Time Complexity tp caadd( ) cssub( ) c ` mmul( ) cddiv ( ) (2.1) where ca, cs, cm, cd ADD( ), SUB( ), MUL( ), DIV( ) : (type-depedet) time required for sigle +, -, *, / operatio : istace characteristics : umber of +, -, *, / operatios (Operatio Couts) Note: the time used for comparisos ad elemet moves may also be cosidered. rsequetialsearch.cpp Example 2.7 idexofmax 07 template<class T> 08 it idexofmax(t a[], it ) 09 {// Locate the largest elemet i a[0: 1]. 10 if ( <= 0) 11 throw illegalparametervalue(" must be > 0"); it idexofmax = 0; 14 for (it i = 1; i < ; i++) 15 if (a[idexofmax] < a[i]) 16 idexofmax = i; 17 retur idexofmax; 18 } Number of comparisos = max{ 1,0} Example 2.8a polyeval (Polyomial Eval.) 10 T polyeval(t coeff[], it, cost T& x) 11 {// Evaluate the degree polyomial with 12 // coefficiets coeff[0:] at the poit x. 13 T y = 1, value = coeff[0]; 14 for (it i = 1; i <= ; i++) 15 {// add i ext term 16 y *= x; 17 value += y * coeff[i]; 18 } 19 retur value; 20 } P( x) ci x i0 i Number of additios = Number of multiplicatios = 2 idexofmax.h 15 polyeval.cpp 16

5 Example 2.8b horer (Polyomial Eval.) 10 T horer(t coeff[], it, cost T& x) 11 {// Evaluate the degree polyomial with 12 // coefficiets coeff[0:] at the poit x. 13 T value = coeff[]; 14 for (it i = 1; i <= ; i++) 15 value = value * x + coeff[ i]; 16 retur value; 17 } i P( x) cix ( ( cxc 1) xc2) xc3) x) xc0 i0.., ( ) ((5 4) 1) 7 eg P x x x x x x x Number of additios = Number of multiplicatios = Example 2.9 rak (Rakig) 10 void rak(t a[], it, it r[]) 11 {// Rak the elemets a[0: 1]. 12 // Elemet raks retured i r[0: 1] 13 for (it i = 0; i < ; i++) 14 r[i] = 0; // iitialize // compare all elemet pairs 17 for (it i = 1; i < ; i++) 18 for (it j = 0; j < i; j++) 19 if (a[j] <= a[i]) r[i]++; 20 else r[j]++; 21 } Number of comparisos = ( 1)/2 horer.cpp 17 rak.cpp 18 Example: Sortig Rearrage a[0], a[1],, a[ 1] ito ascedig order. Whe doe, a[0] <= a[1] <= <= a[ 1] 8, 6, 9, 4, 3 3, 4, 6, 8, 9 Isertio Sort Bubble Sort Selectio Sort Cout Sort (Rak Sort) Shaker Sort Shell Sort Heap Sort Merge Sort Quick Sort Example 2.10 rearrage (Rak Sort) 10 template<class T> 11 void rearrage(t a[], it, it r[]) 12 {// Rearrage the elemets of a ito sorted order 13 // usig a additioal array u. 14 T *u = ew T []; // create additioal array // move to correct place i u 17 for (it i = 0; i < ; i++) 18 u[r[i]] = a[i]; // move back to a 21 for (it i = 0; i < ; i++) 22 a[i] = u[i]; delete [] u; 25 } Number of elemet moves = 2 19 raksort1.cpp 20

6 Example 2.11 selectiosort (Selectio Sort) 10 void selectiosort(t a[], it ) 11 {// Sort the elemets a[0: 1]. 12 for (it size = ; size > 1; size ) 13 { 14 it j = idexofmax(a, size); 15 swap(a[j], a[size 1]); 16 } 17 } Number of comparisos = ( 1)/2 Number of elemet moves = 3( 1) Example 2.12 bubble (Bubble Sort) 10 void bubble(t a[], it ) 11 {// Bubble largest elemet i a[0: 1] to right. 12 for (it i = 0; i < 1; i++) 13 if (a[i] > a[i+1]) swap(a[i], a[i + 1]); 14 } Number of comparisos = 1 16 template<class T> 17 void bubblesort(t a[], it ) 18 {// Sort a[0: 1] usig bubble sort. 19 for (it i = ; i > 1; i ) 20 bubble(a, i); 21 } Total umber of comparisos = ( 1)/2 raksort1.cpp 21 bubblesort.cpp 22 Best, Worst ad Average Operatio Couts Worst-case cout = maximum cout Best-case cout = miimum cout Average cout Operatio Couts sequetialsearch 10 it rsequetialsearch(t a[], it, cost T& x) 11 {// Search the uordered list a[0: 1] for x. 12 // Retur positio if foud; retur 1 otherwise. 13 if ( < 1) retur 1; 14 if (a[ 1] == x) retur 1; 15 retur rsequetialsearch(a, 1, x); 16 } Worst: comparisos (usuccessful search) Best: 1 compariso Average: (+1)/2 23 Because equal probability 1/ for each elemet 1 i ( 1)/2 i 1 sequetialsearch.cpp 24

7 Operatio Couts isert (to a sorted array) Step Couts 10 void isert(t a[], it&, cost T& x) 11 {// Isert x ito the sorted array a[0: 1]. 12 // Assume a is of size > 13 it i; 14 for (i = 1; i >= 0 && x < a[i]; i ) 15 a[i+1] = a[i]; 16 a[i+1] = x; 17 ++; // oe elemet added to a 18 } Worst: comparisos (usuccessful search) Best: 1 compariso Average: comparisos 2 1 Isert to a[i+1] requires i comparisos ad to a[0] requires comparisos ( 1) ( i) j i0 j1 A step is a amout of computig that does ot deped o the istace characteristic 10 adds, 100 subtracts, 1000 multiplies ca all be couted as a sigle step adds caot be couted as 1 step s/e: step/executio isert.cpp Step Couts sum s/e Freq. Total Steps 08 T sum(t a[], it ) {// Retur sum of the umbers a[0: 1] T thesum = 0; for (it i = 0; i < ; i++) thesum += a[i]; 1 13 retur thesum; } t ( ) 23, 0 sum Step Couts rsum s/e Freq. Total Steps 08 template<class T> T rsum(t a[], it ) {// Retur sum of umbers a[0: 1] if ( > 0) 1?? 12 retur rsum(a, 1) + a[ 1]; 1?? 13 retur 0; 1?? 14 } 0 0 0? trsum ( ) 2 trsum ( 1) 22 t ( 2) rsum 2 trsum (0) 22, 0 sum.cpp 27 rsum.cpp 28

8 Step Couts traspose s/e Freq. Total Steps 09 void traspose(t **a, it rows) {//traspose a[0:rows 1][0:rows 1] for (it i = 0; i < rows; i++) 1 rows + 1 rows+1 12 for (it j = i+1; j < rows; j++) 1 rows(rows + 1)/2 rows(rows + 1)/2 13 swap(a[i][j], a[j][i]); 1 rows(rows -1)/2 rows(rows -1)/2 14 } rows 2 + rows + 1 Step Couts s/e is t always 0 or 1 x = sum(a, ); ( is the istace characteristic) has a s/e cout of 2+3. t rows rows rows ( ) 2 1 traspose Note: Here, swap(,) oly takes 1 s/e, although it takes 3 moves. matrixtraspose.cpp Step Couts ief (Prefix Sums) s/e Freq. Total Steps 18 void ief(t a[], T b[], it ) {// Compute prefix sums for (it j = 0; j < ; j++) b[j] = sum(a, j + 1); 2j + 6 ( + 5) 22 } sum(a, j + 1) b[j] = 1 j0 2( j1) j6 (2 j6) ( 5) t ( ) ief Asymptotic Notatio O( 2 ), ( 3 ), ( log ), o() Practical Complexities ief.cpp 31 32

9 Big O (O), Omega (), Theta (), ad Little Oh (o) Notatio Big O (O), Omega (), Theta (), ad Little Oh (o) Notatio f() = O(g()) f() is asymptitically smaller or equal to g() f() = (g()) f() is asymptotically bigger tha or equal to g() f() = (g()) f() is asymptotically equal to g() f() = o(g()) f() is asymptotically smaller tha g() 33 2 lg lg 1 ( ) ( ) 1 < log < < log < 2 < 3 < 2 <! < 1: costat 2 : quadratic log : logarithmic 3 : cubic : liear 2 : expoetial log : log!: factorial Asymptotic Idetities Step Couts ief (Prefix Sums) ( 3 ) ca be ay oe of O,, ad s/e Freq. Total Steps 18 void ief(t a[], T b[], it ) 0 0 (0) 19 {// Compute prefix sums. 0 0 (0) 20 for (it j = 0; j < ; j++) () 21 b[j] = sum(a, j + 1); 2j + 6 ( 2 ) 22 } 0 0 (0) ( 2 ) sum(a, j + 1) b[j] = 1 j0 (2 j6) ( 5) t ( ) 61 ief 2( j1) j ief.cpp 36

10 Practical Complexities Impractical Complexities 10 9 istructios/secod log istructios/secod μsec 10 μsec 1 msec 1 sec mi 3.2 x years 3.2 x years μsec 130 μsec 100 msec 17 mi days?????? msec 20 msec 17 mi 32 years x 10 7 years???????????? Faster Computer vs. Better Algorithm Algorithmic improvemet more useful tha hardware improvemet. e.g., Reduce from 2 to 3 Some Uses Of Performace Aalysis Determie practicality of algorithm Predict ru time o large istace Compare 2 algorithms that have differet asymptotic complexity e.g., O() ad O( 2 ) 39 40

11 Limitatios of Aalysis Memory Hierarchy Does t accout for costat factors. However, costat factor may domiate 1000 vs. 2, ad we are iterested oly i < 1000 Moder computers have a hierarchical memory orgaizatio with differet access time for memory at differet levels of the hierarchy. ALU RAM CPU MAIN L2 1C 2C 10C 100C L1 R KB 512KB 512MB Limitatios of Aalysis Performace Measuremet Our aalysis does t accout for this differece i memory access times. Measure actual time o a actual computer. What do we eed? Programs that do more work may take less time tha those that do less work

12 Performace Measuremet Needs Programmig laguage Workig program Computer Compiler ad optios to use gcc -O2 /O2 i Visual Studio for Speed Optimizatio Choosig Istace Size Developig the Test Data Settig up the Experimet Performace Measuremet Needs Data to use for measuremet Worst-case data Best-case data Average-case data Timig mechaism --- clock Timig i C++ 01 double clockspermillis = double(clocks_per_sec) / 1000; 02 // clock ticks per millisecod 03 clock_t starttime = clock(); isertiosort(a, ); // code to be timed double elapsedmillis = (clock() starttime) / 08 clockspermillis; 09 // elapsed time i millisecods Shortcomig Clock accuracy Assume 100 ticks Examiig remaiig cases, we get trueelapsedtime = fiishtime starttime ± 100 ticks To esure 10% accuracy, require elapsedtime = fiishtime starttime >= 1000 ticks Repeat work may times to brig total time to be >= 1000 ticks timeisertiosort1.cpp 47 48

13 Accurate Timig 01 clock_t starttime = clock(); 02 log umberofrepetitios; 03 do { 04 umberofrepetitios++; 05 // put code to iitialize a[] here 06 isertiosort(a, ); 07 } while (clock() starttime < 1000) 08 double elapsedmillis = (clock() starttime) / 09 clockspermillis; 10 double timeforcode = elapsedmillis/umberofrepetitios; Accuracy Now accuracy is 10%. First readig may be just about to chage to starttime Secod readig (fial value of clock())may have just chaged to fiishtime So fiishtime starttime is off by 100 ticks timeisertiosort2.cpp Bad Way To Time 01 do { 02 couter++; 03 starttime = clock(); 04 isertiosort(a, ); 05 elapsedtime += clock() starttime; 06 } while (elapsedtime < 1000) Calculate the Overhead 01 do 02 { 03 umberofrepetitios++; 04 // iitialize with worst case data 05 for (it i = 0; i < ; i++) 06 a[i] = i; 07 // isertiosort(a, ); 08 } while (clock( ) starttime < 1000); timeisertiosort3.cpp 51 timeisertiosort4.cpp 52

14 Time Shared System Widows (Server 2003/2008 with plugis) timeit f MyProgram UNIX time MyProgram Effect of Cache Misses o Ru Time 08 template<class T> 09 void squarematrixmultiply(t **a, T **b, T **c, it ) 10 {// Multiply the x matrices a ad b to get c. 11 for (it i = 0; i < ; i++) 12 for (it j = 0; j < ; j++) 13 { 14 T sum = 0; 15 for (it k = 0; k < ; k++) 16 sum += a[i][k] * b[k][j]; 17 c[i][j] = sum; 18 } 19 } i j k order More Cache Misses = 2000, t P = sec Oe ested loop More efficiet 53 timematrixmultiply1.cpp 54 Effect of Cache Misses o Ru Time 08 void fastsquarematrixmultiply(it **a, it **b, it **c, it ) 09 { 10 for (it i = 0; i < ; i++) Two ested loops 11 for (it j = 0; j < ; j++) 12 c[i][j] = 0; Less efficiet for (it i = 0; i < ; i++) 15 for (it j = 0; j < ; j++) 16 for (it k = 0; k < ; k++) 17 c[i][j] += a[i][k] * b[k][j]; 18 } i j k order More Cache Misses = 2000, t P = sec Effect of Cache Misses o Ru Time 08 void fastsquarematrixmultiply(it **a, it **b, it **c, it ) 09 { 10 for (it i = 0; i < ; i++) Two ested loops 11 for (it j = 0; j < ; j++) 12 c[i][j] = 0; Less efficiet for (it i = 0; i < ; i++) 15 for (it k = 0; j < ; j++) 16 for (it j = 0; k < ; k++) 17 c[i][j] += a[i][k] * b[k][j]; 18 } i k j order Less Cache Misses = 2000, t P = 54.2 sec timefastsquarematrixmultiply1.cpp 55 timefastsquarematrixmultiply2.cpp 56

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Ruig Time of a algorithm Ruig Time Upper Bouds Lower Bouds Examples Mathematical facts Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite

More information

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs What are we goig to lear? CSC316-003 Data Structures Aalysis of Algorithms Computer Sciece North Carolia State Uiversity Need to say that some algorithms are better tha others Criteria for evaluatio Structure

More information

Algorithm. Counting Sort Analysis of Algorithms

Algorithm. Counting Sort Analysis of Algorithms Algorithm Coutig Sort Aalysis of Algorithms Assumptios: records Coutig sort Each record cotais keys ad data All keys are i the rage of 1 to k Space The usorted list is stored i A, the sorted list will

More information

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis Outlie ad Readig Aalysis of Algorithms Iput Algorithm Output Ruig time ( 3.) Pseudo-code ( 3.2) Coutig primitive operatios ( 3.3-3.) Asymptotic otatio ( 3.6) Asymptotic aalysis ( 3.7) Case study Aalysis

More information

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Pseudocode ( 1.1) High-level descriptio of a algorithm More structured

More information

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects. The

More information

A graphical view of big-o notation. c*g(n) f(n) f(n) = O(g(n))

A graphical view of big-o notation. c*g(n) f(n) f(n) = O(g(n)) ca see that time required to search/sort grows with size of We How do space/time eeds of program grow with iput size? iput. time: cout umber of operatios as fuctio of iput Executio size operatio Assigmet:

More information

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time ( 3.1) Aalysis of Algorithms Iput Algorithm Output A algorithm is a step- by- step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects.

More information

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Ruig Time Most algorithms trasform iput objects ito output objects. The

More information

Data Structures and Algorithms Part 1.4

Data Structures and Algorithms Part 1.4 1 Data Structures ad Algorithms Part 1.4 Werer Nutt 2 DSA, Part 1: Itroductio, syllabus, orgaisatio Algorithms Recursio (priciple, trace, factorial, Fiboacci) Sortig (bubble, isertio, selectio) 3 Sortig

More information

Data Structures and Algorithms. Analysis of Algorithms

Data Structures and Algorithms. Analysis of Algorithms Data Structures ad Algorithms Aalysis of Algorithms Outlie Ruig time Pseudo-code Big-oh otatio Big-theta otatio Big-omega otatio Asymptotic algorithm aalysis Aalysis of Algorithms Iput Algorithm Output

More information

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming Lecture Notes 6 Itroductio to algorithm aalysis CSS 501 Data Structures ad Object-Orieted Programmig Readig for this lecture: Carrao, Chapter 10 To be covered i this lecture: Itroductio to algorithm aalysis

More information

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis Itro to Algorithm Aalysis Aalysis Metrics Slides. Table of Cotets. Aalysis Metrics 3. Exact Aalysis Rules 4. Simple Summatio 5. Summatio Formulas 6. Order of Magitude 7. Big-O otatio 8. Big-O Theorems

More information

Lecture 5. Counting Sort / Radix Sort

Lecture 5. Counting Sort / Radix Sort Lecture 5. Coutig Sort / Radix Sort T. H. Corme, C. E. Leiserso ad R. L. Rivest Itroductio to Algorithms, 3rd Editio, MIT Press, 2009 Sugkyukwa Uiversity Hyuseug Choo choo@skku.edu Copyright 2000-2018

More information

CSE 2320 Notes 8: Sorting. (Last updated 10/3/18 7:16 PM) Idea: Take an unsorted (sub)array and partition into two subarrays such that.

CSE 2320 Notes 8: Sorting. (Last updated 10/3/18 7:16 PM) Idea: Take an unsorted (sub)array and partition into two subarrays such that. CSE Notes 8: Sortig (Last updated //8 7:6 PM) CLRS 7.-7., 9., 8.-8. 8.A. QUICKSORT Cocepts Idea: Take a usorted (sub)array ad partitio ito two subarrays such that p q r x y z x y y z Pivot Customarily,

More information

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000. 5-23 The course that gives CM its Zip Memory Maagemet II: Dyamic Storage Allocatio Mar 6, 2000 Topics Segregated lists Buddy system Garbage collectio Mark ad Sweep Copyig eferece coutig Basic allocator

More information

How do we evaluate algorithms?

How do we evaluate algorithms? F2 Readig referece: chapter 2 + slides Algorithm complexity Big O ad big Ω To calculate ruig time Aalysis of recursive Algorithms Next time: Litterature: slides mostly The first Algorithm desig methods:

More information

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015. Presetatio for use with the textbook Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Hash Tables xkcd. http://xkcd.com/221/. Radom Number. Used with permissio uder Creative

More information

Data Structures and Programming 資料結構與程式設計. Topic 6 Stacks. Stacks. Stack of Cups. Stacks. top. top. bottom. bottom

Data Structures and Programming 資料結構與程式設計. Topic 6 Stacks. Stacks. Stack of Cups. Stacks. top. top. bottom. bottom Data Structures and Programming 資料結構與程式設計 Topic 6 Stacks 課程編號 :90 3900 EE 30 科目名稱 : 資料結構與程式設計授課教師 : 黃鼎偉時間地點 : 一 678 電機二館 229 Stacks Linear list. One end is called top. Other end is called bottom. Additions

More information

Data Structures and Programming 資料結構與程式設計. Topic 3 Linear Lists Array. AbstractDataType linearlist. Linear List - Array Representation

Data Structures and Programming 資料結構與程式設計. Topic 3 Linear Lists Array. AbstractDataType linearlist. Linear List - Array Representation Data Structures and Programming 資料結構與程式設計 Topic 3 Linear Lists Array 課程編號 :901 31900 EE 3011 科目名稱 : 資料結構與程式設計授課教師 : 黃鼎偉時間地點 : 一 678 電機二館 229 Abstract Data Type linearlist Abstract Data Type (ADT) AbstractDataType

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19 CIS Data Structures ad Algorithms with Java Sprig 09 Stacks, Queues, ad Heaps Moday, February 8 / Tuesday, February 9 Stacks ad Queues Recall the stack ad queue ADTs (abstract data types from lecture.

More information

Computer Science Foundation Exam. August 12, Computer Science. Section 1A. No Calculators! KEY. Solutions and Grading Criteria.

Computer Science Foundation Exam. August 12, Computer Science. Section 1A. No Calculators! KEY. Solutions and Grading Criteria. Computer Sciece Foudatio Exam August, 005 Computer Sciece Sectio A No Calculators! Name: SSN: KEY Solutios ad Gradig Criteria Score: 50 I this sectio of the exam, there are four (4) problems. You must

More information

Analysis of Algorithms

Analysis of Algorithms Presetatio for use with the textbook, Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Aalysis of Algorithms Iput 2015 Goodrich ad Tamassia Algorithm Aalysis of Algorithms

More information

Abstract Data Type array. 1D Array Representation In C++ Space Overhead. Data Structures and Programming 資料結構與程式設計. Topic 5 Arrays and Matrices

Abstract Data Type array. 1D Array Representation In C++ Space Overhead. Data Structures and Programming 資料結構與程式設計. Topic 5 Arrays and Matrices Data Structures and Programming 資料結構與程式設計 Topic 5 Arrays and Matrices 課程編號 :901 31900 EE 3011 科目名稱 : 資料結構與程式設計授課教師 : 黃鼎偉時間地點 : 一 678 電機二館 229 Abstract Data Type array Abstract Data Type (ADT) AbstractDataType

More information

CIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8)

CIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8) CIS 11 Data Structures ad Algorithms with Java Fall 017 Big-Oh Notatio Tuesday, September 5 (Make-up Friday, September 8) Learig Goals Review Big-Oh ad lear big/small omega/theta otatios Practice solvig

More information

CS200: Hash Tables. Prichard Ch CS200 - Hash Tables 1

CS200: Hash Tables. Prichard Ch CS200 - Hash Tables 1 CS200: Hash Tables Prichard Ch. 13.2 CS200 - Hash Tables 1 Table Implemetatios: average cases Search Add Remove Sorted array-based Usorted array-based Balaced Search Trees O(log ) O() O() O() O(1) O()

More information

ECE4050 Data Structures and Algorithms. Lecture 6: Searching

ECE4050 Data Structures and Algorithms. Lecture 6: Searching ECE4050 Data Structures ad Algorithms Lecture 6: Searchig 1 Search Give: Distict keys k 1, k 2,, k ad collectio L of records of the form (k 1, I 1 ), (k 2, I 2 ),, (k, I ) where I j is the iformatio associated

More information

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design College of Computer ad Iformatio Scieces Departmet of Computer Sciece CSC 220: Computer Orgaizatio Uit 11 Basic Computer Orgaizatio ad Desig 1 For the rest of the semester, we ll focus o computer architecture:

More information

CSE 417: Algorithms and Computational Complexity

CSE 417: Algorithms and Computational Complexity Time CSE 47: Algorithms ad Computatioal Readig assigmet Read Chapter of The ALGORITHM Desig Maual Aalysis & Sortig Autum 00 Paul Beame aalysis Problem size Worst-case complexity: max # steps algorithm

More information

Lecture 1: Introduction and Strassen s Algorithm

Lecture 1: Introduction and Strassen s Algorithm 5-750: Graduate Algorithms Jauary 7, 08 Lecture : Itroductio ad Strasse s Algorithm Lecturer: Gary Miller Scribe: Robert Parker Itroductio Machie models I this class, we will primarily use the Radom Access

More information

Major CSL Write your name and entry no on every sheet of the answer script. Time 2 Hrs Max Marks 70

Major CSL Write your name and entry no on every sheet of the answer script. Time 2 Hrs Max Marks 70 NOTE:. Attempt all seve questios. Major CSL 02 2. Write your ame ad etry o o every sheet of the aswer script. Time 2 Hrs Max Marks 70 Q No Q Q 2 Q 3 Q 4 Q 5 Q 6 Q 7 Total MM 6 2 4 0 8 4 6 70 Q. Write a

More information

Big-O Analysis. Asymptotics

Big-O Analysis. Asymptotics Big-O Aalysis 1 Defiitio: Suppose that f() ad g() are oegative fuctios of. The we say that f() is O(g()) provided that there are costats C > 0 ad N > 0 such that for all > N, f() Cg(). Big-O expresses

More information

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS)

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS) CSC165H1, Witer 018 Learig Objectives By the ed of this worksheet, you will: Aalyse the ruig time of fuctios cotaiig ested loops. 1. Nested loop variatios. Each of the followig fuctios takes as iput a

More information

Chapter 24. Sorting. Objectives. 1. To study and analyze time efficiency of various sorting algorithms

Chapter 24. Sorting. Objectives. 1. To study and analyze time efficiency of various sorting algorithms Chapter 4 Sortig 1 Objectives 1. o study ad aalyze time efficiecy of various sortig algorithms 4. 4.7.. o desig, implemet, ad aalyze bubble sort 4.. 3. o desig, implemet, ad aalyze merge sort 4.3. 4. o

More information

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5 Morga Kaufma Publishers 26 February, 28 COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Chapter 5 Set-Associative Cache Architecture Performace Summary Whe CPU performace icreases:

More information

Data Structures Week #9. Sorting

Data Structures Week #9. Sorting Data Structures Week #9 Sortig Outlie Motivatio Types of Sortig Elemetary (O( 2 )) Sortig Techiques Other (O(*log())) Sortig Techiques 21.Aralık.2010 Boraha Tümer, Ph.D. 2 Sortig 21.Aralık.2010 Boraha

More information

Algorithm Efficiency

Algorithm Efficiency Algorithm Effiiey Exeutig ime Compariso of algorithms to determie whih oe is better approah implemet algorithms & reord exeutio time Problems with this approah there are may tasks ruig ourretly o a omputer

More information

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle:

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle: Recursio Recursio Jordi Cortadella Departmet of Computer Sciece Priciple: Reduce a complex problem ito a simpler istace of the same problem Recursio Itroductio to Programmig Dept. CS, UPC 2 Mathematical

More information

Big-O Analysis. Asymptotics

Big-O Analysis. Asymptotics Big-O Aalysis 1 Defiitio: Suppose that f() ad g() are oegative fuctios of. The we say that f() is O(g()) provided that there are costats C > 0 ad N > 0 such that for all > N, f() Cg(). Big-O expresses

More information

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1 COSC 1P03 Ch 7 Recursio Itroductio to Data Structures 8.1 COSC 1P03 Recursio Recursio I Mathematics factorial Fiboacci umbers defie ifiite set with fiite defiitio I Computer Sciece sytax rules fiite defiitio,

More information

UNIT 4C Iteration: Scalability & Big O. Efficiency

UNIT 4C Iteration: Scalability & Big O. Efficiency UNIT 4C Iteratio: Scalability & Big O 1 Efficiecy A computer program should be totally correct, but it should also execute as quickly as possible (time-efficiecy) use memory wisely (storage-efficiecy)

More information

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 11 Frieds, Overloaded Operators, ad Arrays i Classes Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Overview 11.1 Fried Fuctios 11.2 Overloadig Operators 11.3 Arrays ad Classes 11.4

More information

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0 Polyomial Fuctios ad Models 1 Learig Objectives 1. Idetify polyomial fuctios ad their degree 2. Graph polyomial fuctios usig trasformatios 3. Idetify the real zeros of a polyomial fuctio ad their multiplicity

More information

Priority Queues. Binary Heaps

Priority Queues. Binary Heaps Priority Queues Biary Heaps Priority Queues Priority: some property of a object that allows it to be prioritized with respect to other objects of the same type Mi Priority Queue: homogeeous collectio of

More information

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions: CS 604 Data Structures Midterm Sprig, 00 VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Istructios: Prit your ame i the space provided below. This examiatio is closed book ad closed

More information

Heaps. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

Heaps. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 Presetatio for use with the textbook Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 201 Heaps 201 Goodrich ad Tamassia xkcd. http://xkcd.com/83/. Tree. Used with permissio uder

More information

Examples and Applications of Binary Search

Examples and Applications of Binary Search Toy Gog ITEE Uiersity of Queeslad I the secod lecture last week we studied the biary search algorithm that soles the problem of determiig if a particular alue appears i a sorted list of iteger or ot. We

More information

Data diverse software fault tolerance techniques

Data diverse software fault tolerance techniques Data diverse software fault tolerace techiques Complemets desig diversity by compesatig for desig diversity s s limitatios Ivolves obtaiig a related set of poits i the program data space, executig the

More information

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then UCLA PIC 10 B Problem Solvig usig C++ Programmig Ivo Diov, Asst. Prof. i Mathematics, Neurology, Statistics Istructor: Teachig Assistat: Suzae Nezzar, Mathematics Chapter 13 Templates for More Abstractio

More information

2. ALGORITHM ANALYSIS

2. 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 information

CMSC Computer Architecture Lecture 12: Virtual Memory. Prof. Yanjing Li University of Chicago

CMSC Computer Architecture Lecture 12: Virtual Memory. Prof. Yanjing Li University of Chicago CMSC 22200 Computer Architecture Lecture 12: Virtual Memory Prof. Yajig Li Uiversity of Chicago A System with Physical Memory Oly Examples: most Cray machies early PCs Memory early all embedded systems

More information

why study sorting? Sorting is a classic subject in computer science. There are three reasons for studying sorting algorithms.

why study sorting? Sorting is a classic subject in computer science. There are three reasons for studying sorting algorithms. Chapter 5 Sortig IST311 - CIS65/506 Clevelad State Uiversity Prof. Victor Matos Adapted from: Itroductio to Java Programmig: Comprehesive Versio, Eighth Editio by Y. Daiel Liag why study sortig? Sortig

More information

Sorting in Linear Time. Data Structures and Algorithms Andrei Bulatov

Sorting in Linear Time. Data Structures and Algorithms Andrei Bulatov Sortig i Liear Time Data Structures ad Algorithms Adrei Bulatov Algorithms Sortig i Liear Time 7-2 Compariso Sorts The oly test that all the algorithms we have cosidered so far is compariso The oly iformatio

More information

Homework 1 Solutions MA 522 Fall 2017

Homework 1 Solutions MA 522 Fall 2017 Homework 1 Solutios MA 5 Fall 017 1. Cosider the searchig problem: Iput A sequece of umbers A = [a 1,..., a ] ad a value v. Output A idex i such that v = A[i] or the special value NIL if v does ot appear

More information

Computational Geometry

Computational Geometry Computatioal Geometry Chapter 4 Liear programmig Duality Smallest eclosig disk O the Ageda Liear Programmig Slides courtesy of Craig Gotsma 4. 4. Liear Programmig - Example Defie: (amout amout cosumed

More information

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 9 Poiters ad Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 9.1 Poiters 9.2 Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 9-3

More information

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures Uiversity of Waterloo Departmet of Electrical ad Computer Egieerig ECE 250 Algorithms ad Data Structures Midterm Examiatio ( pages) Istructor: Douglas Harder February 7, 2004 7:30-9:00 Name (last, first)

More information

CMPT 125 Assignment 2 Solutions

CMPT 125 Assignment 2 Solutions CMPT 25 Assigmet 2 Solutios Questio (20 marks total) a) Let s cosider a iteger array of size 0. (0 marks, each part is 2 marks) it a[0]; I. How would you assig a poiter, called pa, to store the address

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13 CIS Data Structures ad Algorithms with Java Sprig 08 Stacks ad Queues Moday, February / Tuesday, February Learig Goals Durig this lab, you will: Review stacks ad queues. Lear amortized ruig time aalysis

More information

IMP: Superposer Integrated Morphometrics Package Superposition Tool

IMP: Superposer Integrated Morphometrics Package Superposition Tool IMP: Superposer Itegrated Morphometrics Package Superpositio Tool Programmig by: David Lieber ( 03) Caisius College 200 Mai St. Buffalo, NY 4208 Cocept by: H. David Sheets, Dept. of Physics, Caisius College

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 19 Query Optimizatio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio Query optimizatio Coducted by a query optimizer i a DBMS Goal:

More information

CS473-Algorithms I. Lecture 2. Asymptotic Notation. CS 473 Lecture 2 1

CS473-Algorithms I. Lecture 2. Asymptotic Notation. CS 473 Lecture 2 1 CS473-Algorithms I Lecture Asymptotic Notatio CS 473 Lecture 1 O-otatio (upper bouds) f() = O(g()) if positive costats c, 0 such that e.g., = O( 3 ) 0 f() cg(), 0 c 3 c c = 1 & 0 = or c = & 0 = 1 Asymptotic

More information

n Learn how resiliency strategies reduce risk n Discover automation strategies to reduce risk

n Learn how resiliency strategies reduce risk n Discover automation strategies to reduce risk Chapter Objectives Lear how resiliecy strategies reduce risk Discover automatio strategies to reduce risk Chapter #16: Architecture ad Desig Resiliecy ad Automatio Strategies 2 Automatio/Scriptig Resiliet

More information

Designing a learning system

Designing a learning system CS 75 Machie Learig Lecture Desigig a learig system Milos Hauskrecht milos@cs.pitt.edu 539 Seott Square, x-5 people.cs.pitt.edu/~milos/courses/cs75/ Admiistrivia No homework assigmet this week Please try

More information

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames Uit 4, Part 3 Recursio Computer Sciece S-111 Harvard Uiversity David G. Sulliva, Ph.D. Review: Method Frames Whe you make a method call, the Java rutime sets aside a block of memory kow as the frame of

More information

Pattern Recognition Systems Lab 1 Least Mean Squares

Pattern Recognition Systems Lab 1 Least Mean Squares Patter Recogitio Systems Lab 1 Least Mea Squares 1. Objectives This laboratory work itroduces the OpeCV-based framework used throughout the course. I this assigmet a lie is fitted to a set of poits usig

More information

condition w i B i S maximum u i

condition w i B i S maximum u i ecture 10 Dyamic Programmig 10.1 Kapsack Problem November 1, 2004 ecturer: Kamal Jai Notes: Tobias Holgers We are give a set of items U = {a 1, a 2,..., a }. Each item has a weight w i Z + ad a utility

More information

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence _9.qxd // : AM Page Chapter 9 Sequeces, Series, ad Probability 9. Sequeces ad Series What you should lear Use sequece otatio to write the terms of sequeces. Use factorial otatio. Use summatio otatio to

More information

Order statistics. Order Statistics. Randomized divide-andconquer. Example. CS Spring 2006

Order statistics. Order Statistics. Randomized divide-andconquer. Example. CS Spring 2006 406 CS 5633 -- Sprig 006 Order Statistics Carola We Slides courtesy of Charles Leiserso with small chages by Carola We CS 5633 Aalysis of Algorithms 406 Order statistics Select the ith smallest of elemets

More information

Avid Interplay Bundle

Avid Interplay Bundle Avid Iterplay Budle Versio 2.5 Cofigurator ReadMe Overview This documet provides a overview of Iterplay Budle v2.5 ad describes how to ru the Iterplay Budle cofiguratio tool. Iterplay Budle v2.5 refers

More information

APPLICATION NOTE PACE1750AE BUILT-IN FUNCTIONS

APPLICATION NOTE PACE1750AE BUILT-IN FUNCTIONS APPLICATION NOTE PACE175AE BUILT-IN UNCTIONS About This Note This applicatio brief is iteded to explai ad demostrate the use of the special fuctios that are built ito the PACE175AE processor. These powerful

More information

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen COP4020 Programmig Laguages Subrouties ad Parameter Passig Prof. Robert va Egele Overview Parameter passig modes Subroutie closures as parameters Special-purpose parameters Fuctio returs COP4020 Fall 2016

More information

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 8 Strigs ad Vectors Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Slide 8-3 8.1 A Array Type for Strigs A Array Type for Strigs C-strigs ca be used to represet strigs

More information

Algorithm Design Techniques. Divide and conquer Problem

Algorithm Design Techniques. Divide and conquer Problem Algorithm Desig Techiques Divide ad coquer Problem Divide ad Coquer Algorithms Divide ad Coquer algorithm desig works o the priciple of dividig the give problem ito smaller sub problems which are similar

More information

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 8 Strigs ad Vectors Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Copyright 2015 Pearso Educatio, Ltd..

More information

top() Applications of Stacks

top() Applications of Stacks CS22 Algorithms ad Data Structures MW :00 am - 2: pm, MSEC 0 Istructor: Xiao Qi Lecture 6: Stacks ad Queues Aoucemets Quiz results Homework 2 is available Due o September 29 th, 2004 www.cs.mt.edu~xqicoursescs22

More information

Ones Assignment Method for Solving Traveling Salesman Problem

Ones Assignment Method for Solving Traveling Salesman Problem Joural of mathematics ad computer sciece 0 (0), 58-65 Oes Assigmet Method for Solvig Travelig Salesma Problem Hadi Basirzadeh Departmet of Mathematics, Shahid Chamra Uiversity, Ahvaz, Ira Article history:

More information

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 4 Procedural Abstractio ad Fuctios That Retur a Value Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 4.1 Top-Dow Desig 4.2 Predefied Fuctios 4.3 Programmer-Defied Fuctios 4.4

More information

A Generalized Set Theoretic Approach for Time and Space Complexity Analysis of Algorithms and Functions

A Generalized Set Theoretic Approach for Time and Space Complexity Analysis of Algorithms and Functions Proceedigs of the 10th WSEAS Iteratioal Coferece o APPLIED MATHEMATICS, Dallas, Texas, USA, November 1-3, 2006 316 A Geeralized Set Theoretic Approach for Time ad Space Complexity Aalysis of Algorithms

More information

6.854J / J Advanced Algorithms Fall 2008

6.854J / J Advanced Algorithms Fall 2008 MIT OpeCourseWare http://ocw.mit.edu 6.854J / 18.415J Advaced Algorithms Fall 2008 For iformatio about citig these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 18.415/6.854 Advaced Algorithms

More information

BACHMANN-LANDAU NOTATIONS. Lecturer: Dr. Jomar F. Rabajante IMSP, UPLB MATH 174: Numerical Analysis I 1 st Sem AY

BACHMANN-LANDAU NOTATIONS. Lecturer: Dr. Jomar F. Rabajante IMSP, UPLB MATH 174: Numerical Analysis I 1 st Sem AY BACHMANN-LANDAU NOTATIONS Lecturer: Dr. Jomar F. Rabajate IMSP, UPLB MATH 174: Numerical Aalysis I 1 st Sem AY 018-019 RANKING OF FUNCTIONS Name Big-Oh Eamples Costat O(1 10 Logarithmic O(log log, log(

More information

Algorithms Chapter 3 Growth of Functions

Algorithms Chapter 3 Growth of Functions Algorithms Chapter 3 Growth of Fuctios Istructor: Chig Chi Li 林清池助理教授 chigchi.li@gmail.com Departmet of Computer Sciece ad Egieerig Natioal Taiwa Ocea Uiversity Outlie Asymptotic otatio Stadard otatios

More information

Graphs. Minimum Spanning Trees. Slides by Rose Hoberman (CMU)

Graphs. Minimum Spanning Trees. Slides by Rose Hoberman (CMU) Graphs Miimum Spaig Trees Slides by Rose Hoberma (CMU) Problem: Layig Telephoe Wire Cetral office 2 Wirig: Naïve Approach Cetral office Expesive! 3 Wirig: Better Approach Cetral office Miimize the total

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 18 Strategies for Query Processig Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio DBMS techiques to process a query Scaer idetifies

More information

DATA STRUCTURES. amortized analysis binomial heaps Fibonacci heaps union-find. Data structures. Appetizer. Appetizer

DATA STRUCTURES. amortized analysis binomial heaps Fibonacci heaps union-find. Data structures. Appetizer. Appetizer Data structures DATA STRUCTURES Static problems. Give a iput, produce a output. Ex. Sortig, FFT, edit distace, shortest paths, MST, max-flow,... amortized aalysis biomial heaps Fiboacci heaps uio-fid Dyamic

More information

Chapter 4 The Datapath

Chapter 4 The Datapath The Ageda Chapter 4 The Datapath Based o slides McGraw-Hill Additioal material 24/25/26 Lewis/Marti Additioal material 28 Roth Additioal material 2 Taylor Additioal material 2 Farmer Tae the elemets that

More information

Overview. Common tasks. Observation. Chapter 20 The STL (containers, iterators, and algorithms) 8/13/18. Bjarne Stroustrup

Overview. Common tasks. Observation. Chapter 20 The STL (containers, iterators, and algorithms) 8/13/18. Bjarne Stroustrup Overview Chapter 20 The STL (cotaiers, iterators, ad algorithms) Bjare Stroustrup www.stroustrup.com/programmig Commo tasks ad ideals Geeric programmig Cotaiers, algorithms, ad iterators The simplest algorithm:

More information

Math Section 2.2 Polynomial Functions

Math Section 2.2 Polynomial Functions Math 1330 - Sectio. Polyomial Fuctios Our objectives i workig with polyomial fuctios will be, first, to gather iformatio about the graph of the fuctio ad, secod, to use that iformatio to geerate a reasoably

More information

CS211 Fall 2003 Prelim 2 Solutions and Grading Guide

CS211 Fall 2003 Prelim 2 Solutions and Grading Guide CS11 Fall 003 Prelim Solutios ad Gradig Guide Problem 1: (a) obj = obj1; ILLEGAL because type of referece must always be a supertype of type of object (b) obj3 = obj1; ILLEGAL because type of referece

More information

Operating System Concepts. Operating System Concepts

Operating System Concepts. Operating System Concepts Chapter 4: Mass-Storage Systems Logical Disk Structure Logical Disk Structure Disk Schedulig Disk Maagemet RAID Structure Disk drives are addressed as large -dimesioal arrays of logical blocks, where the

More information

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 2 C++ Basics Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 2.1 Variables ad Assigmets 2.2 Iput ad Output 2.3 Data Types ad Expressios 2.4 Simple Flow of Cotrol 2.5 Program

More information

An Improved Shuffled Frog-Leaping Algorithm for Knapsack Problem

An Improved Shuffled Frog-Leaping Algorithm for Knapsack Problem A Improved Shuffled Frog-Leapig Algorithm for Kapsack Problem Zhoufag Li, Ya Zhou, ad Peg Cheg School of Iformatio Sciece ad Egieerig Hea Uiversity of Techology ZhegZhou, Chia lzhf1978@126.com Abstract.

More information

Structuring Redundancy for Fault Tolerance. CSE 598D: Fault Tolerant Software

Structuring Redundancy for Fault Tolerance. CSE 598D: Fault Tolerant Software Structurig Redudacy for Fault Tolerace CSE 598D: Fault Tolerat Software What do we wat to achieve? Versios Damage Assessmet Versio 1 Error Detectio Iputs Versio 2 Voter Outputs State Restoratio Cotiued

More information

The VSS CCD photometry spreadsheet

The VSS CCD photometry spreadsheet The VSS CCD photometry spreadsheet Itroductio This Excel spreadsheet has bee developed ad tested by the BAA VSS for aalysig results files produced by the multi-image CCD photometry procedure i AIP4Wi v2.

More information

Multiprocessors. HPC Prof. Robert van Engelen

Multiprocessors. HPC Prof. Robert van Engelen Multiprocessors Prof. Robert va Egele Overview The PMS model Shared memory multiprocessors Basic shared memory systems SMP, Multicore, ad COMA Distributed memory multicomputers MPP systems Network topologies

More information

Markov Chain Model of HomePlug CSMA MAC for Determining Optimal Fixed Contention Window Size

Markov Chain Model of HomePlug CSMA MAC for Determining Optimal Fixed Contention Window Size Markov Chai Model of HomePlug CSMA MAC for Determiig Optimal Fixed Cotetio Widow Size Eva Krimiger * ad Haiph Latchma Dept. of Electrical ad Computer Egieerig, Uiversity of Florida, Gaiesville, FL, USA

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 6 Defiig Fuctios Pytho Programmig, 2/e 1 Objectives To uderstad why programmers divide programs up ito sets of cooperatig fuctios. To be able to

More information

CS 11 C track: lecture 1

CS 11 C track: lecture 1 CS 11 C track: lecture 1 Prelimiaries Need a CMS cluster accout http://acctreq.cms.caltech.edu/cgi-bi/request.cgi Need to kow UNIX IMSS tutorial liked from track home page Track home page: http://courses.cms.caltech.edu/courses/cs11/material

More information

. Written in factored form it is easy to see that the roots are 2, 2, i,

. Written in factored form it is easy to see that the roots are 2, 2, i, CMPS A Itroductio to Programmig Programmig Assigmet 4 I this assigmet you will write a java program that determies the real roots of a polyomial that lie withi a specified rage. Recall that the roots (or

More information

1&1 Next Level Hosting

1&1 Next Level Hosting 1&1 Next Level Hostig Performace Level: Performace that grows with your requiremets Copyright 1&1 Iteret SE 2017 1ad1.com 2 1&1 NEXT LEVEL HOSTING 3 Fast page loadig ad short respose times play importat

More information