Answered step by step
Verified Expert Solution
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 ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started