2. A list of n distinct integers a1, a2,..., an is called a mountain list if...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2. A list of n distinct integers a1, a2,..., an is called a mountain list if the elements reading from left to right first increase and then decrease. The location of the peak is the value i where a; is greatest. For example, the list 1, 2, 3, 7, 6 is a mountain list with a peak at 4 since the greatest number occurs in the fourth position. We also consider a list of n increasing numbers to be a mountain list with a peak at n, and a list of n decreasing numbers to be a mountain list with a peak at 1. (a) Give pseudocode for an algorithm based on linear search that takes as input a mountain list a1, a2,,an and returns the location of the peak. procedure LinearPeak(a1, a2,..., an: mountain list) 1. for 1 ton-1 2. if 3. return i 4. return n (b) (5 points) Give an algorithm based on binary search that takes as input a mountain list a1, a2,..., an and returns the location of the peak. procedure BinaryPeak (a1, a2, ..., an: mountain list) 1. i = 1 2. 3. 4. j = n while (i < j) m == [i+1] 5. if 6. i = m +1 7. else 8. j := m 9. return i 2. A list of n distinct integers a1, a2,..., an is called a mountain list if the elements reading from left to right first increase and then decrease. The location of the peak is the value i where a; is greatest. For example, the list 1, 2, 3, 7, 6 is a mountain list with a peak at 4 since the greatest number occurs in the fourth position. We also consider a list of n increasing numbers to be a mountain list with a peak at n, and a list of n decreasing numbers to be a mountain list with a peak at 1. (a) Give pseudocode for an algorithm based on linear search that takes as input a mountain list a1, a2,,an and returns the location of the peak. procedure LinearPeak(a1, a2,..., an: mountain list) 1. for 1 ton-1 2. if 3. return i 4. return n (b) (5 points) Give an algorithm based on binary search that takes as input a mountain list a1, a2,..., an and returns the location of the peak. procedure BinaryPeak (a1, a2, ..., an: mountain list) 1. i = 1 2. 3. 4. j = n while (i < j) m == [i+1] 5. if 6. i = m +1 7. else 8. j := m 9. return i
Expert Answer:
Answer rating: 100% (QA)
a Linear search will be searching max element so procedure will be procedure Linear... View the full answer
Related Book For
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall
Posted Date:
Students also viewed these programming questions
-
Let r and s be solutions to the quadratic equation x 2 b x + c = 0. For n N, define d0 = 0 d1 = r s dn = b dn1 c dn2 (n 2) Prove that dn = r n s n for all n N. [4 marks] (b) Recall that a commutative...
-
In this question assume that p and q are atomic formulae. (a) Compare and contrast path formulae and state formulae in temporal logic. [4 marks] (b) Describe and contrast the meanings of F(G p) and...
-
2. C. b. d. e. a. A proposed public project would produce the following pattern of individual benefits and costs. Revise only the cost shares of individuals C and E to meet the Pareto Criterion. (7...
-
Explain why, when a company uses FIFO with a periodic inventory system, the cost of goods sold and ending inventory costs are the same as they would be had FIFO been used with a perpetual system.
-
Sue T. is a nurse manager for medical-surgical units at a hospital. She is enrolled in a nursing master's degree program at the local university. As part of the requirements for a Nursing Management...
-
1. Identify an entrepreneur in your area you would like to interview. 2. Contact the person you have selected and make an appointment. Be sure to explain why you want the appointment and to give a...
-
Fenton Company applied FIFO to its inventory and got the following results for its ending inventory . Cameras 100 units at a cost per unit of ....... $68 DVD players 150 units at a cost per unit of...
-
Solve the following DES. a) y (4) - (3) -3y"+5y'-2y=0
-
? Dean and Ellen Price are married and have a manufacturing business. They bought a piece of business equipment (7-year personal property) on 4/1/2017 for $50,000. Use half-year convention to...
-
Mention some applications of linked list and give a real life example where used linked list.
-
9 ( + + + ) ( - 23/0 ) dr. .10 du Identify u and dx for the integral
-
4. Consider the model of cleaning an apartment in Appendix A.2.3. Suppose the government offers a subsidy, o, for each unit of effort by each person. So 0x Si. if person i chooses efforts, she...
-
Discuss the impact that freight movement has on the environmental and financial sustainability of a supply chain. Considering how congestion can affect the effectiveness of a company's supply chain,...
-
Calculate Shark's taxable income (Shark did not have any other income or deductions) Assessable Income "Receipt Amount $" "Workings (show clearly)" "Enter Claimable amount $ " Share of Partnership...
-
Use the information given below to calculate each of the following independently: 3.1 Expected total Marginal Income and Net Profit/Loss 3.2 Margin of safety (as a percentage; expressed to two...
-
5a. Do you think that Bcl-x response in lymphoid cells is different from myeloid cells? Write a conclusion statement answering the question and an evidence statement providing your reasoning. Please...
-
Using Apple, demonstrate how the differentiation strategy can be well implemented.
-
Its hard to focus on what we want to achieve. I look at what our real competitors, the convenience stores, are doing and think we should copy that. Then a hundred customers come in, and I listen to...
-
What is the advantage of using structured English to communicate with people in the organization?
-
List the three entity constraints. In a sentence, describe the meaning of each entity constraint.
-
Discuss four important risk and tax-related considerations that are relevant to Omos portfolio. With most of Omos personal net worth tied up in his software company, he is asset rich but cash poor....
-
Determine the most appropriate strategy that can generate liquidity and accomplish Omos goals. Justify your response. Jing asks Omo about his plans for the shares of his previous employers company....
-
Recommend, for both Enlows niece and nephew, the most tax-efficient wealth transfer option (lifetime gift or testamentary bequest). Show your calculations. Recommend, for both Enlow's niece and...
Study smarter with the SolutionInn App