Write a program that randomly generates an array of 500,000 integers between 0 and 499.999, and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program that randomly generates an array of 500,000 integers between 0 and 499.999, and then prompts the user for a search key value. Estimate the execution time of invoking the linearSearch method in Listing A below. Sort the array and estimate the execution time of invoking the binarySearch method in Listing B below. You can use the following code template to obtain the execution time: long startTime = System.currentTimeMillis(); [your code goes here] long endTime = System.currentTimeMillis(); long executionTime endTime - startTime; Here are two sample runs: Enter a search key: 11079 Searching... The key, 11079, was found at index 357158. Linear search execution time: 7 milliseconds. Searching... The key value, 11079, was found at index: 11115. Binary search execution time: milliseconds. Enter a search key: 95043 Searching... The key, 95043, was not found. Linear search execution time: 11 milliseconds. Searching... The key value, 95043, was not found. Binary search execution time: 0 milliseconds. A. Linear Search public static int linearSearch (int[] list, int key) { for (int i=0; i < list.length; i++) { if (key list[i]) Activate Win Go to Settings to return i; } return -1; A. Linear Search public static int linearSearch (int[] list, int key) { for (int i = 0; i < list.length; i++) { if (key ==list[i]) return 1; return -1; } } B. Binary Search public static int binarySearch (int[] list, int key) { int low = 0; = int high list.length - 1; while (high = low) { int mid = (low + high) / 2; if (key = list [mid]) high mid 1; else if (key == list [mid]) else return mid; low mid + 1; } return -low - } 1; // Now high < low, key not found 7.2 Analyze scores 1. Design: Create the pseudocode to design the process for a program that reads an unspecified number of scores and determines how many scores are above or equal to the average and how many scores are below the average. A negative number should signify the end of the input. Assume that the maximum number of scores is 100. 2. Implementation: Follow your pseudocode to implementent your program. Please submit the following: 1. Click the Write Submission button and enter your pseudocode 2. The zipped (compressed) file containing your project folder with the entire project 3. A captured image (jpeg or png) of your screen showing your program's output 7.3 Dice Rolling Create a flowchart for an application to simulate the rolling of two dice. Requirements: The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums. Table 1 below shows the 36 possible combinations of the two dice. Your application should roll the dice 36,000 times. Use a one-dimensional array to tally the number of times each possible sum appears. Print the results in tabular format. Determine whether the totals are reasonable (e.g., there are six ways to roll a 7, so approximately one-sixth of the rolls should be 7). Table 1 123456 1234567 2345678 3456789 1 456789 0 11 56789 01 111 6789 0 1 2 Here is an example tabular format: 2 3 4 56 7 8 9 10 11 12 ### ### ### ### ### ### ### ### Implementation: Follow your flowchart to implement your program. Please submit the following: 1. Your flowchart as an image file (jpeg or png) 2. A captured image of your screen showing your program's output. 3. The project folder containing your entire project Write a program that randomly generates an array of 500,000 integers between 0 and 499.999, and then prompts the user for a search key value. Estimate the execution time of invoking the linearSearch method in Listing A below. Sort the array and estimate the execution time of invoking the binarySearch method in Listing B below. You can use the following code template to obtain the execution time: long startTime = System.currentTimeMillis(); [your code goes here] long endTime = System.currentTimeMillis(); long executionTime endTime - startTime; Here are two sample runs: Enter a search key: 11079 Searching... The key, 11079, was found at index 357158. Linear search execution time: 7 milliseconds. Searching... The key value, 11079, was found at index: 11115. Binary search execution time: milliseconds. Enter a search key: 95043 Searching... The key, 95043, was not found. Linear search execution time: 11 milliseconds. Searching... The key value, 95043, was not found. Binary search execution time: 0 milliseconds. A. Linear Search public static int linearSearch (int[] list, int key) { for (int i=0; i < list.length; i++) { if (key list[i]) Activate Win Go to Settings to return i; } return -1; Write a program that randomly generates an array of 500,000 integers between 0 and 499.999, and then prompts the user for a search key value. Estimate the execution time of invoking the linearSearch method in Listing A below. Sort the array and estimate the execution time of invoking the binarySearch method in Listing B below. You can use the following code template to obtain the execution time: long startTime = System.currentTimeMillis(); [your code goes here] long endTime = System.currentTimeMillis(); long executionTime endTime - startTime; Here are two sample runs: Enter a search key: 11079 Searching... The key, 11079, was found at index 357158. Linear search execution time: 7 milliseconds. Searching... The key value, 11079, was found at index: 11115. Binary search execution time: milliseconds. Enter a search key: 95043 Searching... The key, 95043, was not found. Linear search execution time: 11 milliseconds. Searching... The key value, 95043, was not found. Binary search execution time: 0 milliseconds. A. Linear Search public static int linearSearch (int[] list, int key) { for (int i=0; i < list.length; i++) { if (key list[i]) Activate Win Go to Settings to return i; } return -1; Write a program that randomly generates an array of 500,000 integers between 0 and 499.999, and then prompts the user for a search key value. Estimate the execution time of invoking the linearSearch method in Listing A below. Sort the array and estimate the execution time of invoking the binarySearch method in Listing B below. You can use the following code template to obtain the execution time: long startTime = System.currentTimeMillis(); [your code goes here] long endTime = System.currentTimeMillis(); long executionTime endTime - startTime; Here are two sample runs: Enter a search key: 11079 Searching... The key, 11079, was found at index 357158. Linear search execution time: 7 milliseconds. Searching... The key value, 11079, was found at index: 11115. Binary search execution time: milliseconds. Enter a search key: 95043 Searching... The key, 95043, was not found. Linear search execution time: 11 milliseconds. Searching... The key value, 95043, was not found. Binary search execution time: 0 milliseconds. A. Linear Search public static int linearSearch (int[] list, int key) { for (int i=0; i < list.length; i++) { if (key list[i]) Activate Win Go to Settings to return i; } return -1; A. Linear Search public static int linearSearch (int[] list, int key) { for (int i = 0; i < list.length; i++) { if (key ==list[i]) return 1; return -1; } } B. Binary Search public static int binarySearch (int[] list, int key) { int low = 0; = int high list.length - 1; while (high = low) { int mid = (low + high) / 2; if (key = list [mid]) high mid 1; else if (key == list [mid]) else return mid; low mid + 1; } return -low - } 1; // Now high < low, key not found A. Linear Search public static int linearSearch (int[] list, int key) { for (int i = 0; i < list.length; i++) { if (key ==list[i]) return 1; return -1; } } B. Binary Search public static int binarySearch (int[] list, int key) { int low = 0; = int high list.length - 1; while (high = low) { int mid = (low + high) / 2; if (key = list [mid]) high mid 1; else if (key == list [mid]) else return mid; low mid + 1; } return -low - } 1; // Now high < low, key not found A. Linear Search public static int linearSearch (int[] list, int key) { for (int i = 0; i < list.length; i++) { if (key ==list[i]) return 1; return -1; } } B. Binary Search public static int binarySearch (int[] list, int key) { int low = 0; = int high list.length - 1; while (high = low) { int mid = (low + high) / 2; if (key = list [mid]) high mid 1; else if (key == list [mid]) else return mid; low mid + 1; } return -low - } 1; // Now high < low, key not found 7.2 Analyze scores 1. Design: Create the pseudocode to design the process for a program that reads an unspecified number of scores and determines how many scores are above or equal to the average and how many scores are below the average. A negative number should signify the end of the input. Assume that the maximum number of scores is 100. 2. Implementation: Follow your pseudocode to implementent your program. Please submit the following: 1. Click the Write Submission button and enter your pseudocode 2. The zipped (compressed) file containing your project folder with the entire project 3. A captured image (jpeg or png) of your screen showing your program's output 7.2 Analyze scores 1. Design: Create the pseudocode to design the process for a program that reads an unspecified number of scores and determines how many scores are above or equal to the average and how many scores are below the average. A negative number should signify the end of the input. Assume that the maximum number of scores is 100. 2. Implementation: Follow your pseudocode to implementent your program. Please submit the following: 1. Click the Write Submission button and enter your pseudocode 2. The zipped (compressed) file containing your project folder with the entire project 3. A captured image (jpeg or png) of your screen showing your program's output 7.2 Analyze scores 1. Design: Create the pseudocode to design the process for a program that reads an unspecified number of scores and determines how many scores are above or equal to the average and how many scores are below the average. A negative number should signify the end of the input. Assume that the maximum number of scores is 100. 2. Implementation: Follow your pseudocode to implementent your program. Please submit the following: 1. Click the Write Submission button and enter your pseudocode 2. The zipped (compressed) file containing your project folder with the entire project 3. A captured image (jpeg or png) of your screen showing your program's output 7.3 Dice Rolling Create a flowchart for an application to simulate the rolling of two dice. Requirements: The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums. Table 1 below shows the 36 possible combinations of the two dice. Your application should roll the dice 36,000 times. Use a one-dimensional array to tally the number of times each possible sum appears. Print the results in tabular format. Determine whether the totals are reasonable (e.g., there are six ways to roll a 7, so approximately one-sixth of the rolls should be 7). Table 1 123456 1234567 2345678 3456789 1 456789 0 11 56789 01 111 6789 0 1 2 Here is an example tabular format: 2 3 4 56 7 8 9 10 11 12 ### ### ### ### ### ### ### ### Implementation: Follow your flowchart to implement your program. Please submit the following: 1. Your flowchart as an image file (jpeg or png) 2. A captured image of your screen showing your program's output. 3. The project folder containing your entire project 7.3 Dice Rolling Create a flowchart for an application to simulate the rolling of two dice. Requirements: The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums. Table 1 below shows the 36 possible combinations of the two dice. Your application should roll the dice 36,000 times. Use a one-dimensional array to tally the number of times each possible sum appears. Print the results in tabular format. Determine whether the totals are reasonable (e.g., there are six ways to roll a 7, so approximately one-sixth of the rolls should be 7). Table 1 123456 1234567 2345678 3456789 1 456789 0 11 56789 01 111 6789 0 1 2 Here is an example tabular format: 2 3 4 56 7 8 9 10 11 12 ### ### ### ### ### ### ### ### Implementation: Follow your flowchart to implement your program. Please submit the following: 1. Your flowchart as an image file (jpeg or png) 2. A captured image of your screen showing your program's output. 3. The project folder containing your entire project 7.3 Dice Rolling Create a flowchart for an application to simulate the rolling of two dice. Requirements: The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums. Table 1 below shows the 36 possible combinations of the two dice. Your application should roll the dice 36,000 times. Use a one-dimensional array to tally the number of times each possible sum appears. Print the results in tabular format. Determine whether the totals are reasonable (e.g., there are six ways to roll a 7, so approximately one-sixth of the rolls should be 7). Table 1 123456 1234567 2345678 3456789 1 456789 0 11 56789 01 111 6789 0 1 2 Here is an example tabular format: 2 3 4 56 7 8 9 10 11 12 ### ### ### ### ### ### ### ### Implementation: Follow your flowchart to implement your program. Please submit the following: 1. Your flowchart as an image file (jpeg or png) 2. A captured image of your screen showing your program's output. 3. The project folder containing your entire project
Expert Answer:
Answer rating: 100% (QA)
import javautilArrays import javautilRandom import javautilScanner public class Searching public sta... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Write a program that randomly generates an array of 100,000 integers and a key. Estimate the execution time of invoking the linearSearch method in Listing 7.6. Sort the array and estimate the...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Use a calculator to approximate the value. Round your answer to two decimal places. arccos(0.051)
-
Why are metals good conductors both of heat and of electricity?
-
What is an access token?
-
Many researchers are interested in the transcription of protein-encoding genes in eukaryotes. Such researchers want to study mRNA. One method that is used to isolate mRNA is column chromatography....
-
Kenseth Corp. has the following beginning-of-the-year present values for its projected benefit obligation and market-related values for its pension plan assets. The average remaining service life per...
-
Multiple Choice Question One indication of financial weakness is that Multiple choice question. the fair value of the firm's debt is higher than the book value. current cash from operations is more...
-
Reconstruct the following syllogistic forms and use the five rules for syllogisms to determine if they are valid from the Boolean standpoint, conditionally valid from the Aristotelian standpoint, or...
-
. Let (0%) for i=1,2,...,n be the volatilities and expected returns of n risky investments. The expected return and volatility of the market portfolio are M = 4% p.a. and OM= 18% p.a., respectively....
-
Summarise the steps required to report your concerns about the risk of harm to the child in the scenario. (Approximately 400 words) In your summary, discuss each of the following key points: What...
-
explain in depth how individual employees differ for tax purposes from independent contractors, For vs From AGI, how deductions and credits work, etc.
-
Due professional care, the third general standard is concerned with what is done by the independent auditor and how well it is done. For example, due care in the matter of audit documentation...
-
Students should select an organization or a section in an organization. 1. You should document the accounting information that is process within the organization or section. 2. What accounting...
-
Joe is 30 years old. She is single and has private health insurance with no dependents. Joe also received $13,000 in cash dividends from her investment in BHP Billiton' s fully franked shares. and a...
-
Water at 45 o C and 10kPa is pumped adiabatically to a pressure of 8.6 kPa. Assuming pump efficiency to be 0.75, calculate: a. What is the work of the pump. b. The temperature change of the water. c....
-
Following is the current balance sheet for a local partnership of doctors: The following questions represent independent situations: a. E is going to invest enough money in this partnership to...
-
Write a program that demonstrates the properties of a text area. The program uses a check box to indicate whether the text is wrapped onto next line, as shown in Figure 16.41a. Four score and seven...
-
Write a program that demonstrates selecting items in a list. The program uses a combo box to specify a selection mode, as shown in Figure 16.43a. When you select items, they are displayed in a label...
-
Rewrite Exercise using a thread to control car racing. Compare the program with Exercise by setting the delay time to 10 in both programs. Which one runs the animation faster? Write a program that...
-
Find the input-output differential equation relating \(v_{o}\) and \(v_{i}(t)\) for the circuit shown below. w R R Vo v(t) R L
-
Consider the following circuit where \(i_{i}(t)\) is the input current and \(i_{o}(t)\) is the output current. (a) Obtain the State-Variable Matrix model \((A, B, C, D)\) for the circuit. (b) Obtain...
-
(a) For the following circuit find the State-Variable Matrix model (A, B, C, D) where \(v_{o}\) is the output voltage and \(v_{i}\) is the input voltage. (b) Also, find the input-output differential...
Study smarter with the SolutionInn App