Question

Question 4.5 Consider the fragment in Algorithm 4.8 shown below. Algorithm 4.8 sum = 0; for...

Question 4.5 Consider the fragment in Algorithm 4.8 shown below.
Algorithm 4.8

sum = 0;
for (i =1; i <=f(n); i ++)
sum += i;

Here f(n) is a function call. Give a simple and tight Big-Oh upper bound on the
running time of Algorithm 4.8, as a function of n, on the assumption that

(a) the running time of f(n) is O(n), and the value of f(n) is n!.
(b) the running time of f(n) is O(n), and the value of f(n) is n.
(c) the running time of f(n) is O(n2), and the value of f(n) is n.
(d) the running time of f(n) is O(1), and the value of f(n) is 0.

Homework Answers

Answer #1

(a)
the running time of f(n) is O(n), and the value of f(n) is n!.
tight Big-Oh upper bound on the running time of Algorithm 4.8 is O(n!)

(b)
the running time of f(n) is O(n), and the value of f(n) is n.
tight Big-Oh upper bound on the running time of Algorithm 4.8 is O(n)

(c)
the running time of f(n) is O(n2), and the value of f(n) is n.
tight Big-Oh upper bound on the running time of Algorithm 4.8 is O(n^2)

(d)
the running time of f(n) is O(1), and the value of f(n) is 0.
tight Big-Oh upper bound on the running time of Algorithm 4.8 is O(1)
Know the answer?
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
Similar Questions
1.) the following code fragments give running time analysis (Big Oh). Explain your answer: sum2 =...
1.) the following code fragments give running time analysis (Big Oh). Explain your answer: sum2 = 0; sum5 = 0; for(i=1; i<=n/2; i++) { sum2 = sum + 2; } for(j=1; j<=n*n; j++) { sum5 = sum + 5; } i think it is O(n^2) since big oh finds the order of worst case which is the the second loop being n^2 complexity. but im not sure. 2.) Give an efficient algorithm along with running time analysis to find the...
Problem 1. (1 point) The SolEc algorithm shown below is used with a = 0, b...
Problem 1. (1 point) The SolEc algorithm shown below is used with a = 0, b = 2 and n = 3. What is the value of c on the line Write c? Function z <- f (x) z = 85−99x + 15x2 − x3; End Function algorithm SolEc Read a, b, n; For i From 1 To n Do c = (a + b) / 2; Write a, ",", c, ",", b; If f (a) * f (c) <0...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm that is executed most frequently. Express the number of times it is executed as a function of N. Convert this expression into the Big-O notation. A. For each of the three fragments of code, what is its worst-case time complexity, in the form "O(…)". (Use the given solution to the first problem as a model)                 //----------------- This is a sample problem – solved ------...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
The following algorithm finds the initial substring of y that can be reversed and found in...
The following algorithm finds the initial substring of y that can be reversed and found in y. For example, longestInitialReverseSubstringLength(“aabaa”) = 5, because “aabaa” is the same string forwards and backwards, so the longest initial substring that can be reversed and found in the string is “aabaa”. Also, longestInitialReverseSubstringLength(“bbbbababbabbbbb”) is 6, because “babbbb” can be found in the string (see color-highlighted portions of the string), but no longer initial string exists reversed in any part of the string. longestInitialReverseSubstringLength(String y)...
public int linearSearch2(ArrayList<Integer> pList, Integer pKey) { for (int i = 0; i <= pList.size() /...
public int linearSearch2(ArrayList<Integer> pList, Integer pKey) { for (int i = 0; i <= pList.size() / 2; ++i) { if (pList.get(i).equals(pKey)) { return i; } else if (pList.get(pList.size() - 1 - i).equals(pKey)) { return pList.size() - 1 - i; } } return -1; } ----- Q1)Which function f(n) counts how many times the key operation(s) is(are) performed as a function of the list size n when pKey is not in pList (the worst case behavior of linearSearch2() occurs when pKey...
Divide-and-Conquer technique is famous for providing O(n log n) solutions for problems with O(n2) straight forward...
Divide-and-Conquer technique is famous for providing O(n log n) solutions for problems with O(n2) straight forward solutions. One of those problems is the “Maximum Subarray Sum” or “Maximum Value Contiguous Subsequence": Given a sequence of n numbers A[0 ... n-1], give an algorithm for finding a contiguous subsequence A[i ... j], for which the sum of elements in this subsequence is the maximum we can get by choosing different i or j.   For example: the maximum subarray sum for the...
1.Let f and g be two functions such that f(n)/g(n) converges to a positive value less...
1.Let f and g be two functions such that f(n)/g(n) converges to a positive value less than 1 as n tends to infinity. Which of the following is necessarily true? Select one: a. g(n)=Ω(f(n)) b. f(n)=Ω(g(n)) c. f(n)=O(g(n)) d. g(n)=O(f(n)) e. All of the answers 2. If T(n)=n+23 log(2n) where the base of the log is 2, then which of the following is true: Select one: a. T(n)=θ(n^2) b. T(n)=θ(n) c. T(n)=θ(n^3) d. T(n)=θ(3^n) 3. Let f and g be...
Match the descriptions below with the correct answer, using the letter codes shown in the table...
Match the descriptions below with the correct answer, using the letter codes shown in the table below. (8 points) A. Realizable value B. Percentage of receivables method C. 1/10, n/60 D. FOB shipping point E. Aging of receivables F. Direct write-off method G. Operating cycle H. Specific identification method I. Bad debt Expense J. Percentage of sales method K. Permanent accounts L. 2/10, EOM M. Time period assumption N. n/10 EOM O. 2/10, n/30 P. FOB destination Please Solve As...
You're are working on n different projects, but in m hours you are going on vacation....
You're are working on n different projects, but in m hours you are going on vacation. Imagine that for each project i, you had a function fi that told you how happy the people paying for project i would be if out your m available hours you devoted 0 ≤ x ≤ m to project i. Imagine further that each such function has maximum value at most s, corresponding to the project being fully finished (and thus the clients being...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT