Problem 1 Please implement an “efficient” program name it p7 to solve the following problem and give big O notations of all your functions and main routine in document strings enclosed in triple...

1 answer below »
Please follow instructions in the given document, complete both two problems.


Problem 1   Please implement an “efficient” program name it p7 to solve the following problem and give big O notations of all your functions and main routine in document strings enclosed in triple quotes. Your program should read input of two lines, the first line specifies the sum of integer pairs which is looking for, and the second line contains a list of integers. Your program should read all t7*.dat in the same directory as your p7.py or p7.ipynb, and generate output for each t7*.dat as the example below. You need handle whitespace as the whitespace convention and handle errors as always.   Input Example: $ cat t70.dat 30 1,-56,32,5,-2,25 Output Example: 32 + -2 = 30 5 + 25 = 30 1, -56 Note: the output order of the remaining integers unpaired is not strict, i.e., both 1, -56 or -56, 1 are fine for above output example.   Problem 2  Please give the big O notation for the function below. Note: please make this answer as a comment at end of problem 1 above and thus you only need to upload it on Canvas all together. def myzip(a): while True: k = len(a) for x,i in enumerate(a): if len(i): print(i[0]) a[x] = a[x][1:] else: k -= 1 if k == 0: break
Answered Same DayOct 18, 2021

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
155 Votes
{
"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",
" ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here