Evaluate the time complexity of the different algorithms

Assignment Help C/C++ Programming
Reference no: EM131799727

Question 1. Using the piece of code in Table # 1 below, Evaluate the time complexity of the 3 different algorithms to produce the sum of the first n numbers as indicated in Table # 2 below.

Question 2. Compare the result obtained for various value of n. You are to display the result in a comparative table and possibly plot a comparative graph (curve).

Table 1: Program Execution Time estimation
import java.util.Date
Date current = new Date();
long beginTime =
current.getTime();
myMethod(); //code to be timed
current = new Date();
long endTime = current.getTime();

long TotalExecutionTime = endTime - beginTime; long startTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
// long startTime = System.nanoTime();

Table 2: Three Algorithms to implement the sum 1 to n

Algorithm A
Sum = 0
for i = 1 to n Sum = Sum + i

Algorithm B
Sum = 0
for i = 1 to n {
for j = 1 to i Sum = sum + 1 }

Algorithm C
Sum = n * ( n + 1 ) /2

3. Using the getTime() as shown above, display a table of the run time of each algorithm for the following values of n: 10, 100, thousand, ten thousands, hundred thousand, one million.

Algorithms

n=10

n=100

n=1000

n=10,000

N=100,000

Algorithm A

T=

 

 

 

 

 

 

 

 

 

 

Algorithm B

T=

 

 

 

 

Algorithm C

T=

 

 

 

 

 

 

 

 

 

 

Reference no: EM131799727

Questions Cloud

What price would cherokee charge to maximize revenues : Cherokee company sells a single product that has a variable costs
What is the carrying value of the bonds : What is the carrying value of the bonds? What effect will the acquisition of treasury stock have on stockholders' equity and earnings per share, respectively?
Rules and regulations of federal purchasing : Imagine for a moment that there were fewer rules and regulations as related to federal purchasing. Yes, the issue arises all the time.
Is there anything else you would like to learn : Discuss if these ideas connected with any concepts discussed in class and/or information from the media (about 200 words)
Evaluate the time complexity of the different algorithms : Evaluate the time complexity of the 3 different algorithms to produce the sum of the first n numbers as indicated in Table - You are to display the result
Find the company predetermined overhead rate : Using GSCC's current product-costing system: Determine the company's predetermined overhead rate using direct-labor cost as the single cost driver
Discuss disadvantage of reworking these calculators : what is the net advantage or disadvantage of reworking these calculators
Discuss your educational aspirations and goals : As we have started to explore the different readings for the week, we can see just how varied to the approach to understanding terrorism has become.
Describing the ima and aicpa ethical codes : The IMA and AICPA ethical codes refer to objectivity and competence in the profession. This means if you don't participate in continuing education.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Generate a random number

Generate a random number between 1 – 5 and 3 – 8 for express and normal lanes, respectively. This represents the arrival time of the first customer into each lane. Set the variable for total time elapsed to 0.

  A list of toppings should be shown on the screen as a menu

Write a menu-driven C++ program that allows a user to select from the following items: Pizza, Cheeseburger, and Hot Dog. Pizza should be represented by the integer value 1. Cheeseburger should be represented by the integer value 2.

  Design a phonecall class that holds a phone number

Design a PhoneCall class that holds a phone number to which a call is placed, the length of the call in minutes, and the rate charged per minute. Overload extraction and insertion operators for the class.

  Calculation of mortgage interest rates

Instruction of pointers and the calculation of mortgage interest rates.

  Program to read in the number of a month

Program to read in the number of a month and output the name of the month. Then the user is asked if they want to know the number of days in that month and if so output the number of days

  Goto statements to explicitly

Rewrite the following program fragment using goto statements to explicitly show the flow control through the loop.

  Write a program that creates an array of 200 random numbers

Write a program that creates an array of 200 random real numbers between 0 and 200.  Using the statistics library, calculate and output the following: mean, median, variance, standard deviation, maximum value, and minimum value.

  Display a count of the number of vowels

Write a program that accepts a word into a character array string variable. Display a count of the number of letters in the word.

  Create a flowchart of the program

Create a flowchart of the program, using the pseudo-code from Unit 4 Topic 2 as a guide.

  Direct cost variance analysis

Problem 2: Direct Cost Variance Analysis  Ken Co. uses standard costing for accounting. Following is the standards for production of its only product:Direct material: 18 pounds at $25 per pound

  Client-server architecture program for windows

You need a client-server architecture program for windows OS (minimum support: Win 7),. the agent program will run as a background process and perform certain tasks every X time, and send results to a web server (PHP API).

  Write the program with indentation and formatting style

Write the program with indentation and formatting style as discussed in class, and given in the program requirement. Write documentation for your programs as discussed in class and given in the program requirement.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd