Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started