2 Then 1 2 1 2 Example 3 2 1 7 12 What is the time complexity of Let 1 3 2 1 2

2 then 1 2 1 2 example 3 2 1 7 12 what is the time

This preview shows page 14 - 20 out of 27 pages.

𝑛 = 𝑂(? 2 𝑛 ) Then, ? 1 𝑛 ⋅ ? 2 𝑛 = 𝑂(? 1 𝑛 ⋅ ? 2 (𝑛)) Example ? 𝑛 = (𝑛 3 + 𝑛 2 + 1)(𝑛 7 + 𝑛 12 ) What is the time complexity of ? 𝑛 Let ? 1 𝑛 = (𝑛 3 + 𝑛 2 + 1) , ? 2 𝑛 = (𝑛 7 + 𝑛 12 ) ? 1 𝑛 = 𝑂 𝑛 3 , ? 2 𝑛 = 𝑛 12 ? 𝑛 = ? 1 𝑛 ⋅ ? 2 𝑛 = 𝑂 𝑛 3 ⋅ 𝑛 12 = 𝑂(𝑛 15 ) Product Rule Complexity Analysis: Growth of Functions 14 The big multiple the big
Image of page 14
CSCI2100C Data Structures Sum property ? 1 𝑛 = 𝑂 ? 1 𝑛 , ? 2 𝑛 = 𝑂(? 2 𝑛 ) Then, ? 1 𝑛 + ? 2 𝑛 = 𝑂 max(? 1 𝑛 , ? 2 𝑛 ) Example ? 𝑛 = 𝑛 3 + 𝑛 2 + 1 + (𝑛 4 + 𝑛 7 + 𝑛 20 + 𝑛 30 ) ? 1 = 𝑛 3 + 𝑛 2 + 1 , ? 2 = 𝑛 4 + 𝑛 7 + 𝑛 20 + 𝑛 30 ? 1 = 𝑂(𝑛 3 ) ? 2 = 𝑂(𝑛 30 ) ? 𝑛 = 𝑂 max(𝑛 3 , 𝑛 30 ) 𝑂 𝑛 30 Big-Oh Rules (iii) Complexity Analysis: Growth of Functions 15 The bigger of the two big
Image of page 15
CSCI2100C Data Structures We denote the number of basic operations of each line as a function of n ? 1 𝑛 , ? 2 𝑛 , ⋯ LinearSearch: Using Sum Property Complexity Analysis: Growth of Functions 16 LinearSearch(A, n, searchnum) for i = 0 to n -1 if a [i] = searchnum return i return -1 1 2 3 4 2*n +2 2*n 1 1 Total: 4*n+4 ? 1 𝑛 = 𝑂(𝑛) ? 2 𝑛 = 𝑂(𝑛) ? 3 𝑛 = 𝑂(1) ? 4 𝑛 = 𝑂(1) 𝑂 max(𝑛, 𝑛 , 1,1 ) = 𝑂(𝑛)
Image of page 16
CSCI2100C Data Structures What is wrong here? . Complexity Analysis: Growth of Functions 17
Image of page 17
CSCI2100C Data Structures Log functions grow slower than power functions. lim 𝑛→∞ log 𝑛 ? 𝑛 ? → 0 , for ?, ? > 0 If ? 𝑛 = log 𝑛 ? + 𝑛 ? where ?, ? > 0, Then ?(𝑛) = 𝑂(𝑛 ? ) . If ? 𝑛 = log 𝑛 ? + ? , where ?, ? > 0, Then ?(𝑛) = 𝑂 log 𝑛 ? . Example ? 𝑛 = log 𝑛 2 + 𝑛 0.0001 Let ? = 2, ? = 0.0001 𝑂(𝑛 0.0001 ) Big-Oh Rules (iv) Complexity Analysis: Growth of Functions 18 log only beats constant
Image of page 18
What is the time complexity of ? 2)What is the time complexity of
Image of page 19
Image of page 20

You've reached the end of your free preview.

Want to read all 27 pages?

  • Fall '14
  • Big O notation, Analysis of algorithms, Computational complexity theory

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture