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....
-
Certain springs are characterized by decreasing stiffness with increasing deformation according to the relation F = k1x ?? k2x3 , where F is the force exerted by the spring, 1 k and 2 k are positive...
-
An experiment called for 4.83 L of sulfur dioxide, SO 2 , at 0C and 1.00 atm. What would be the volume of this gas at 29C and 1.00 atm?
-
A capital investment project involves the purchase of a 3-D soldering station for $\$ 15,000$, producing an annual net benefit of $\$ 2,250$. The system has an 8-year useful life with a salvage value...
-
Stein Books Inc. sold 1,900 finance textbooks for $250 each to High Tuition University in 2013. These books cost $210 to produce. Stein Books spent $12,200 (selling expense) to convince the...
-
You have purchased one call and one put option on the same underlying stock. The strike price of the call option is 195 SEK and the strike price of the put option is 205 SEK. a)What is the minimum...
-
Can someone please summarize the case study below: if you know about the case IKEA Looks to Further Penetrate the U.S. Market 10 CASE Synopsis: IKEA is known around the world for its stylish,...
-
Lack of play is a factor that can hinder a child's early development. Provide two aspects that hinder a child's early development, and Provide two impacts on a child's early development if the factor...
-
Stephen Glass (Hayden Christensen) is a 24-year-old writer who takes great pride in working for the New Republic because it is read by policymakers in Washington, D.C. He plays to people's needs in...
-
James has been working closely with a new supplier in India to produce products for the U.S. market. James has offered several suggestions to improve the efficiency of the assembly line, but every...
-
To what extent should technology and news media companies be responsible for monitoring and preventing the spread of fake and to what extent is the consumer responsible? Who is responsible and why?
-
Sarah wants to use her resume for three different purposes: she wants to be able to submit it to recruiters in printed form, she wants recruiters to be able to transfer it easily to a company's 6...
-
After his graduation from Harvard Law School, James B. Donovan (1916-1970) served as a commander in the Navy and associate prosecutor at the Nuremberg trials of Nazi war criminals. Subsequently, he...
-
What will be the cell potential for a Cu?Zn galvanic cell with[Zn2+]=0.1 M and the [Cu2+]=0.01 M? What will be the cell potential for a galvanic cellwith and the ? A) 1.10 V b) 1.13 V c) 1.04 V d)...
-
What are current assets and current liabilities? How are they different from non-current assets and non-current liabilities?
-
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...
-
You shoot a beam of electrons through a double slit to make an interference pattern. After noting the properties of the pattern, you then double the speed of the electrons. What effect would this...
-
How many photons does a \(5.0 \mathrm{~mW}\) helium-neon laser \((\lambda=633 \mathrm{~nm})\) emit in 1 second? A. \(1.2 \times 10^{19}\) B. \(4.0 \times 10^{18}\) C. \(8.0 \times 10^{16}\) D. \(1.6...
-
Light consisting of \(2.7 \mathrm{eV}\) photons is incident on a piece of potassium, which has a work function of \(2.3 \mathrm{eV}\). What is the maximum kinetic energy of the ejected electrons? A....
Study smarter with the SolutionInn App