I’m working on a macro economics multi-part question and need an explanation and answer to help me learn.

- UMD Data Structures and Algorithms

Big-O practice. Find T(n) and O() of this 14 questions.

- for (i=n; i<=2n, i+=2)

for (j = 0; j < n; j++)

print(“Hi Mom”) - for (i=1; I <= 1000; i++)

for (j=1; j<=n; j++)

for (k=1; k<=1000; k++)

for (l=1; l<=n; l++)

x+=1; - for (i=n*n*n; i>1; i/=n)

print(“I Love Algorithms”) - for (i=1; i<=n; i+=10)

print(“Hi dad”) - for (i=1; i<=n; i*=10)

print(“hmmm…”) - i=n

While(i>1)

i/=4; - for (i=1; i<=n; i+=i)

print(“aardvarks are nocturnal”) - for (i=0; i<n; i++)

for (j=0; j<=n; j+=2)

print(“aardvarks eat ants”) - for (i=0; i < n*n + 5*n + 17; i+=4)

print(“get an aardvark for a pet today!”) - for (i=0; i < n; i++){ if (i % 2 == 0)for (j = 0; j < 5*n*n, j++) print(“uh oh!”) }else{ for (j = 0; j < n/2, j++) print(“oh my”)}}
- for (i=0; i < n+1; i++)

if (i = n-1)

for (j=0; j <n; j++)

print(“why?”)

else

print(“why not?”) - i = n*n*n;

i*=i;

while (i > 5)

print(“really?”)

i -= 3; - Suppose a method returns either 0, -1, and 1 with equal likelihood. If 0 is returned then 130 loop iterations occur. If -1 or 1 is returned then 75 iterations occur. What is T(n) in the best case, worst case, and average case?
- How does the previous T(n) change if the likelihood of 0 is 20% and -1 and 1 occur at 30% and 50% respectively?

0 comments