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. |
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
5000 C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast
10000 C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast
15000 C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast
20000 C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast
100000 C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast
1000000 C:\Users\User\Desktop>java -jar runningtimes.jar 2sumfast
1048576 C:\Users\User\Desktop> |
We have packaged the four algorithms TwoSumFast and TwoSum, in a jar file that you can...
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 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 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 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 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 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 (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 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 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 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...