Question 2. [8 points=4+41 Consider the following algorithm given in Java code: 1. boolean orderedPrefixes (String...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Question 2. [8 points=4+41 Consider the following algorithm given in Java code: 1. boolean orderedPrefixes (String s) { 2. // Input: an string S of length 3. // Output: print all sorted boolean valid-true; int nos. length(); with letters prefixes of S and return true if S is sorted 4. System.out.println(s.charAt(0)); n; i++) { for (int i 1 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. if (s.charAt(i-1)> s.charAt(i)) { d = false; break; 19. for (int j=0; j<= i; j++) System.out.print(s.charAt(j)); System.out.println(); } } return valid; } Subject to mehr Note: when giving the big-Oh, give the tightest upper bound possible. For example, if you can prove that f(n) is 0(n), and that f(n) is 0(n²), choose the tighter upper bound, i.e. f(n) is O(n). (a) (4 pts) Give a big-Oh for T(n), the worst-case running time of this algorithm for an input string of length n. Explain how you obtained this worst case. (b) (4 pts) Give a big-Oh for B(n), the best-case running time of this algorithm for an input string of length n. Explain the type of inputs (sample inputs) that will give this case. Question 2. [8 points=4+41 Consider the following algorithm given in Java code: 1. boolean orderedPrefixes (String s) { 2. // Input: an string S of length 3. // Output: print all sorted boolean valid-true; int nos. length(); with letters prefixes of S and return true if S is sorted 4. System.out.println(s.charAt(0)); n; i++) { for (int i 1 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. if (s.charAt(i-1)> s.charAt(i)) { d = false; break; 19. for (int j=0; j<= i; j++) System.out.print(s.charAt(j)); System.out.println(); } } return valid; } Subject to mehr Note: when giving the big-Oh, give the tightest upper bound possible. For example, if you can prove that f(n) is 0(n), and that f(n) is 0(n²), choose the tighter upper bound, i.e. f(n) is O(n). (a) (4 pts) Give a big-Oh for T(n), the worst-case running time of this algorithm for an input string of length n. Explain how you obtained this worst case. (b) (4 pts) Give a big-Oh for B(n), the best-case running time of this algorithm for an input string of length n. Explain the type of inputs (sample inputs) that will give this case.
Expert Answer:
Answer rating: 100% (QA)
a The worstcase running time Tn of this algorithm is On2 This occurs when the input string is in descending order which causes the inner for loop to execute the maximum number of times Specifically th... View the full answer
Related Book For
Applied Regression Analysis and Other Multivariable Methods
ISBN: 978-1285051086
5th edition
Authors: David G. Kleinbaum, Lawrence L. Kupper, Azhar Nizam, Eli S. Rosenberg
Posted Date:
Students also viewed these programming questions
-
The total liabilities of Hogan's Company on the balance sheet are $270,000; this amount is equal to three-fourths of the total assets. What is the amount of owners' equity?
-
A road building company is purchasing an excavator for $500,000. The corporate tax rate is 45% and the expected after-tax rate of return is 12%. What would be the present value of the future tax...
-
A 500 mm diameter closed-end steel pipe pile is to be driven to a depth of 17 m into the following soil profile. Depth (m) 0-2.0 2.0-6.5 6.5 16.0 16.0 17.5 Soil Classification Silty sand Fine to...
-
Argue whether or not you believe using a sample of students from your schools cafeteria (you recruit the next 100 people to visit the cafeteria to participate) may or may not yield biased estimates...
-
Consider the interconnected LANs shown in Fig. 4-44. Assume that hosts a and b are on LAN 1, c is on LAN 2, and d is on LAN 8. Initially, hash tables in all bridges are empty and the spanning tree...
-
Determine the truth value of the statement xy (xy = 1) if the domain for the variables consists of a) The nonzero real numbers. b) The nonzero integers. c) The positive real numbers.
-
The market research department of a chain of hamburger restaurants wants to compare the mean monthly sales of hamburgers under three different marketing strategies. It randomly assigns 15 restaurants...
-
Hodge Confections is known for its creamy milk chocolate fudge. Hodge sells its fudge to local retailers. A unit of fudge is a 10- pound batch. The standard quantities of ingredients for a batch...
-
You know that y is a normally distributed variable with a variance of 16. You do not know its mean. You collect some data. For each sample below, form the 90% confidence interval and test the null...
-
6.2. Data has been collected from a chemical reactor. The inlet concentration was the only input variable that changed when the data was collected. The input and output data is given in Table Q6.2....
-
If the price of a Big Mac hamburger in the US is $3.99 and the price of a Big Mac hamburger is $6.60 in Australia and the current exchange rate is $1 A = $0.76 US what does this indicate about the...
-
Description of the overall business processes impacted by the ERP system in FedEx company including comparison between the processes before and after the ERP system.(750word) Analyse each of the...
-
The 30-kg block A and the 50-kg block B connected by the weightless, frictionless pully system were released from rest. Determine their speeds when block A has displaced downwards by 0.4 m.
-
a random sample of 130 items is drawn from a population whose standard deviation is known to be o=60. The sample mean is x=70. a) Construct an interval estimate for u with 95 percent confidence....
-
Explain in your own words the different types of anesthesia, including what types of procedures each are used for.
-
In what ways does Texas try to limit the political power of the bureaucracy?
-
The nominal risk free rate is a function of the real risk free rate and the investors variance the prime rate and the rate of inflation the T-bill rate plus the inflation rate the tax free rate plus...
-
General Electric Capital, a division of General Electric, uses long-term debt extensively. In a recent year, GE Capital issued $11 billion in long-term debt to investors, then within days filed legal...
-
The manager of a market research company conducted an experiment to investigate the productivity of three employees on each of two computerized data-entry systems. The employees conducted phone...
-
The data set for this problem derives from the posture measurement study described in the main body of this chapter. Here we consider the data on shoulder flexion (SF) for 19 subjects that were each...
-
Redo Examples 27.11, 27.13, and 27.15 to determine the approximate sample size if a. The desired power is 0.9 (all other parameters are as given in the examples). b. The desired significance level is...
-
Draw and explain the class diagram for stable analysis pattern? Identify and highlight all participants and explain why they exist.
-
List some design and implementation issues faced, when implementing this pattern. Explain each issue.
-
List some differences between the analysis pattern described here and the traditional pattern.
Study smarter with the SolutionInn App