{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CC2203-Les07Perf-for-viewing

# CC2203-Les07Perf-for-viewing - Lesson 7 Performance...

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

7-1/31 Lesson 7: Performance Analysis & Asymptotic Notation lozenge4 After 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 Analysis

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

View Full Document
7-2/31 Complexity lozenge4 Space/Memory lozenge4 Time Count a particular operation Count number of steps Asymptotic complexity
7-3/31 Comparison Count for (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 Sort

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

View Full Document
7-4/31 Comparison Count lozenge4 An instance may have many characteristics (e.g. no of inputs/outputs, magnitudes of inputs/outputs) lozenge4 Pick an instance characteristic … n, n = a.length for insertion sort lozenge4 Determine count as a function of this instance characteristic.
7-5/31 Comparison Count for (j = i - 1; j >= 0 && t < a[j] ; j--) a[j + 1] = a[j]; How many comparisons are made?

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

View Full Document
7-6/31 Comparison Count for (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/31 Comparison Count head2right Worst-case count = maximum count head2right Best-case count = minimum count head2right Average count

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

View Full Document
7-8/31 Worst-Case Comparison Count for (j = i - 1; j >= 0 && t < a[j] ; j--) a[j + 1] = a[j]; a = [1, 2, 3, 4] and t = 0 => 4 comparisons a = [1,2,3,…,i] and t = 0 => i comparisons
7-9/31 Worst-Case Comparison Count for (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/2 1 2 3 4 Suppose n – 1 = 4 Therefore, the total no of dots = 4 (4 + 1) / 2 = 10 (n – 1) n / 2 4 + 1 = 5

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

View Full Document
7-10/31 Best-Case Comparison Count for (j = i - 1; j >= 0 && t < a[j] ; j--) a[j + 1] = a[j]; a = [1, 2, 3, 4] and t = 5 => 1 comparison a = [1,2,3,…,i] and t > i => 1 comparison
7-11/31 Best-Case Comparison Count for (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-1 4 4 4 3 4 4 4 2 1 n-1

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern