4. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
4. 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 outputs two integers: the initial and final indices of the longest subarray. (a) (4 marks) Give the algorithm pseudocode. (b) (1 mark) Justify your big-Oh (1 mark). A solution that uses extra memory that is in O(1) is worth 100%; if you use O(n) extra memory your solutions is worth 80%. Example: If n = 10 and A= [8,6,7,10,-2,4,5,6,2,5] then the algorithm outputs 4 and 7, since A[4..7] [-2, 4, 5, 6] is the longest sorted subarray. 4. 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 outputs two integers: the initial and final indices of the longest subarray. (a) (4 marks) Give the algorithm pseudocode. (b) (1 mark) Justify your big-Oh (1 mark). A solution that uses extra memory that is in O(1) is worth 100%; if you use O(n) extra memory your solutions is worth 80%. Example: If n = 10 and A= [8,6,7,10,-2,4,5,6,2,5] then the algorithm outputs 4 and 7, since A[4..7] [-2, 4, 5, 6] is the longest sorted subarray.
Expert Answer:
Answer rating: 100% (QA)
a PSEUDO CODE longestsortedsubarray size Declare MAX1 len1 i1 j0 initialpos0 finalpos1 ifarrayiarray... View the full answer
Related Book For
Algorithm Design And Applications
ISBN: 9781118335918
1st Edition
Authors: Michael T. Goodrich, Roberto Tamassia
Posted Date:
Students also viewed these programming questions
-
Determine an estimate of the blood flow rate needed to sustain a total of 750,000 islets. Each islet can be assumed to be 150 m in diameter. Given: pO2(avg) = 68mmHg basal oxygen consumption rate =...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Which of the following are valid in a Java file, listed in the order in which they are declared? (Choose two.) A. A package-private class declaration and a public interface declaration B. Two package...
-
(a) For formic acid, HCOOH, find the two stable conformers at the HF/6-31G* level; check that each conformer is a local minimum. Then find the structure of the HF/6-31G* transition state between...
-
Improv Club (IC) features entertaining improvisational theatre performances. The theatre features a range of shows and talented performers. IC prepares financial statements on an annual basis. The...
-
The annual reports of publicly traded companies describe some of the financial ratios presented in this chapter. Other ratios must be calculated using the information provided in the financial...
-
a. Construct a personal income statement for the Humperdinck family using the following information: salaries, $42,000; mortgage payment, $7,980; food, $2,400; interest income, $150; transportation,...
-
1. Buyer: Purchase of $3,250 of inventory for cash. 2. Buyer: Return of $705 of inventory to seller for credit on account. 3. Buyer: Purchase of $3,760 of inventory on account, terms 2/10, n/45. 4....
-
Univex is a calendar year, accrual basis retail business. Its financial statements provide the following information for the year: Revenues from sales of goods $ 783,200 Cost of goods sold (FIFO) ...
-
What are the primary presenting Human Resources Management problems? What strengths and weaknesses about EDS can you infer from the research? Which HR problems, if addressed, will have the largest...
-
Describe the inherent limitations of internal control.
-
Provide two examples of tests of details of balances and transactions.
-
What are the limits on the efficiency of a screw jack to be of the self-locking type?
-
Fraudulent financial reporting has been described as a function of three requirements. Describe these requirements (not the primary or secondary indicators of each requirement).
-
What matters should an auditor consider when planning an audit?
-
Explain the cash ratio with example. Why this term is useful in accounting?
-
Find the reduced echelon form of each of the matrices given in Problems 120. c 1 26 + 4
-
Give an O(n)-time algorithm for computing the depth of all the nodes of a tree T, where n is the number of nodes of T.
-
Consider the substring pattern matching problem for a length-m pattern, P, and a length-n text, T, where one of the characters in P is a symbol, ?, which is not in the alphabet for the text. This...
-
Suppose you are computer security expert working for a major company, CableClock, any you have just discovered that many of the computers at CableClock are infected with malware that must have come...
-
If a taxi service is operating in the region of diminishing marginal product and more taxi service is added in the short run, what will happen to the marginal cost of providing the additional...
-
When marginal product is increasing, a. marginal cost is increasing. b. marginal cost is decreasing. c. average variable cost is increasing. d. average total cost is increasing. e. total cost is...
-
Why are long-run costs different from short-run costs?
Study smarter with the SolutionInn App