Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1 Sum of K Problem Description We are given an input file that contains word SumOfK, target number K, and a sequence of N

Exercise 1 Sum of K Problem Description

We are given an input file that contains word SumOfK, target number K, and a sequence of N numbers.

We want to determine if there are two numbers whose sum equals the given target number K.

For instance, if the input file contains SumOfK // word 10 // target number K 8 4 1 6 // sequence of N numbers We know from the file that K is 10, sequence of numbers is 8 4 1 6, and number of elements N is 4 (we can count numbers). In this case, the answer is yes, there are two such numbers (4 and 6), because 4+6 is 10. One number may be used twice (doubled). If the input file is SumOfK 10 8 4 5 3 the answer is also yes, because 5+5 is 10. Exercise1 Program Devise an O(N2) algorithm to solve this problem. Code the solution. The program has to read 5 input files and print the results to corresponding 5 output files. All files have to be processed in one program run. The input files have to be named inX.txt and the output files have to be named outX.txt (where X is 1, 2, 3,4,5). The input and output files shall be in format similar to the examples below. The instructor will use different numbers to test your program.

There are 5 input files.

input1.txt

SumOfK 14 5 12 8 11 7 4 3 5 5 3 2 1

expected output

14 SumOfK 5 12 8 11 7 4 3 5 5 3 2 1 Exercise1 calculation complexity O(n^2) Yes 12+2=14

please advise

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

More Books

Students also viewed these Databases questions

Question

What are the main objectives of Inventory ?

Answered: 1 week ago

Question

Explain the various inventory management techniques in detail.

Answered: 1 week ago

Question

Writing a Strong Introduction

Answered: 1 week ago