Question

In: Computer Science

42. Describe the order of growth of each of the following functions using O notation. a....

42. Describe the order of growth of each of the following functions using O notation.

a. N2+3N

b. 3N2+N

c. N5+100N3+245

d. 3NlogN+N2 2

e. 1+N+N2 +N3 +N4

f. (N * (N − 1)) / 2

  1. Describe the order of growth of each of the following code sections, using O notation:

    1. count = 0;
      for (i = 1; i <= N; i++)

      count++;

    2. count=0;

      for (i = 1; i <= N; i++) for (j = 1; j <= N; j++)

      count++;

    3. value = N; count = 0;

      while (value > 1) {

      value = value / 2;

      count++; }

    4. count=0; value = N;

      value = N * (N – 1);

      count = count + value;

    5. count = 0;

      for (i = 1; i <= N; i++) count++;

      for (i = N; i >= 0; i--) count++;

    6. count = 0;
      for (i = 1; i <=N; i++)

      for (j = 1; j <= 5; j++) count++;

Solutions

Expert Solution

42) Rules for defining growth in terms of O notation are as below.

a) Do not consider constants. Ignore them while finding big O notation.

b) Ignore lower order terms while addition or subtraction.

Considering rules above, let's find out big O notation as below.

for the code sections,

a)

count = 0;
for (i = 1; i <= N; i++)

count++;

code runs from count 0 till count N. i value changes from 1 to N incrementing count by 1. So the complexity is O(N)

b)

count=0;

for (i = 1; i <= N; i++) for (j = 1; j <= N; j++)

count++;

these are 2 nested loops, both running from 1 to N so the complexity of code is O(N) for outer loop and O(N) for inner loop

code complexity is O(N)*O(N) = O(N2)

c)

value = N; count = 0;

while (value > 1) {

value = value / 2;

count++; }

loop runs from value = N to 1 with value going by value/ 2 everytime. value = N, N/2, N/4 and so on.

This has a time complexity of O(log N)

d)

count=0; value = N;

value = N * (N – 1);

count = count + value;

single statements complexity is O(1) for each statement since there is no loop

e)

count = 0;

for (i = 1; i <= N; i++) count++;

for (i = N; i >= 0; i--) count++;

first loop is O(N) and second is O(N) too as it is going from i = N to 0. so it runs N times. these 2 loops are not nested. hence the complexity will be added.

Code complexity is O(N+N) = O(2N) ignore 2 as it is a constant. answer is O(N)

f)

count = 0;
for (i = 1; i <=N; i++)

for (j = 1; j <= 5; j++) count++;

these are 2 nested loops. one is under another loop. outer loop has a complexity of O(N)

inner loop runs 5 times so this is O(5)

since they are nested complexity is multiplied.

code complexity is O(5*N) = O(N) ignore 5 as it is constant as per rule


Related Solutions

Match the following functions to their respective big-O notation 1. 5 + 0.001n3 + 0.025n 2....
Match the following functions to their respective big-O notation 1. 5 + 0.001n3 + 0.025n 2. 100nlog n + n5 + 100n 3. n2log n + nlog n 4. 2n + n5 + 5n 5. 100n + 0.01n2 A. O(n3) B. O(5n) C. O(n2) D. O(n5) E. O(n2log n)
Algorithm problem 6 [Problem3-3] a Rank the following functions by order of growth; that is,find an...
Algorithm problem 6 [Problem3-3] a Rank the following functions by order of growth; that is,find an arrangement g1,g2,...,g30 of the functions satisfying g1 ∈ Ω(g2),g2 ∈ Ω(g3),...,g29 ∈ Ω(g30). Partition your list into equivalence classes such that ƒ(n) and g(n) are in the same class if and only if ƒ(n)∈Θ(g(n)). - lg(lg∗ n)    - 2^(lg∗ n)    -( sqrt(2))^(lg n)    - n^2 - n!    - (lg n)! - (3/2)^n    - n^3    - lg^(2)*n    -...
Solve each of the following problems by translating the values into two’s complement notation (using patterns...
Solve each of the following problems by translating the values into two’s complement notation (using patterns of 5 bits), converting any subtraction problem to an equivalent addition problem, and performing that addition. Check your work by converting your answer to base 10 notation. (Watch out for overflow.) a. 5 + 1 b. 12 – 5 c. 5 – 11 d. 12 + 5 e. 5 – 1
It is known that in Canada, the blood types have the following distribution: 46% O, 42%...
It is known that in Canada, the blood types have the following distribution: 46% O, 42% A, 9% B, 3% AB. A randomly chosen Canadian receives a blood transfusion. Knowing that O is a universal donor, A can only donate to A and AB, B can only donate to B and AB, and AB can only donate to AB, what is the probability that the transfusion is not successful? Graph this distribution.
It is known that in Canada, the blood types have the following distribution: 46% O, 42%...
It is known that in Canada, the blood types have the following distribution: 46% O, 42% A, 9% B, 3% AB. A randomly chosen Canadian receives a blood transfusion. Knowing that O is a universal donor, A can only donate to A and AB, B can only donate to B and AB, and AB can only donate to AB, what is the probability that the transfusion is not successful? Graph this distribution.
Describe each of the following economic functions of money and provide an example of each: (1)...
Describe each of the following economic functions of money and provide an example of each: (1) medium of exchange; (2) standard of value; and (3) store of value.
1. For each of the following, prove using the definition of O(·): (a) 7n + log(n)...
1. For each of the following, prove using the definition of O(·): (a) 7n + log(n) = O(n) (b) n2 + 4n + 7 = O(n2 ) (c) n! = O(nn) (d) 2n = O(22n) Please explain the procedure clearly for all (They are of the same question)
How to determine whether the following statements about big-O notation are true or false? (a) Let...
How to determine whether the following statements about big-O notation are true or false? (a) Let f(n) = √ n log n − 4, then f(n) = O(n^ 2) (b) Let f(n) = 4 n + 2 log^ 2 (n), then f(n) = O(log^ 2 (n)) (c) Let f(n) = 5 √ n + 2, then f(n) = Ω(log^ 4 (n)) (d) Let f(n) = 5 n^ 2 + 5 n log n + 4, then f(n) = O(n^3 )...
Identify (using the most appropriate of lists, rules, or notation) the elements of each of the...
Identify (using the most appropriate of lists, rules, or notation) the elements of each of the following sample spaces: 1) Weight of a randomly selected crawfish 2) A cubic die and a octahedron (8 sided) die being rolled 3) Human IQ 4) Days till next hurricane hits Baton Rouge 5) A die being rolled until an odd number is obtained thrice in a row
Exercise 3.1.5: Expressing sets in set builder notation. About Express each set using set builder notation....
Exercise 3.1.5: Expressing sets in set builder notation. About Express each set using set builder notation. Then if the set is finite, give its cardinality. Otherwise, indicate that the set is infinite. PLEASE show some explanation how you got answer. Thanks! (a) {-2, -1, 0, 1, 2} (b) { 3, 6, 9, 12, .... } (c) { -3, -1, 1, 3, 5, 7, 9 } (d) { 0, 10, 20, 30, ...., 1000 } Exercise 3.2.4: A subset of a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT