Question: 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 

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

1 Expert Approved Answer
Step: 1 Unlock

a Bruteforce algorithm pseudocode maxProductarr maxProd INFINITY n arrlength for i from 0 to n1 for ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!