Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given an array of unsorted integers, find the maximum product of two integers in an array. For example, if the arr = [10, 8,

 

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)

Step by Step Solution

3.47 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

a Bruteforce algorithm pseudocode maxProductarr maxProd INFINITY n arrlength for i from 0 to n1 for ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Venture capital and the finance of innovation

Authors: Andrew Metrick

2nd Edition

9781118137888, 470454709, 1118137884, 978-0470454701

More Books

Students also viewed these Programming questions