Given an array of unsorted integers, find the maximum product of two integers in an array....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Given an array of unsorted integers, find the maximum product of two integers in an array. For example, if the arr = [10, 8, -1, 7, 14] then the maximum product would be 140, as output of (10 x 14). To solve this problem, the following idea can be used: a) Design a brute-force algorithm to solve this problem using a Pseudocode and find its complexity. (4+3 marks) b) Another solution would be "Sort the array first, and then to get the product of its highest two integers". Is this idea better that the first one? Explain why? (2+4 marks) c) Is there any extreme case that should be considered while designing your algorithm? Justify your answer. (6 marks) d) Design your own idea to solve this problem in O(n) complexity, where n is the size of the array. [note: your idea should be explained in simple English, and then transformed into algorithm (pseudocode)]. (6 marks) Given an array of unsorted integers, find the maximum product of two integers in an array. For example, if the arr = [10, 8, -1, 7, 14] then the maximum product would be 140, as output of (10 x 14). To solve this problem, the following idea can be used: a) Design a brute-force algorithm to solve this problem using a Pseudocode and find its complexity. (4+3 marks) b) Another solution would be "Sort the array first, and then to get the product of its highest two integers". Is this idea better that the first one? Explain why? (2+4 marks) c) Is there any extreme case that should be considered while designing your algorithm? Justify your answer. (6 marks) d) Design your own idea to solve this problem in O(n) complexity, where n is the size of the array. [note: your idea should be explained in simple English, and then transformed into algorithm (pseudocode)]. (6 marks)
Expert Answer:
Answer rating: 100% (QA)
a Bruteforce algorithm pseudocode maxProductarr maxProd INFINITY n arrlength for i from 0 to n1 for ... View the full answer
Related Book For
Venture capital and the finance of innovation
ISBN: 978-0470454701
2nd Edition
Authors: Andrew Metrick
Posted Date:
Students also viewed these programming questions
-
200 kg Speed 10.5 m/s Acceleration: 0.64 m/s -20 50 kg 0 20 Sum of Forces 41N Friction Force 94N -500 50 kg Forces Sum of Forces Values Masses Speed Acceleration Friction None Lots Applied Force 135N...
-
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...
-
Portray in words what transforms you would have to make to your execution to some degree (a) to accomplish this and remark on the benefits and detriments of this thought.You are approached to compose...
-
(a) A circular diaphragm 60 cm in diameter oscillates at a frequency of 25 kHz as an underwater source of sound used for submarine detection. Far from the source, the sound intensity is distributed...
-
ABC Corporation is authorized to issue 50,000 shares of $50 par value, 8% cumulative, participating preferred stock and 750,000 shares of $5 par value common stock. Please prepare journal entries to...
-
What is the typical size of the security staff in a small organization? A medium sized organization? A large organization? A very large organization?
-
Anston Industries is the manufacturing division of a large multinational. The divisional general manager is about to purchase new equipment for the manufacture of a new product. He can buy either the...
-
Chelsea Bush is an emerging candidate for her partys nomination for President of the United States. She now is considering whether to run in the high-stakes Super Tuesday primaries. If she enters the...
-
4. Suppose the vapor pressure of pure water at the temperature of your experiment (e.g., 25C) is 3 kPa and the water activity of your sample is 0.85. What is the vapor pressure of water in the...
-
Exercise 6.1 Configuring Memory on Paper Objective: a computer is not performing as well as it used to. Windows 10 tool would the technician get the user to open to quickly tell how much RAM is...
-
4. Partner Company acquired 85% of the common stock of Simplex Company in two separate cash transactions. The first purchase of 108,000 shares (60%) on January 1, 2015, cost $735,000. The second...
-
Laura invested $ 6 5 0 at the end of every month in an investment fund that was earning interest at a rate of 4 . 4 4 % compounded monthly. She stopped making regular deposits at the end of 5 years...
-
Sales for Furthur Bus Company are shown in the table below. wwwwww Sales November December January February March $9,500 $10,000 $11,000 $12,100 $13,310 All sales are for credit, with 80% collected...
-
Indiana Bones Company produces and sells 2,000 units of a single product, a deluxe dog house. Selling price per unit Variable cost per unit Annual fixed cost $2,000 $1,000 $500,000 By how much will...
-
c) Four point charges are arranged as shown in the figure. Show the direction of net electric field at point P? +99 D P d +90 (1)
-
On September 1, Year 1, Lewis Company sells inventory costing $133,515 for $310,500. The sales agreement states that the buyer will pay $27,000 down and 21 equal monthly installment payments, with...
-
For each of the following transactions, indicate whether operating (O), investing (I), or financing activities (F), or none of the activities (NE) are affected and whether the effect is a cash inflow...
-
Find the equations of the ellipses satisfying the given conditions. The center of each is at the origin. Passes through (2, 2) and (1, 4)
-
Consider the following four investors in Newco: Series A: CP: $5M APP (and 2X liquidation preference) or converts to 5M shares Series B: RP: $10M APP plus 5M shares of common Series C: PCP: $10M APP...
-
True, False, or Uncertain: If two firms have exactly the same balance sheet and income statement on their respective graduation dates, then the firm with the higher growth rate will also have the...
-
True, False, or Uncertain: After a portfolio company has an IPO, the VCs are free to sell their stock in this company in the public market.
-
The unsystematic risk of a security is also called its a. b. c. d. perceived risk unique or asset-specific risk market risk fundamental risk
-
The systematic risk principle states that a. systematic risk doesn't matter to investors b. C. d. systematic risk can be essentially eliminated by diversification the reward for bearing risk is...
-
Which type of risk is essentially eliminated by diversification? a. b. c. d. perceived risk market risk systematic risk unsystematic risk
Study smarter with the SolutionInn App