Question

In: Computer Science

I have a set of 100,000 random integers. How long does it take to determine the...

I have a set of 100,000 random integers. How long does it take to determine the maximum value within the first 25,000, 50,000 and 100,000 integers? Will processing 100,000 integers take 4 times longer than processing 25,000? You may use any programming language/technique. It is possible the time will be very small, so you might need to repeat the experiment N times and determine an average value for time. Complete this table. Source code is not needed.

Number

Time

25,000

50,000

100,000

Language/Tool used:

Technique used:

Solutions

Expert Solution

Number Time
25,000 2 msec
50,000 2 msec
100.000 4 msec
Language/Tool Used: JAVA/Ecilipse
Technique Used: Comparison

if you want source code

/**********************MaxRandom.java****************************/

import java.util.Random;
import java.util.Scanner;

public class MaxRandom {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       // prompt for limit
       System.out.print("Enter the limit: ");
       // enter limit
       int limit = scan.nextInt();
       // set max number to minimum value
       int maxNumber = Integer.MIN_VALUE;
       Random random = new Random();
       // start time
       long startTime = System.currentTimeMillis();
       // generate random and compare with max and set max if greater than max
       for (int i = 0; i < limit; i++) {

           int randomNumber = random.nextInt(100000);
           if (maxNumber < randomNumber) {

               maxNumber = randomNumber;
           }
       }
       // end time
       long endTime = System.currentTimeMillis();
       // print value and time taken
       System.out.println("Max number " + maxNumber + " found in: " + (endTime - startTime) + " msec");
       scan.close();
   }
}
/*********************output*********************/

Enter the limit: 100000
Max number 99999 found in: 4 msec

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

How long does it take for an investment to double in value if it is invested...
How long does it take for an investment to double in value if it is invested at 15?% compounded monthly??Compounded? continuously?
What are the phases of fracture healing? How long does each stage take for a long...
What are the phases of fracture healing? How long does each stage take for a long bone vs a distal/small bone? How will this knowledge come into action when working with orthopedic patients?
3. For each of the following relations on the set Z of integers, determine if it...
3. For each of the following relations on the set Z of integers, determine if it is reflexive, symmetric, antisymmetric, or transitive. On the basis of these properties, state whether or not it is an equivalence relation or a partial order. (a) R = {(a, b) ∈ Z 2 ∶ a 2 = b 2 }. (b) S = {(a, b) ∈ Z 2 ∶ ∣a − b∣ ≤ 1}.
How long does it take to reduce the capacitor's charge to 10 μC?
A 20 μF capacitor initially charged to 25 μC is discharged through a 1.5 kΩ resistor. Part A How long does it take to reduce the capacitor's charge to 10 μC?  
How long does it take to reduce the capacitor's charge to 5.00 µC?
A 10.0 µF capacitor initially charged to 30.0 µC is discharged through a 1.50 kO resistor. How long does it take to reduce the capacitor's charge to 5.00 µC?  
How long does it take for an investment of P800,000 for a new product to earn...
How long does it take for an investment of P800,000 for a new product to earn P600,000 if it is expected to yield a 15% per year compounded annually? If the manager requested simple interest instead, would there be a difference?
If an object is projected at a given angle and speed, how long does it take...
If an object is projected at a given angle and speed, how long does it take to reach its maximum height? Please explain in simplest terms and give an example using units given.
QUESTION 1 How long? How much time in seconds does it take for the sled to...
QUESTION 1 How long? How much time in seconds does it take for the sled to go down part of a hill? A sled with a total mass of 671 kilograms is going down a straight part of a hill where the angle of incline is 10.6 degrees. The length of the straight part of the hill is 76.4 metres. The speed of the sled at the top of the hill is 4 meters per second. The combined forces of...
Problem 2.3 Suppose that we take the universal set U to be the integers. Let S...
Problem 2.3 Suppose that we take the universal set U to be the integers. Let S be the even integers, letT be the integers that can be obtained by tripling any one integer and adding one to it, and let V be the set of numbers that are whole multiples of both two and three. (i) Write S, T, and V using symbolic notation. (ii) ComputeS∩T, S∩V andT∩V and give symbolic representations that do not use the symbols S, T,...
Part A How long does it take a person at rest to breathe one mole of...
Part A How long does it take a person at rest to breathe one mole of air if the person breathes 84.0 mL/s of air that is measured at 25 ∘C and 755 mmHg? Express your answer numerically in seconds. Part B Typically, when a person coughs, he or she first inhales about 2.50 L of air at 1.00 atm and 25 ∘C. The epiglottis and the vocal cords then shut, trapping the air in the lungs, where it is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT