Question

1. Order following function by growth rate: N, √N, N1.5, N log (N), log (log (N)),...

1. Order following function by growth rate: N, √N, N1.5, N log (N), log (log (N)), log (N) log (N), N2, 2N, 200, NN

2. Give a useful Θ (big Theta) estimation for each of following function t(n).

a. t(n) = 122 * 212

b. t(n) = 2log2(n2) + log4(n ) + (log2 n) 2 + (log2 (202)) 2

c. t(n) = 3t(n/2) + n

d. t(n) = 3t(n/2) + (n+1)(n-1)

e. t(n) = 4t(n/2) + (n2 + n-1)

f. t(n) is the runtime of following function,

public static int f1(int n){

int mid = n/2;

for (int i = mid; i >= 0; i--) System.out.println(i);

for (int i = mid + 1; i <= n; i++) System.out.println(i); return mid;

}

g. t(n) is the runtime of following function, public static int f2(int n){

if (n < 1) return 1; //update from original int mid = n/2;

mid = f2(mid);

for (int i = 30; i > 0; i /= 3){

System.out.println(i );

}

return mid; }

h. t(n) is the runtime of following function, public static int f3(int n){

for (int i = n; i >= 0; i--){

for (int j = 0, j <= i + i; j++)

for (int k = n; k > 0; k /= 3) System.out.println(i * j + k);

}

return n;

}

i. t(n) is the runtime of following function,

public static int f4(int [] a, int start, int end){

int ans = 0;

if (start >= end) ans = a[start]; else {

int mid = (start + end) / 2;

int x = f4(a, start, mid);

int y = f4(a, mid + 1, end);

print(a, start, end); //print each element in a from start to end if (x < y) ans = x;

else ans = y;

}

return ans;

}

public static void print(int [] a, int s, int e){

for (int i = s; i <= e; i++) System.out.println(i); }

j. t(n) the run time of the following method: The method removeLast for a doubly linked list that has size n

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

1. 200 < O(log(log n )) < O(logn) < O(log n log n) <O(√n )< O(n) < O(1.5N) < O(2N) < O(nlog n)< O(N2) < O(NN)

While for some cases 200 would not be the least but constant complexity algorithm is always preferred over those which depends on N(number of elements)

2. a)An algorithm is said to be constant time (also written as O(1) time) if the value of T(n) is bounded by a value that does not depend on the size of the input(N)

Hence t(n) = Θ(1)

2.b) t(n) = 2log2(n2) + log4(n ) + (log2 n) 2 + (log2 (202)) 2

T(n)=Θ (log n2) ,since 2log 2 (n2) would be the greatest degree in above expression.

2.c)t(n) = 3t(n/2) + n

T(n)= Θ(n) ,since highest power of n Above is 1.

2.d)t(n) = 3t(n/2) + (n+1)(n-1)

Highest power here is n 2 as (n+1)(n-1) gives us n^2 -1

T(n)= Θ(n 2 )

2.e)

t(n) = 4t(n/2) + (n2 + n-1)

Although highest power is n^2 but time dependent highest power is n in term 4t(n/2) ,hence time complexity

T(n)=Θ(n^2)

"As per Chegg Q&A Guidelines expert must answer first four sub-parts in case of a multiple sub-part question or only the first question".

I have solved entire 1st question and five sub-parts of second question,if you want us to help you with other sub-parts as well,please repost the questions specifying those sub-parts only.

Please up-vote if you find this answer helpful !!

Add a comment
Know the answer?
Add Answer to:
1. Order following function by growth rate: N, √N, N1.5, N log (N), log (log (N)),...
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
  • 1. t(n) is the runtime of following function, public static int f4(int [] a, int start,...

    1. t(n) is the runtime of following function, public static int f4(int [] a, int start, int end){ int ans = 0; if (start >= end) ans = a[start]; else { int mid = (start + end) / 2; int x = f4(a, start, mid); int y = f4(a, mid + 1, end); print(a, start, end); //print each element in a from start to end if (x < y) ans = x; else ans = y; } return ans; }...

  • What is the runtime of each method? Give answer in Θ(big Theta) notation as a function...

    What is the runtime of each method? Give answer in Θ(big Theta) notation as a function of n, give a brief explanation. A. public static int method1(int n){ int mid = n/2; for (int i = mid; i >= 0; i--) System.out.println(i); for (int i = mid + 1; i <= n; i++) System.out.println(i); return mid; } B. public static int method2(int n){ for (int i = n; i >= 0; i / 3){ System.out.println(i ); } return mid; }...

  • Select all the valid asymptotic runtime bounds for the following function f2 in the worst case:...

    Select all the valid asymptotic runtime bounds for the following function f2 in the worst case: public static int f1 (int n) { int x = 0; for (int i = 0; i < n; i++) { x++; } return x; } public static int f2 (int n) { if (n <= 1) { return 1; } return f1(n) + f2(n/2) + f2(n/2); } Θ(n^2) O(n^2) Θ(log(n)) Θ(log^2(n)) Θ(nlog(n)) Ω(n) Ω(n^2)

  • use the same code. but the code needs some modifications. so use this same code and...

    use the same code. but the code needs some modifications. so use this same code and modify it and provide a output Java Program to Implement Merge Sort import java.util.Scanner Class MergeSort public class MergeSort Merge Sort function / public static yoid sortfintfl a, int low, int high) int N-high-low; if (N1) return; int mid- low +N/2; Il recursively sort sort(a, low, mid); sort(a, mid, high); I/ merge two sorted subarrays int] temp new int[N]; int i- low, j-mid; for...

  • 3. Recursive Program (6 points) Consider the following recursive function for n 1: Algorithm 1 int...

    3. Recursive Program (6 points) Consider the following recursive function for n 1: Algorithm 1 int recurseFunc(int n) If n 0, return 1. If n 1, return 1 while i< n do while j <n do print("hi") j 1 end while i i 1 end while int a recurse Func(n/9); int b recurse Func (n/9) int c recurse Func (n/9) return a b c (1) Set up a runtime recurrence for the runtime T n) of this algorithm. (2) Solve...

  • I have a multithreaded java sorting program that works as follows: 1. A list of double...

    I have a multithreaded java sorting program that works as follows: 1. A list of double values is divided into two smaller lists of equal size 2. Two separate threads (which we will term sorting threads) sort each sublist using a sorting algorithm of your choice 3. The two sublists are then merged by a third thread merging thread that merges the two sublists into a single sorted list. SIMPLE EXECUTION >java SortParallel 1000 Sorting is done in 8.172561ms when...

  • Which big-O expression best characterizes the worst case time complexity of the following code? public static...

    Which big-O expression best characterizes the worst case time complexity of the following code? public static int foo(int N) ( int count = 0; int i1; while (i <N) C for (int j = 1; j < N; j=j+2) { count++ i=i+2; return count; A. O(log log N) B. O(log N2) C. O(N log N) D. O(N2)

  • 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...

  • What are the valid runtime bounds for the method mystery with respect to argument n? Select...

    What are the valid runtime bounds for the method mystery with respect to argument n? Select all that apply. public static int mystery(int n) { for (int i = 1; i < n; i = i + i) { for (int j = 0; j < i; j++) { for (int k = 0; k < n; k++) { f0(n); } } } return -1; } public static void f0(int n) { int[] arr = new int[200]; for (int i...

  • 8.         R-4.8 Order the following functions by asymptotic growth rate. 4nlogn + 2n 2^10    2^logn 3n...

    8.         R-4.8 Order the following functions by asymptotic growth rate. 4nlogn + 2n 2^10    2^logn 3n + 100logn      4n     2^n n^2 + 10n        n^3       nlogn 9.         R-4.9 Give a big-Oh characterization, in terms of n, of the running time of the example 1 method shown in Code Fragment 4.12. 10.       R-4.10 Give a big-Oh characterization, in terms of n, of the running time of the example 2 method shown in Code Fragment 4.12. 11.       R-4.11 Give a big-Oh characterization, in...

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