Write a program that performs a one-position left rotation of the elements in an array. Demon...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program that performs a one-position left rotation of the elements in an array. Demon strate the effect by having the program rotate the elements in this particular array: should print the new sequence. Your solution should perform the rotation without creating another array, The rotation should change the sequence of the array's elements to: "Amy," "Raj." and "Sheldon." Then i String[] scientists ("Sheldon". "Amy". "Raj"); although you will need a variable to temporarily hold an element's value. 9. [after $9.8] Given the following list array, use the selection sort algorithm to sort the array. Show each step of the selection sort process. Do not provide code; just show pictures of the list array after each ele ment swap. list (original) 0 18 1 2 2 6 3 -5 5 list (sorted) 0 -5 2 23 5 3 6 18 10. [after $9.8] The insertion-sort algorithm provides an alternative to the selection-sort algorithm for sorting something like a hand of cards, where there is a small number of items (about 20 or less). It's more eff cient than selection sort if the array is only slightly out of order, but it's relatively inefficient for large numbers of items. The following code implements a descending insertion-sort algorithm: 1 public static void insertionSort(int[] cards) 2 [ int pick: 3 4 int j: 5 6 7 8 9 for (int 1-1: 1 10 11 [ 12 for (j-1: j>0 && pick>cards[j-11: --) cards[j] - cards[j-1]; 13 14 cards[j] pick; // insert as next highest 15 ) 16 // end insertionSort 45 Note that the scope of the j count variable extends beyond the scope of the for loop in which it's used. Assume that an array of int has been instantiated and the insertionSort method has been called with a reference to this array passed in as a parameter. Trace the execution of this method, using the following header and initial entries: 26 Sort insertionSort arr1 line# (cards) i j pick length O 1 5 3 2 1 arr1 39 Write a program that performs a one-position left rotation of the elements in an array. Demon strate the effect by having the program rotate the elements in this particular array: should print the new sequence. Your solution should perform the rotation without creating another array, The rotation should change the sequence of the array's elements to: "Amy," "Raj." and "Sheldon." Then i String[] scientists ("Sheldon". "Amy". "Raj"); although you will need a variable to temporarily hold an element's value. 9. [after $9.8] Given the following list array, use the selection sort algorithm to sort the array. Show each step of the selection sort process. Do not provide code; just show pictures of the list array after each ele ment swap. list (original) 0 18 1 2 2 6 3 -5 5 list (sorted) 0 -5 2 23 5 3 6 18 10. [after $9.8] The insertion-sort algorithm provides an alternative to the selection-sort algorithm for sorting something like a hand of cards, where there is a small number of items (about 20 or less). It's more eff cient than selection sort if the array is only slightly out of order, but it's relatively inefficient for large numbers of items. The following code implements a descending insertion-sort algorithm: 1 public static void insertionSort(int[] cards) 2 [ int pick: 3 4 int j: 5 6 7 8 9 for (int 1-1: 1 10 11 [ 12 for (j-1: j>0 && pick>cards[j-11: --) cards[j] - cards[j-1]; 13 14 cards[j] pick; // insert as next highest 15 ) 16 // end insertionSort 45 Note that the scope of the j count variable extends beyond the scope of the for loop in which it's used. Assume that an array of int has been instantiated and the insertionSort method has been called with a reference to this array passed in as a parameter. Trace the execution of this method, using the following header and initial entries: 26 Sort insertionSort arr1 line# (cards) i j pick length O 1 5 3 2 1 arr1 39
Expert Answer:
Related Book For
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean
Posted Date:
Students also viewed these programming questions
-
Briefly describe ASCII and Unicode and draw attention to any relationship between them. [3 marks] (b) Briefly explain what a Reader is in the context of reading characters from data. [3 marks] A...
-
William made the following acquisitions of preference shares in Pangol plc: In January 2020, the company made a 1 for 4 bonus issue. In February 2021, William sold 450 shares for 4 per share....
-
Using the notation scheme for defining manipulator configurations, draw diagrams of the following robots: (a) TRL, (b) OLO, (c) LVL.
-
A painting with a mass of 21 kg is suspended by two wires from hooks on a ceiling. if the wires have lengths of 21 cm and 30 cm and the distance between the hooks is 35 cm , find the tension in each...
-
P(x > 18) Write the binomial probability in words. Then, use a continuity correction to convert the binomial probability to a normal distribution probability.
-
Des Moines Power and Light has been collecting data on demand for electric power in its western subregion for only the past 2 years. Those data are shown in the table at the top of the shown below....
-
In order for a business to control costs, it must first identify the costs that can be incurred and the nature of these costs. It is critical that managers are able to identify what causes costs, as...
-
Can you give an example of a complex business concept you had to explain to a non-expert audience?
-
Margaret Hastings is a 48 year old widowed single parent with one child, aged 14. Margaret's husband had been a heavy smoker all of his life, and he died two years ago from lung cancer. On his death,...
-
You are working at La Pizza Buonaan Italian chain of restaurants in North Dakota. Since last year we have seen a decline in visits and the marketing department is looking for new ideas. They want to...
-
1. Given the following actual sales, t A(t) 1 8 2 4 3 4 5 a. Use a 3 period Simple Moving Average method to forecast sales in periods 6, 7, and 8. b. Use a 3 month Weighted Moving Average method...
-
7. [-/1.25 Points] The O'Neill Shoe Manufacturing Company will produce a special-style shoe if the order size is large enough to provide a reasonable profit. For each special-style order, the company...
-
It is December 31, 2019 and Jane needs to assess the difficulty of the task ahead for her gourmet sandwich shop in 2020. She is planning to introduce several new sandwiches and hence has not...
-
What role does a complete and current job description play in Human Resource Management?
-
On 1 July 2021, Croydon Ltd leased ten excavators for five years from Machines4U Ltd. The excavators are expected to have an economic life of 6 years, after which time they will have an expected...
-
This exercise considers data from the Medical Expenditure Panel Survey (MEPS) described in Exercise 1.1 and Section 11.4. Our dependent variable consists of the number of outpatient (COUNTOP) visits....
-
This exercise considers the data described in the Section 13.2.2 ratemaking classification example using data in Table 13.3 Table 13.3 . a. Fit a gamma regression model using a log-link function with...
-
Verify that the Tweedie distribution is a member of the linear exponential family of distributions by checking equation (13.9). In particular, provide an expression for \(S(y, \phi)\) (note that...
Study smarter with the SolutionInn App