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
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...
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)...
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...
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...
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. Bad debt Expense E. Aging of receivables F. Direct write-off method G. Operating cycle H. Specific identification method I. FOB shipping point J. Time period assumption K. n/10 EOM L. Percentage of sales method M. Permanent accounts N. 2/10, EOM O. 2/10, n/30 P. FOB destination The economic life...
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.      3/10, n/60 D.    Bad debt Expense E.      Aging of receivables F.      Allowance method G.     Operating cycle H.     Specific identification method I.        FOB shipping point J.        Time period assumption K.    n/10 EOM L.    Percentage of sales method M.   Permanent accounts N.    2/10, EOM O.    2/10, n/30 P.     FOB destination Credit terms that allow...
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the...
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the values for hours, minutes and seconds are a legal military time (i.e. 00 00 00 to 23 59 59) the program should display the formatted results (i.e. 12 34 56 should be displayed as 12:34:56). If there's an error for any of the entered values, an exception should be thrown and an error message should be displayed. Note, there are three exception conditions, one...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT