Question

Find the worst case runtime f(n) for the following algorithms.

  • Specify the number of operations executed for an input size n, for the worst case run time as a function of n.
  • Circle statement(s) and draw a   line to the right side specifying the number of operations.
  • If statement(s) are a part of an iteration of n, specify the total number of iterations as a function of n.
  • Algorithm-01 int sum = 0; int j = 1; while ( <= n) { sum++; j-j.2; } Algorithm-02 int sum - 0; for (int i = 1; i <= n * 2; i+
0 0
Add a comment Improve this question Transcribed image text
Answer #1

# STAY HOME # STAY SAFE

The solution to the above problem is given in the attached images.Please refer.

If you have any queries please comment in the comments section and kindly upvote.

Solution- 1.2 int sum = 0; int while lean) # No of operations log(n) sum tt; to tlagn Tatab no-ofoperations. It log.com) +log3 #No of operations int sum = 0 fort int i=1; icin; i++) fortint <= 1000000; j++) 106m n asf sum += 100 106m sun to 9999 Itni4.) #No. of operations 1 int sum=0; fortint i = 1; i =n; i++) fort int jal; jc = i; ji 4 m mm له n(n+1)/2 suma sum titji n(n+Х (= (429 | + - + + + () t 41. . , . . . + 1 + + |

Add a comment
Know the answer?
Add Answer to:
Find the worst case runtime f(n) for the following algorithms. Specify the number of operations executed...
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
  • 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)

  • Show your work Count the number of operations and the big-O time complexity in the worst-case...

    Show your work Count the number of operations and the big-O time complexity in the worst-case and best-case for the following code int small for ( i n t i = 0 ; i < n ; i ++) { i f ( a [ i ] < a [ 0 ] ) { small = a [ i ] ; } } Show Work Calculate the Big-O time complexity for the following code and explain your answer by showing...

  • 5. Calculate the worst-case scenario runtime for int P(int al, int low, int high) int t;...

    5. Calculate the worst-case scenario runtime for int P(int al, int low, int high) int t; int lo = (low <= high)?(low): (high); int hi = (high + low) - lo; int i = lo - 1; int pivot = a[hi]: for(int j = 10; j < hi;j +1) if (a[j] < pivot) i += 1; t = a[i]; a[i] = a[j]; a[j] = t; t = a[i+1]; a[i+1] = a[hi]: a[hi] = t; return (i + 1); where high...

  • Need to find number of elementary expressions in terms of n, not looking for Big O...

    Need to find number of elementary expressions in terms of n, not looking for Big O complexity. 4. Work out the number of elementary operations in the worst possible case and the best possible case for the following algorithm (justify your answer): 0: function Nonsense (positive integer n) 1: it1 2: k + 2 while i<n do for j+ 1 to n do if j%5 = 0 then menin else while k <n do constant number C of elementary operations...

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

  • (10 pts.) Count the worst-case number of array element comparisons (A[j] < A[j-1]) made by InsertionSort...

    (10 pts.) Count the worst-case number of array element comparisons (A[j] < A[j-1]) made by InsertionSort on arrays of size n: void InsertionSort(int A[], int n) { for (int i = 1; i < n; ++i) for (int j = i; j > 0 && A[j] < A[j-1]; --j) swap(A[j], A[j-1]); } Do the same for the number of swap's. 2. Which function grows faster: 2^((lg?))2 or ?^(2019)? Justify your answer. 3. Use "name and conquer" to give a derivation...

  • Find the best case, worst case and average case complexity for numbers of comparison and assignment...

    Find the best case, worst case and average case complexity for numbers of comparison and assignment operations for the following code. Indicate when there is no best or worst case. Comparisons Assignments Given 2-D array of integer map[n][n]: Best: Best: worst: worst: for (i0; 1 <n; i++) for(j = 0j <n; j++) If (map 10] < 0) map[001-mapli01: average: average: For ease of analysis, assume half of the elements in map are negative.

  • Exercise 7.3.5: Worst-case time complexity - mystery algorithm. The algorithm below makes some changes to an...

    Exercise 7.3.5: Worst-case time complexity - mystery algorithm. The algorithm below makes some changes to an input sequence of numbers. MysteryAlgorithm Input: a1, a2....,an n, the length of the sequence. p, a number Output: ?? i != 1 j:=n While (i < j) While (i <j and a < p) i:= i + 1 End-while While (i <j and a 2 p) j:=j-1 End-while If (i < j), swap a, and a End-while Return( aj, a2,...,an) (a) Describe in English...

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

  • what’s T(n) of the QuickSort algorithm in (1) the best case, (2) the worst case and...

    what’s T(n) of the QuickSort algorithm in (1) the best case, (2) the worst case and (3) the case where the partition() algorithm always splits the input array with a 40:60 ratio (i.e., 40% of data goes in one partition and the remaining 60% the other)? algorithm quicksort(A, lo, hi) if lo < hi then p := partition(A, lo, hi) quicksort(A, lo, p - 1 ) quicksort(A, p + 1, hi) algorithm partition(A, lo, hi) pivot := A[hi] i :=...

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