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
-
What do you think about China's currency manipulation? is it good or bad for us here in the U.S.? why or why not If the value of the U.S. dollar decreases , what would be the implications for...
-
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)
-
Let be an eigenvalue of an n x n matrix A. and let x be an eigenveclor belonging to . Show that e is an eigenvalue of eA and x is an eigenvector of eA belonging to e.
-
According to the textbook, an example of a tax sustainability KPI would be: a. Frequency of concerns pertaining to the organizations tax position. b. Level of job satisfaction of the tax personnel....
-
The following information from Buchanan Company's current operations is available: Required a. Prepare a multiple-step income statement. Disregard earnings per share. b. Prepare a single-step income...
-
The financial statements of The Hershey Company are presented in Appendix B, following the financial statements for Tootsie Roll Industries in Appendix A. Instructions (a) Based on the information...
-
Heads Up Company was started several years ago by two hockey instructors. The company's comparative balance sheets and income statement follow, along with additional information. Balance Sheet at...
-
Kevin has met with you and Brenda. Brenda has explained his current duties as an enduring power of attorney holder. She has also provided Kevin with a copy of Norman's will and briefly explained his...
-
sapling learning The image below shows a lipid bilayer, with the polar heads represented by circles and the hydrophobic tails represented by lines. Drag the fatty acids into the lipid bilayer to...
-
When doing business with an emerging market like Africa, there are often surprise costs, such as the logistics costs. How might you incorporate that into your initial NPV for the acquisition?
-
It is a general knowledge that there exists a gap between theory and practice in the world of economic thinking and behavior. By implication, a theory which appears logically sound might not be...
-
Having a hard time with these two review questions for my exam, the correct answer is highlighted however could you show the steps on how to achieve this answer? Materials costs of $300,000 and...
-
In JavaScript in separate programs create: Assignment 1: Create an HTML file with a button and a paragraph element. Use jQuery to hide the paragraph element when the button is clicked and show it...
-
The current balance sheet of Apex reports total assets of $20 million, total liabilities of $2 million, and stockholders' equity of $18 million. Apex is considering several financing possibilities in...
-
For f(x)=x-e-2x Evaluate f'(x). Any form is good for this if it's right!
-
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...
-
As Example 6.8 clearly illustrates, the pdf of a random variable that is symmetric about the origin is not in general a valid reproducing kernel. Take two such iid random variables \(X\) and...
-
Given two Hilbert spaces \(\mathscr{H}\) and \(\mathscr{G}\), we call a mapping \(A: \mathscr{H} ightarrow \mathscr{G}\) a Hilbert space isomorphism if it is (i) a linear map; that is, \(A(a f+b...
-
Let \(\mathbf{X}\) be an \(n \times p\) model matrix. Show that \(\mathbf{X}^{\top} \mathbf{X}+n \gamma \mathbf{I} \mathbf{I}_{p}\) for \(\gamma>0\) is invertible.
Study smarter with the SolutionInn App