Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSE 2321

HOMEWORK 7

SPRING 2024

Due 7:00 pm Friday, March 8th

1.   Determine the running time of the following algorithm. Write summations to represent loops and solve using bounding. Be sure to show work on both the upper bound and lower bound, justify the split, and check that the bounds differ by only a constant factor. Use asymptotic notation to write the answer.

Func1(n)

1       s  ←  0;

2       for i  ←  nton2  do

3             for j  ←  1 to i do

4                   fork  ←  9n to 10n2  do

5                      form  ←  itok

6                                   s  ←  s  +  i   − j  +  k − m;

7                          end

8                    end

9             end

10     end

11     return (s);

2.   Find the running time for each of the following algorithms. Show work by finding a table of values for each while loop, writing the summations, then solving. Be sure to show work on both the upper bound and lower bound, justify the split, and check that the bounds differ by only a constant factor. Use asymptotic notation to write the answer.

a)   Func2(n)

1       s  ←  0;

2       j  ←  7n2 ;

3       while (j  >  8) do

4              s  ←  s  +  i  − j;

5              j  ←  ⌊j/9⌋;

6       end

7       return (s);

b)  Func3(n)

1       s  ←  0;

2       i  ←  n;

3       while (i  <  5n3) do

4           j  ←  7n2 ;

5             while (j  >  8) do

6                  s  ←  s  +  i  − j;

7                  j  ←  ⌊j/9⌋;

8              end

9             i  ←  4  ×  i;

10     end

11     return (s);

c)  Func4(n)

1       s  ←  0;

2       for i  ←  1 to 5n do

3            j  ←  3i;

4             while (j  <  i3) do

5                   s  ←  s  +  i  − j;

6                  j  ←  5  × j;

7             end

8       end

8    return (s);

3.   Give the asymptotic complexity of each of the following functions in simplest terms and

then order the functions by asymptotic dominance. That is, produce a permutation, f1 (n), f2 (n), … , such that fi( n) = O(fi+1 (n)). Note if any two functions are asymptotically equivalent, i.e., if fi (n) = Θ(fi+1 (n)). Note: ‘lg x’ is asimpler notation for ‘log2  x’ .

•     fa (n) =n4  lg n4 + lg n2 ;

•    fb (n) = 3n+1 + 4n

•    fc(n) = 6n0.2   + 3n0.8

•    fd (n) = 2

•    fe(n) = 4 lg (n2  + 2n) + 6n0.7

•    ff(n) = n5 + 1010 lg (n+100)

•     fg (n) = 3n lg (n2 + 2) + n2

•    fh (n) =  ((9n2)( 6n)(121))1/2

•    fi(n) = (4n5 + 5n2  + lg n5)1/2

•    fj (n) = 400