Question

Hello, I would like to get help with the following algorithms and their respective analysis of...

Hello, I would like to get help with the following algorithms and their respective analysis of runtime along with their recurrence equations, thanks in advance.

1.       Analyze each of the following algorithms by providing a tight big-Oh bound on the run time with respect to the value n. Create a recurrence equation.

a.    

void padawan(int n)

{

      if( n <= 10 )

            time++;

      else

      {

            for(int i=0; i<n; i++)

                        time++;

            padawan(n/3);

            padawan(n/3);

            padawan(n/3);

      }

}

b.   

void nerfHerder(int n)

{

      if( n <= 15 )

            time++;

      else

      {

            for(int i=0; i<n; i++)

                  time++;

            nerfHerder(n-1);

      }

}

c.   

void squire(int n)

{

      if( n <= 12 )

            time++;

      else

      {

            squire(n/2);

            squire(n/2);

            for(int i=0; i<n; i++)

                  for(int j=i; j<n; j++)

                        time++;

            squire(n/2);

            squire(n/2);

            squire(n/2);

            squire(n/2);

            squire(n/2);

            squire(n/2);

      }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Master method

T(n) = aT(n/b) + f(n) where a>=1 and b>1

There are following three cases:
1. If f(n) = Θ(nc) where c < Logba then T(n) = Θ(nLogba)

2. If f(n) = Θ(nc) where c = Logba then T(n) = Θ(ncLog n)

3.If f(n) = Θ(nc) where c > Logba then T(n) = Θ(f(n))

a) Given equation runtime

Runtime for if condition is O(1)

In else condition runtime for loop is O(n) and for recurrence relation runtime can be written as

 

By using Master method as as c=logab it falls under case 2, T(n)=

b)runtime for loop is O(n)

recurrence relation is

and c>logab as c=1,a=1,b=1 it falls under case 3,T(n)=

3)runtime for for loops is O(n2)

As there are 6 recursive functions

c<logab because a=6,b=2 and c=2 this falls under case 1,Therefore

Add a comment
Know the answer?
Add Answer to:
Hello, I would like to get help with the following algorithms and their respective analysis of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PROBLEM 1 (24 points): For each of the recursive functions below and on the next page,...

    PROBLEM 1 (24 points): For each of the recursive functions below and on the next page, give a correct recurrence relation expressing its runtime and then a tight runtime bound for the recurrence relation. Functions that take parameters lo and hi: n=hi-lo+1 RECURRENCE RELATION: int foo(int a[], int lo, int hi) { int x, i, j, m; X = 0; if(lo==hi) return a[10]; for(i=lo; i<=hi; i++) { for(j=i+1; j<=hi; j++) { if(a[i] % 2) x += a[i]; else x -=...

  • Based off Java Homework 2 Analyzing Runtimes of Algorithms Homework Objectives Be able to understand the...

    Based off Java Homework 2 Analyzing Runtimes of Algorithms Homework Objectives Be able to understand the part of the code • Be able to analyze the efficiency of the given part of the code Introduction We have shown the Big-O Notation. Use Big-O notation to analyze the codes. Task #1 Big-O based Runtime Analysis 1. Give the Big-O runtime of the following code parts as much as tight. for (int i = 0; i < N;i++){ sequence of statements for...

  • Analyze the runtime of c functions below and give a tight runtime bound for each. ....

    Analyze the runtime of c functions below and give a tight runtime bound for each. . . Both functions have the same best-case and worst-case runtime (so this is not an issue). Since we want a "tight" runtime bound, your final answer should be in big-m form. Show your work! "The runtime of foo() is e(< something >)" is not sufficient even if <something> happens to be correct. In other words, convince the reader of the correctness of your answer....

  • 3a. Runtime Analysis: For each of the following recursive algorithms, state the recurrence equation that is...

    3a. Runtime Analysis: For each of the following recursive algorithms, state the recurrence equation that is the runtime of the algorithm. Briefly describe how you determined each term. You do not need to provide the runtime bound – just the equation. T(n) = Product(array, p) // n is size of array if (p>n) return 1 if (array[p] != 0) return array[p] * Product(array, p+1) else return Product(array, p+1) Describe terms: T(n) = Describe terms: // modified merge sort mod Merge(...

  • Hey, I really need help understanding the math get the answer that is given. Please help....

    Hey, I really need help understanding the math get the answer that is given. Please help. Thanks in advance. for (int k =0; k s Ign; k++) {for (int i =0; is n2; i++) Print “Hello World"; for (int j =0; j s n; j++) Print “Hello World"; } When n = 2, how many times will “Hello World” be printed?16 When n =4, how many times will “Hello World” be printed? 66 Assuming that the print is the basic...

  • Hello, I would like to get help with the following question, thanks in advance. Order the...

    Hello, I would like to get help with the following question, thanks in advance. Order the following functions according to their asymptotic growth rate.  Justify the ordering. n2 --- n! --- (lg n)! --- (3/2)n --- ln ln n --- nlg(n) --- n2n ---- ln n --- en    ---- n ---- sqrt(n) ---- 1          --- n(1/lg n) ---   ln2(n) --- 2n --- lg(n!)  

  • 4. Big-Oh and Rune time Analysis: describe the worst case running time of the following pseudocode...

    4. Big-Oh and Rune time Analysis: describe the worst case running time of the following pseudocode functions in Big-Oh notation in terms of the variable n. howing your work is not required (although showing work may allow some partial t in the case your answer is wrong-don't spend a lot of time showing your work.). You MUST choose your answer from the following (not given in any particular order), each of which could be re-used (could be the answer for...

  • pleas answer asap 3. (20 points) Algorithm Analysis and Recurrence There is a mystery function called Mystery(n) and the pseudocode of the algorithm own as below. Assume that n 3* for some positiv...

    pleas answer asap 3. (20 points) Algorithm Analysis and Recurrence There is a mystery function called Mystery(n) and the pseudocode of the algorithm own as below. Assume that n 3* for some positive integer k21. Mystery (n) if n<4 3 for i1 to 9 5 for i-1 to n 2 return 1 Mystery (n/3) Print "hello" 6 (1) (5 points) Please analyze the worst-case asymptotic execution time of this algorithm. Express the execution time as a function of the input...

  • Hello, i need help finding the time complexity(big0) for n..(java) a) for (int a = 0;...

    Hello, i need help finding the time complexity(big0) for n..(java) a) for (int a = 0; a < n; a = a + C) for (int b = 0; b < 10; b++) s[a] += b * s[a]; b) for (int a = 1; a < n; a = a * C) for (int j = 0; j < a; j++)    s[a] += j * s[a]; c)               for (int i = 1; i < n; i...

  • Need some help with finding the runtime of these java functions in the form of exact,...

    Need some help with finding the runtime of these java functions in the form of exact, tilde and big oh notation: Example of how: Func Exact Tilde O() Example 1 1 ~1 O(1) Example 2 2n+1 ~2n O(2n) Here are the functions: void funcA(int n) {         step();         for (int i = 0; i < n; i++) {             funcA(n-1);         }     }     void funcB(int n) {         step();         if (n > 0)             funcB(n-1);    ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT