Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Give a useful (big Theta) estimation for each of the following functions t(n). a. t(n) is the runtime of following function, public static int

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

a. 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;

}

b. 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; }

c. 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;

}

d. 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); }

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

Step by Step Solution

3.44 Rating (160 Votes )

There are 3 Steps involved in it

Step: 1

a Since the two loops are not independent Therefore it is of the highest for it to count ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

College Algebra Graphs and Models

Authors: Marvin L. Bittinger, Judith A. Beecher, David J. Ellenbogen, Judith A. Penna

5th edition

321845404, 978-0321791009, 321791002, 978-0321783950, 321783956, 978-0321845405

More Books

Students also viewed these Programming questions

Question

Find the sum of the first n terms of x2 - x3 + x4 - x5 + ......

Answered: 1 week ago

Question

Find the sum. 40 (2k + 3) 43

Answered: 1 week ago

Question

State the reasons for entity clustering.

Answered: 1 week ago