Jump to content

bccheatha

New Members
  • Posts

    1
  • Joined

  • Last visited

Profile Information

  • Favorite Area of Science
    Computers

bccheatha's Achievements

Lepton

Lepton (1/13)

0

Reputation

  1. I am very new to learning about Big-O so its still confusing to me. Could you please check my answers to these problems and perhaps give a me a nudge in the right direction on any that i got wrong. The ones involving code give me the most trouble. 1. What is the Big Oh of the following: a. 4n^2 + 2 is: O(n^2) ? b. n^2 + 14n + 6 is: O(n^2) c. 5n^3 + 10n^2 – n – 8 is: O(n^3) d. 3n^2 + 2n is: O(n^2) I apologize for the poor formatting with the code. 3. int count = 0; O(1) for (int i = 1; i <= n; i++) { i = n; count += 1; } // end for 4. int total = 0; O(n^3) for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) { for (int k = 1; three < j; j++) { total += 1; } //end for } // end for } // end for 5. int total = 0; O(n^3) for (int one = 1; one <= n; one++) { for (int two = 1; two < n; two++) { for (int three = 1; three < 10; three++) { total += 1; } //end for } // end for } // end for 6. int total = 0; O(log n) for (int pass = 1; pass <= n; pass*=2) { total += 1; } // end for 7. p = n; O(n log n) while (n>1) { n = n/2; while (p>0) { p = p - 1; } // end while } // end while 8. for (int i = 1; i <= n; i+=2) { O(log n) j=1; while(j < n) { j = j + 2; x = x + 2; } // end while } // end for
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.