NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

1-(a) Implement a Java method that generates a random permutation (i.e. ordering) of integers from 1 to 5 and display it on the screen. Your program should use array(s) and you can use the nextInt method of the Random class under java.util package or the nextInt method of the SecureRandom class under the java.security package to generate random integers but you cannot use these classes to generate a random permutation.
(b) Call the method you implemented in part (a) 100,000 times and compute the frequency of the 5 integers (1 to 5) at each position of the permutation and report these frequencies. You should expect to have equal frequency for each number at each position. Your answer can be provided as a table shown below:

Number | Position 1 | Position 2 | Position 3 | Position 4 | Position 5

1 4303 4215 …



5 3957 4165 …



Starting with the InsertionSort algorithm modify the Java code InsertionSort.java so that your program prints the original array, sorted array and the indices of the sorted numbers to the screen. Assume that the indices start from 0. For instance your output can look like:
orig = [41, 38, 48, 12, 28, 46, 33, 19, 10, 58]

data = [10, 12, 19, 28, 33, 38, 41, 46, 48, 58]

indices = [8, 3, 7, 4, 6, 1, 0, 5, 2, 9]





public class MyInsertionSort {

public static void main(String a[]){
int[] arr1 = {10,34,2,56,7,67,88,42};
int[] arr2 = doInsertionSort(arr1);
for(int i:arr2){
System.out.print(i);
System.out.print(", ");
}
}

public static int[] doInsertionSort(int[] input){

int temp;
for (int i = 1; i < input.length; i++) {
for(int j = i ; j > 0 ; j--){
if(input[j] < input[j-1]){
temp = input[j];
input[j] = input[j-1];
input[j-1] = temp;
}
}
}
return input;
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.