Answer To: Problem 1 Please implement an “efficient” program name it p7 to solve the following problem and give...
Shivam answered on Oct 19 2021
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import csv\n",
"\n",
"data = [i.strip().split() for i in open(\"./t70-mpxtyxnv.dat\").readlines()]\n",
"'''big O = O(n)'''"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"sum = int(data[0][0])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"30"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'1,-56,32,5,-2,25'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data[1][0]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"pair = [int(x) for x in data[1][0].split(',')]\n",
"'''big O = O(n)'''"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, -56, 32, 5, -2, 25]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pair"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"32 + -2 = 30\n",
"5 + 25 = 30\n",
"-56 1 "
]
}
],
"source": [
"pairlist = []\n",
"nopair = []\n",
"for i in pair:\n",
" for j in pair:\n",
" if i + j == sum:\n",
" if i not in pairlist:\n",
" ...