Question

5. Calculate the worst-case scenario runtime for int P(int al, int low, int high) int t; int lo = (low <= high)?(low): (high)

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

The variable lo will contain the shorter value among the low and high.

for example if low=2 and high=100

then lo will have the value 2.

now, high will contain the highest value among low and high because the shorter of them is being subtracted from the sum of the two values.

The for loop will always execute hi-lo times and we know that 'n' is the length between the high and low values.

therefore,

the time complexity of the above code will be O(n).

Add a comment
Know the answer?
Add Answer to:
5. Calculate the worst-case scenario runtime for int P(int al, int low, int high) int t;...
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
  • 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 :=...

  • QUESTION 5 What is the worst-case complexity of line 10 of function bar? A. O(1) B....

    QUESTION 5 What is the worst-case complexity of line 10 of function bar? A. O(1) B. O(N) C. O(i) D. O(log N) E. O(sqrt N) F. O(A[i]) G. O(N sqrt N) H. O(N log N) I. O(N^2) J. O(i^2) K. None of the above QUESTION 6 What is the worst-case complexity of lines 8-11 of function bar? A. O(1) B. O(N) C. O(i) D. O(log N) E. O(sqrt N) F. O(A[i]) G. O(N sqrt N) H. O(N log N) I....

  • QUESTION 8 What is the worst-case complexity of line 7 of function bar? A. O(1) B....

    QUESTION 8 What is the worst-case complexity of line 7 of function bar? A. O(1) B. O(N) C. O(i) D. O(log N) E. O(sqrt N) F. O(A[i]) G. O(N sqrt N) H. O(N log N) I. O(N^2) J. O(i^2) K. None of the above QUESTION 9 What is the worst-case complexity of lines 6-11 of function bar? A. O(1) B. O(N) C. O(i) D. O(log N) E. O(sqrt N) F. O(A[i]) G. O(N sqrt N) H. O(N log N) I....

  • Refer to the following program sample to answer the parts (a-i) below. Keep in mind that low and high are both indices of array A. /1 Assume that A is a sorted array containing N integers // Assume t...

    Refer to the following program sample to answer the parts (a-i) below. Keep in mind that low and high are both indices of array A. /1 Assume that A is a sorted array containing N integers // Assume that x is a variable of type int int low= 0; // Line 1 int high- N; // Line 2 while (low- high) I/ Line 3 m- (lowthigh)/2; // Line 4 (This is integer division) if (A [m]<) I/Line 5 then low-...

  • I only need help with question 5! Thank you! Question 4 4 pts Consider this variant...

    I only need help with question 5! Thank you! Question 4 4 pts Consider this variant of the linear search algorithm which attempts to speed up the search by reducing the number of iterations of the for loop by approximately one-half. During each pass of the loop, the algorithm performs two comparisons rather than one comparison as in linear Search(). The two comparisons compare the elements at indices i and pList size() - 1-i to pKey for equality. If a...

  • Here is the code I made, but the test case is not working, it goes wrong...

    Here is the code I made, but the test case is not working, it goes wrong when the binary string convert to decimal. please help. #include "stdafx.h" #include <iostream> #include <string> #include <math.h> #include <locale> using namespace std; // function for option 1 void decToBin(int number) {        int array[16];        int i = 0;        for (int counter = 0; counter < 16; counter++)        {               array[counter] = 0;        }        while (number > 0)        {...

  • please help with the operator overloading lab (intArray) in c++ will provide what it is being...

    please help with the operator overloading lab (intArray) in c++ will provide what it is being required and the code that was given from the book. the code that was provided is below ------------------------------------------------------------------------------------------------------------------------- // iadrv.h #ifndef _IADRV_H #define _IADRV_H #include "intarray.h" int main(); void test1(); void test2(); void test3(); void test4(); void test5(); void test6(); void test7(); void test8(); void test9(); void test10(); void test11(); void test12(); void test13(); void test14(); void test15(); void test16(); void test17(); void test18();...

  • does anyone know what High and low group means in this context? i really do not...

    does anyone know what High and low group means in this context? i really do not understand this article so anyone that does please explain it to me and what the hugh and low group mean in the figures. Received: 21 November 2018 Revised: 27 February 2019 Accepted: 6 March 2019 DOE: 10.1002p28546 ORIGINAL RESEARCnes-highdearee of intra modole connecHvity WILEYa Phypliology ARTICLE Four novel biomarkers for bladder cancer identified by weighted gene coexpression network analysis Zi-Xin Guo | Xiao-Ping Liu...

  • please complete the entire case study pertaining to cirrhosis and nursing, thank you. 3 Cirrhosis John...

    please complete the entire case study pertaining to cirrhosis and nursing, thank you. 3 Cirrhosis John Richards, 45 years old Primary Concept Nutrition Interrelated Concepts (In order of emphasis) I. Fluid and Electrolyte Balance 2. Perfusion 3. Cognition 4. Addiction 5. Clinical Judgment 6. Patient Education 7. Communication 8.Collaboration O 2016 Keith Rischer/www.KeithRN.com UNFOLDING Reasoning Case Study: STUDENT History of Present Problem: John Richards is a 4S year-old male who Cirrhosis presents to the emergency department (ED) with abdominal pain...

  • All of the following questions are in relation to the following journal article which is available...

    All of the following questions are in relation to the following journal article which is available on Moodle: Parr CL, Magnus MC, Karlstad O, Holvik K, Lund-Blix NA, Jaugen M, et al. Vitamin A and D intake in pregnancy, infant supplementation and asthma development: the Norwegian Mother and Child Cohort. Am J Clin Nutr 2018:107:789-798 QUESTIONS: 1. State one hypothesis the author's proposed in the manuscript. 2. There is previous research that shows that adequate Vitamin A intake is required...

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