Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In python It is the same problem as in Exercisel, but you have to write a different program. We are given an input file that
In python
It is the same problem as in Exercisel, but you have to write a different program. 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 10 8416 // word // "target" number K // sequence of N numbers We know from the file that K is 10, sequence of numbers is 8 416, 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 8453 the answer is also yes, because 5+5 is 10. Lab1 Program Devise and implement an O(N*log(N)) algorithm to solve the problem. Split it in two parts - sort the items first, after it is done, you have to search for numbers in O(N). See https://en.wikipedia.org/wiki/Heapsort Code the solution. Read data from input file inx.txt and print the results to output file outx.txt (where X is 1, 2, ...). The differences between Lab1 and Exercisel are The algorithm has to consist of two parts - (N*log(N)) sorting and O(N) searching The output file has also to contain the sorted list of input numbers Test and Sample Files There are five test input files provided -in1.txt, in2.txt, in3.txt, in 4.txt and in5.txt. There are also four sample output files corresponding to the input files -out1_sample.txt, out2_sample.txt, out3_sample.txt and out4_sample.txt (file out5_sample.txt is not provided). Correspondent files Correspondent files Correspondent files Correspondent files Correspond ent files in1.txt in2.txt in3.txt in4.txt In5.txt Provide d test input files Provide out1_sample.txt out2_sample.txt out3_sample.txt out4_sample.txt none sample output files out1.txt out2.txt out3.txt out4.txt out5.txt Output files to produce The format of the produced output files shall be similar to the provided sample output files. The results have to be the same. Run your program using all five test input files to produce five output files and submit the input and output files together with the source code. Compare the output files produced by your program with the sample files. Submit the test input and the produced output files together with the program source codeStep by Step Solution
There are 3 Steps involved in it
Step: 1
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