Question

We have packaged the four algorithms TwoSumFast and TwoSum, in a jar file that you can download from (https://github.com/id1020/lab2-runningtimes/blob/master/runningtimes. jar? raw=true). Also, a simple program has been added to measure the execution time of each of the algorithms for some given input, For example, if you want to measure the time taken by TwoSum for a file of 1000 numbers, you should run > java -jar runningtimes.jar 2sum 1000 1000 0.006 The program prints back the input size which is 1000 and the time taken which is 0.006 seconds. Question: Estimate the amount of time it would take to run TwoSumFast and TwoSum, on your computer to solve the problems for a file of 1048576 numbers. Notice that measuring the execution time is not feasible for all points, so you have to think about predicting time for those point you cant measure. Answer with at least 50 words to explain which of the alternatives are correct: a) miliseconds or seconds b) minutes or hours c) hours or days d) days or months e) years

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Two sum

The 2sum algorithm was checked with running a sum of variable number of elements and 5 observations were recorded.

1st Run on total 1,000 elements -- time taken to complete the process - 0.013 seconds

2nd Run on total 5,000 elements -- time taken to complete the process - 0.025 seconds

3rd Run on total 10,000 elements -- time taken to complete the process - 0.126 seconds

4th Run on total 15,000 elements -- time taken to complete the process - 0.236 seconds

5th Run on total 20,000 elements -- time taken to complete the process - 0.453 seconds

Now, studying the pattern it was found

0.025 = 1.92 x 0.013

0.126 = 9.69 x 0.013

0.236 = 18.15 x 0.013

0.453 = 34.84 x 0.013

Hence studying the above pattern the time can be calculated as approximately

=> 2n+1 0.013 -----------------------------where n = total elements / 5000

Hence calculating for 1,048,576 elements

n = 1048576 / 5000 = 209.71 = 210 approx

Putting the value of n in in the formula we get,

( 2( 210 + 1 ) ) . ( 0.013 )

( 2211 ) . ( 0.013 )

4.2783 x 10^61 seconds

Changing into hours

1.1884 x 10^58 hours

Now changing hours to days we get

4.9517 x 10^56 days

Now changing days to years

1.3566 x 10^54 years to complete.

Hence it would take years to complete the summation using the algorithm 2sum.

C:AWINDoWS system32\cmd.exe UsersUser Desktop>java -jar runningtimes-jar 2sum 1000 Users User Desktop java -jar Users User De

2sumfast

This algorithm's time is not increasing exponentially, rather it's increasing by a fraction of 10. On running this algorithm for few observations it was found it took less than a second to sum the 10,000,000 elements.

Look at the findings below.


C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast 1000
1000 0.007

C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast 5000
5000 0.013

C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast 10000
10000 0.022

C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast 15000
15000 0.03

C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast 20000
20000 0.034

C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast 100000
100000 0.089

C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast 1000000
1000000 0.353

C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast 1048576
1048576 0.395

C:\Users\User\Desktop>

Add a comment
Know the answer?
Add Answer to:
We have packaged the four algorithms TwoSumFast and TwoSum, in a jar file that you can...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Overview: In this lab, you will write a program called JobScheduler; it should take a single...

    Overview: In this lab, you will write a program called JobScheduler; it should take a single input file as a command-line argument. Each line in the input file has the following format: <job #> <priority> <arrival time (sec)> <duration (sec)> e.g. a file might contain: 1 3 10 100 5 2 20 50 8 4 5 100 (all values will be positive integers) These jobs might represent computer programs (or threads) that need to be run by the operating system....

  • Overview These exercises will allow you to have some practice with basic Java file Input/Output. In...

    Overview These exercises will allow you to have some practice with basic Java file Input/Output. In addition, you will also have an opportunity to have more practice with methods and arrays.   Objectives Practice with programming fundamentals Variables - Declaration and Assignment Primitive types Arithmetic Expressions Simple keyboard input and text display output Branching - if-elseif-else syntax Loops - simple while loops, nested while loops Methods - functions and procedures ArrayLists - collections of variables File I/O Works towards the following...

  • In this lab we are going to complete a profile of two sorting algorithms by running...

    In this lab we are going to complete a profile of two sorting algorithms by running some tests to collect empirical data. 1. First we need to be able to generate some random integers. You can do this by including the following library : #include Now first run the following to generate a seed : srand (time(NULL)) You can then generate a random number using the function rand() 2. We will use two sort algorithms - Selection Sort and Bubble...

  • Create a header file timer.h containing the following functions (you can have more functions, but the...

    Create a header file timer.h containing the following functions (you can have more functions, but the below ones are required. Do not modify the given function signatures. // Initialize the timer with the user-provided input void initTimer(ClockType *clock, int minutes, int seconds); // Run the timer -- print out the time each second void runTimer(); // Clean up memory (as needed) void cleanTimer(ClockType *clock); Create a file timer.c and implement (at least) these three functions and any other functions you...

  • HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the...

    HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the second line of the display, using the HH:MM:SS format. Use the 24-hour format for the hours, in other words, have the time go from 00:00:00 to 23:59:59. #include<LiquidCrystal.h> LiquidCrystal LcdDriver(11, 9, 5, 6, 7, 8); int minutes = 27; //These global integers keep the value of the clock int sec = 10; int hr = 10; const long interval = 1000; //This interval is...

  • Untitled - Notepad File Edit Format View Help Algorithms 1.You have been given a 1le with two columns: a name and an integer (whole number representing how many aquatics training sessions the per...

    Untitled - Notepad File Edit Format View Help Algorithms 1.You have been given a 1le with two columns: a name and an integer (whole number representing how many aquatics training sessions the person has attended in semester 1 between 0 and 24 inclusive. The 1le will look something like: Ada 22 Jordan 10 Anita 15 Xavier 24 are in the 1le, however the 1le will be terminated by It is not known at the outset how many rows EOF (end...

  • Capitalization JAVA In this program, you will read a file line-by-line. For each line of data...

    Capitalization JAVA In this program, you will read a file line-by-line. For each line of data (a string), you will process the words (or tokens) of that line one at a time. Your program will capitalize each word and print them to the screen separated by a single space. You will then print a single linefeed (i.e., newline character) after processing each line – thus your program will maintain the same line breaks as the input file. Your program should...

  • As we continue with our study of programming fundamentals, here is a short extra credit programming...

    As we continue with our study of programming fundamentals, here is a short extra credit programming challenge involving selection control structures. To be specific, the program specifications below and the algorithm you develop and write will involve the set-up and use of either nested if-else statements and/or switch statements. Choose one of the following programming challenges below for this algorithm workbench extra credit programming challenge… ------------------------------------------------------------------------------------------- Finding median Use selection control structures to write a C++ program that determines the...

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that...

    Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT