CC2203-Les07Perf-for-viewing

CC2203-Les07Perf-for-viewing - 7-1/31Lesson 7: Performance...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 7-1/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 Average-Case Analysis7-2/31Complexity lSpace/MemorylTime–Count a particular operation–Count number of steps–Asymptotic complexity7-3/31Comparison Countfor (int i = 1; i < a.length; i++){// insert a[i] into a[0:i-1]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 Sort7-4/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.7-5/31Comparison Countfor (j = i - 1; j >= 0 && t < a[j]; j--)a[j + 1] = a[j];How many comparisons are made?7-6/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 7-7/31Comparison CounthWorst-case count = maximum counthBest-case count = minimum counthAverage count7-8/31Worst-Case 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 comparisons7-9/31Worst-Case 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 + … + (n-1)= (n-1)n/21234Supposen – 1 = 4Therefore, the total no of dots =4 (4 + 1) / 2 = 10(n – 1) n / 24 + 1 = 57-10/31Best-Case 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 comparison7-11/31Best-Case 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 = n-1444 3444 21n-17-12/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.

Page1 / 31

CC2203-Les07Perf-for-viewing - 7-1/31Lesson 7: Performance...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online