{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
7-2/31 Complexity lozenge4 Space/Memory lozenge4 Time Count a particular operation Count number of steps Asymptotic complexity
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
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.
Image of page 4
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?
Image of page 5

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

View Full Document Right Arrow Icon
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
Image of page 6
7-7/31 Comparison Count head2right Worst-case count = maximum count head2right Best-case count = minimum count head2right Average count
Image of page 7

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

View Full Document Right Arrow Icon
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
Image of page 8
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
Image of page 9

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

View Full Document Right Arrow Icon
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
Image of page 10
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
Image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern