304 North Cardinal St.
Dorchester Center, MA 02124

# Programming Assignment 1: Maximum Pairwise Product Solution – Algorithmic Toolbox

## Get Programming Assignment 1: Maximum Pairwise Product Solution

This online course covers basic algorithmic techniques and ideas for computational problems arising frequently in practical applications: sorting and searching, divide and conquer, greedy algorithms, dynamic programming.

We will learn a lot of theory: how to sort data and how it helps for searching; how to break a large problem into pieces and solve them recursively; when it makes sense to proceed greedily; how dynamic programming is used in genomic studies. You will practice solving computational problems, designing new algorithms, and implementing solutions efficiently (so that they run in less than a second).

Enroll on Coursera

### Instruction of Programming Assignment 1: Maximum Pairwise Product

In this programming challenge, your goal is to implement a program that works in less than one second even on huge datasets. In section Maximum Pairwise Product of the file week1_programming_challenges/week1_programming_challenges.pdf we walk you through a step-by-step process of solving this challenge. We will encounter several common pitfalls and will show you how to fix them.

The archive file with all the statements and starters is available from a separate page (that can be found at the left pane under Resources): https://www.coursera.org/learn/algorithmic-toolbox/resources/3r3Mv

#### Programming Assignment 1: Maximum Pairwise Product Solution in Python

``````#Naive approach
def max_prod_naive(arr):
product = 0
for i in range(len(arr)):
for j in range(i+1,len(arr)):
product = max(product,arr[i]*arr[j])
return product
#Fast approach
def max_prod_fast(arr):
p1 = max(arr)
arr.remove(p1)
p2 = max(arr)
return p1*p2
#Stress test
from random import randint
def max_prod_stress(N,M):
while True:
n = randint(2,N)
A = [None]*n
for i in range(n):
A[i] = randint(0,M)
print(A)
result1 = max_prod_naive(A)
result2 = max_prod_fast(A)
if result1==result2:
print('OK')
else:
return
max_prod_stress(5,100)``````

#### Programming Assignment 1: Maximum Pairwise Product Solution in C++

``````#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,i;
cin>>n;
long long a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
cout<<(a[n-1]*a[n-2]);
}``````
##### How to Submit Programming Assignment 1: Maximum Pairwise Product Solution?

When you’re ready to submit, you can upload files for each part of the assignment on the “My submissions” tab.

##### Algorithmic Toolbox Course Review:

In our experience, we suggest you enroll in Algorithmic Toolbox Course and gain some new skills from Professionals completely free and we assure you will be worth it.

Algorithmic Toolbox course is available on Coursera for free, if you are stuck anywhere between quiz or graded assessment quiz, just visit Queslers for Peer Graded Solution and Networking Funda to get Algorithmic Toolbox Quiz Answers.

##### Conclusion:

I hope this Programming Assignment 1: Maximum Pairwise Product Solution would be useful for you to learn something new from this Course. If it helped you then don’t forget to bookmark our site for more Coursera Quiz Answers.

This course is intended for audiences of all experiences who are interested in learning about new skills in a business context; there are no prerequisite courses.

Keep Learning!