Question: Based off the question below, I have created a method and I have determined that regardless of data in random, ordered or reversed data, this
Based off the question below, I have created a method and I have determined that regardless of data in random, ordered or reversed data, this has a complexity of O(n^2).
I was wondering if you could explain to me how to find the number of comparisons necessary to identify larges and smallest integers with the set of l elements, as would be determined by my algorithm. I am having troubel conceptualizing.
Lets sort using a method not discussed in class. Suppose you have n data values in in array A. Declare an array called Count. Look at the value in A[i]. Count the number of items in A that are smaller than the value in A[i]. Assign that result to count[i]. Declare an output array Output. Assign Output[count[i]] = A[i]. Think about what the size of Output needs to be. Is it n or something else? Write a method to sort based on this strategy.
Public class Array {
//main method
Public static void main (String args[] {
int j = 0;
int l = 16;
int counter;
//create array to hold values
int[] countNumbers = new int[n];
int[A] = {15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
int[] OutputArray = new int[n];
//create nested for loop that has counter count up to biggest number held in array.
for (int i=0; i counter =0; for (int k = 0; k j++; if (A[k]>A[i]) counter++; countNumber[i] = counter; output[countNumber[i]] = A[i]; For (int i = 0; i System.out.println(OutputArray[i]); j++;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
