This preview shows pages 1–12. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 71/31Lesson 7: Performance Analysis & Asymptotic NotationlAfter completing this lesson, you should be able to do the following:–Carry out Performance Analysis–Describe the Space and Time Complexity–Identify Comparison and Step Count–Define Asymptotic Complexity–Perform the Best, Worst, and AverageCase Analysis72/31Complexity lSpace/MemorylTime–Count a particular operation–Count number of steps–Asymptotic complexity73/31Comparison Countfor (int i = 1; i < a.length; i++){// insert a[i] into a[0:i1]int t = a[i];int j;for (j = i  1; j >= 0 && t < a[j]; j)a[j + 1] = a[j];a[j + 1] = t;}Insertion Sort74/31Comparison CountlAn instance may have many characteristics (e.g. no of inputs/outputs, magnitudes of inputs/outputs)lPick an instance characteristic … n, n = a.length for insertion sortlDetermine count as a function of this instance characteristic.75/31Comparison Countfor (j = i  1; j >= 0 && t < a[j]; j)a[j + 1] = a[j];How many comparisons are made?76/31Comparison Countfor (j = i  1; j >= 0 && t < a[j]; j)a[j + 1] = a[j];number of comparisons depends on a[]s and t as well as on i 77/31Comparison CounthWorstcase count = maximum counthBestcase count = minimum counthAverage count78/31WorstCase Comparison Countfor (j = i  1; j >= 0 && t < a[j]; j)a[j + 1] = a[j];a = [1, 2, 3, 4] and t = 0 => 4 comparisonsa = [1,2,3,…,i] and t = 0 => i comparisons79/31WorstCase Comparison Countfor (int i = 1; i < n; i++)for (j = i  1; j >= 0 && t < a[j]; j)a[j + 1] = a[j];total no of comparisons = 1 + 2 + 3 + … + (n1)= (n1)n/21234Supposen – 1 = 4Therefore, the total no of dots =4 (4 + 1) / 2 = 10(n – 1) n / 24 + 1 = 5710/31BestCase Comparison Countfor (j = i  1; j >= 0 && t < a[j]; j)a[j + 1] = a[j];a = [1, 2, 3, 4] and t = 5 => 1 comparisona = [1,2,3,…,i] and t > i => 1 comparison711/31BestCase Comparison Countfor (int i = 1; i < n; i++)for (j = i  1; j >= 0 && t < a[j]; j)a[j + 1] = a[j];total no of comparisons = 1 + 1 + … + 1 = n1444 3444 21n1712/31...
View
Full
Document
This note was uploaded on 08/18/2011 for the course COMP 3868 taught by Professor Keithchan during the Summer '97 term at Hong Kong Polytechnic University.
 Summer '97
 KEITHCHAN

Click to edit the document details