1. Can you write the algorithmic form for the above description? example: 2. Show that your...
Fantastic news! We've Found the answer you've been seeking!
Question:
1. Can you write the algorithmic form for the above description?
example:
2. Show that your algorithm needs at most 3*n/2.
Transcribed Image Text:
In fact, we can find both the minimum and the maximum using at most 3 [n/2] comparisons. We do so by maintaining both the minimum and maximum elements seen thus far. Rather than processing each element of the input by comparing it against the current minimum and maximum, at a cost of 2 comparisons per element, 9.2 Selection in expected linear time 215 we process elements in pairs. We compare pairs of elements from the input first with each other, and then we compare the smaller with the current minimum and the larger to the current maximum, at a cost of 3 comparisons for every 2 elements. How we set up initial values for the current minimum and maximum depends on whether n is odd or even. If n is odd, we set both the minimum and maximum to the value of the first element, and then we process the rest of the elements in pairs. If n is even, we perform 1 comparison on the first 2 elements to determine the initial values of the minimum and maximum, and then process the rest of the elements in pairs as in the case for odd n. Let us analyze the total number of comparisons. If n is odd, then we perform 3 [n/2] comparisons. If n is even, we perform 1 initial comparison followed by 3(n − 2)/2 comparisons, for a total of 3n/2-2. Thus, in either case, the total number of comparisons is at most 3 [n/2]. In fact, we can find both the minimum and the maximum using at most 3 [n/2] comparisons. We do so by maintaining both the minimum and maximum elements seen thus far. Rather than processing each element of the input by comparing it against the current minimum and maximum, at a cost of 2 comparisons per element, 9.2 Selection in expected linear time 215 we process elements in pairs. We compare pairs of elements from the input first with each other, and then we compare the smaller with the current minimum and the larger to the current maximum, at a cost of 3 comparisons for every 2 elements. How we set up initial values for the current minimum and maximum depends on whether n is odd or even. If n is odd, we set both the minimum and maximum to the value of the first element, and then we process the rest of the elements in pairs. If n is even, we perform 1 comparison on the first 2 elements to determine the initial values of the minimum and maximum, and then process the rest of the elements in pairs as in the case for odd n. Let us analyze the total number of comparisons. If n is odd, then we perform 3 [n/2] comparisons. If n is even, we perform 1 initial comparison followed by 3(n − 2)/2 comparisons, for a total of 3n/2-2. Thus, in either case, the total number of comparisons is at most 3 [n/2].
Expert Answer:
Answer rating: 100% (QA)
Heres the algorithmic form of the description for finding both the minimum and maximum elements using at most 3n2 comparisons python def findminmaxarr ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these algorithms questions
-
Assume that Jones Company made a payment on a mortgage. It included $100 of principal and $150 of interest. What would the journal entry be to record the payment?
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
DTG agreed to merge with the SPQ. The total equity purchase price of $45,000 is going to be 50% financed issuing DTGs common shares and 50% financed with cash raised by DTG issuing long-term debt....
-
Fred Fisher is a licensed scuba diver who lives in Key Largo. He is employed full-time as an engineer. Five years ago he had been employed as a professional diver for a salvage company. While working...
-
Calculate (a) The molality of chloride ions in an aqueous solution of iron(III) chloride for which x FeCl 3 = 0.0312; (b) The molality of hydroxide ions in a solution prepared from 3.24 g of barium...
-
Costsave Corporation, a U'S. company, acquired Denner, a discount supermarket chain in Switzerland, on J anuary 1, 2017. Denner is a subsidiary of Costsave, and its results are consolidated with...
-
The management of Nabar Manufacturing prepared the following estimated balance sheet for June, 2013: To prepare a master budget for July, August, and September of 2013, management gathers the...
-
K Juan has 3 ties, 7 shirts, and 3 pairs of pants. How many different outfits can he wear if he chooses one tie, one shirt, and one pair of pants for each outfit? There are different outfits Juan can...
-
Prepare general journal entry. Billy Bob's Bikes Transactions Nov. 1: Billy Bob paid in advance for an 8-month insurance policy, which will begin today. He paid $3,856 cash for the policy. Nov, 1-...
-
It is May 5, 2017. The quoted price of a government bond with a 12% coupon that matures on July 27, 2024, is 110-17. Calculate the cash price of the government bond. (8 Marks)
-
What major, different market-entry strategies exist for companies that engage in international marketing, and what are the benefits and disadvantages of each method?
-
What is liquidity? How can it be measured using a classified statement of financial position?
-
In 1956 Dean Buntrock took control of Ace Scavenger, a garbage collector that was owned by his then father-in-law who had recently died. After merging Ace with several waste companies, Buntrock...
-
In what ways does the international sales environment differ from the typical sales environment in the domestic market? What additional considerations need to be made by sales managers to adapt to...
-
WorldCom evolved from a long distance telephone provider named Long Distance Discount Services (LDDS), which had annual revenues of approximately \($1.5\) billion by the end of 1993. LDDS connected...
-
Match the risk with the correct transaction ( if any ) : The DC appreciates, altering relative prices in the current account The DC depreciates, altering relative prices in the current account The DC...
-
Sundial Technologies produces and sells customized network systems in New Brunswick. The company offers a 60-day, all software and labor-and an extra 90-day, parts-only- warranty on all of its...
-
Van makes an investment in a partnership in 2012. Van's capital contributions to the partnership consisted of $30,000 cash and a building with an adjusted basis of$70,000, subject to a nonrecourse...
-
On February 2, 2012, Alexandra purchases a personal computer for her home. The computer cost $3,000. Alexandra uses the computer 80 percent of the time in her accounting business, 10 percent of the...
-
Cypress Corporation has regular taxable income of $170,000 (assume annual gross receipts are greater than $5 million) and regular tax liability of $49,550 for 2012. The corporation also has tax...
-
Master Corp. issued \(8 \%, \$ 80,000\) bonds on February 1,2020 . The bonds pay interest semiannually each July 31 and January 31 and were issued to yield \(7 \%\). The bonds mature January 31,...
-
Master Corp. issued \(5 \%, \$ 300,000\) bonds on January 1, 2020. The bonds pay cash interest semiannually each July 1 and January 1, and were issued to yield \(6 \%\). The bonds mature January...
-
For the following separate bond issues, assume that the bonds are sold on January 1, 2020, interest is paid semiannually on July 1 and December 31, and the bond term is 5 years. Required Complete the...
Study smarter with the SolutionInn App