Question

Algorithm ComparisonCountingSorting(A[0..n-1], S[0..n-1] )          //Input: Array A[0..n-1] of orderable values          //Output: Array S[0..n-1] of...

Algorithm ComparisonCountingSorting(A[0..n-1], S[0..n-1] )

         //Input: Array A[0..n-1] of orderable values

         //Output: Array S[0..n-1] of A's values in ascending order

  for i ← 0 to n – 1 do

Count[i] ← 0

        for i ← 0 to n – 2 do

for ji + 1 to n – 1 do

                     if A[i] < A[j]

   Count[j] ← Count[j] + 1      // increment counter of larger

else

Count[i] ← Count[i] + 1

  for i ← 0 to n – 1 do

S[ Count[i] ] ← A[i]

For n = 6, trace this algorithm to sort the list 30, 18, 40, 48, 8, 24 into ascending order by indicating the final values of the array Count.

Note: do not show the final sorted values; just the Count values.

Enter the correct values for each sub-scripted element of the array Count:

Count[0] =  

Count[1] =  

Count[2] =

Count[3] =  

Count[4] =  

Count[5] =

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Algorithm ComparisonCountingSorting(A[0..n-1], S[0..n-1] )          //Input: Array A[0..n-1] of orderable values          //Output: Array S[0..n-1] of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following algorithm. ALGORITHM Enigma(A[0.n - 1]) //Input: An array A[0.n - 1] of integer...

    Consider the following algorithm. ALGORITHM Enigma(A[0.n - 1]) //Input: An array A[0.n - 1] of integer numbers for i leftarrow† 0 to n - 2 do for j leftarrow†† i +1 to n - 1 do if A[i] = = A[j] return false return true a) What does this algorithm do? b) Compute the running time of this algorithm.

  • (15 points) Consider the algorithm for insertion sort shown below. The input to this algorithm is...

    (15 points) Consider the algorithm for insertion sort shown below. The input to this algorithm is an earray A. You must assume that indexing begins at 1. 1: for j = 2: A.length do key = A i=j-1 while i > 0 and A[i] > key do Ali + 1] = Ai i=i-1 7: A[i+1] = key (a) Follow this algorithm for A[1..4) =< 7,9,6,8 >. Specifically, please indicate the contents of the array after each iteration of the outer...

  • 1. Design and write a Divide& Conquer algorithm that, given an array A of n distinct...

    1. Design and write a Divide& Conquer algorithm that, given an array A of n distinct integers which is already sorted into ascending order, will find if there is some i such that Ali] in worst-case 0(log n) time.

  • Implement in C SharpCreate a new algorithm based on the algorithm, selection sort. The new algorithm...

    Implement in C SharpCreate a new algorithm based on the algorithm, selection sort. The new algorithm should be able to sort an array like this: Input: an array that has n elements, and the values of its elements are assigned randomly, for example: Index 0 1 2 3 4 5 value 7 3 6 2 1 5 Output: an array - its first n/2 elements are sorted in ascending order and its second n/2 elements sorted in descending order. That...

  • 1. Consider the following well-known sorting algorithm, which is studied later in the book, with a...

    1. Consider the following well-known sorting algorithm, which is studied later in the book, with a counter inserted to count the number of key comparisons. ALGORITHM SortAnalysis(A[0..n − 1]) //Input: An array A[0..n − 1] of n orderable elements //Output: The total number of key comparisons made count ←0 for i ←1 to n − 1 do v ←A[i] j ←i − 1 while j ≥ 0 and A[j ]> v do count ←count + 1 A[j + 1]←A[j ]...

  • Suppose you have an array S indexed from 1 to n which contains n numbers, not...

    Suppose you have an array S indexed from 1 to n which contains n numbers, not in any particular order, and you wish to count how many times a given number x occurs in S. Consider the recursive algorithm below for this which finds the number of occurrences of x in the index range i...j in S. Of course, solving the problem would involve an initial call to the algorithm for the range 1.n: int CountOccur (int i,j) { int...

  • How can i make a counter for the number of exchanges made in the linear algorithm?? The binary counter works but the lin...

    How can i make a counter for the number of exchanges made in the linear algorithm?? The binary counter works but the linear doesn't. Here's my code. #include <iostream> using namespace std; void selectionSort(int[], int, int& ); void showSelection(int[], int); void sortArray(int[], int, int&); void showArray(const int[], int); int main() {    int values[25] = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24...

  • Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers

    Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...

  • In C++: 1. What is the difference between a deterministic algorithm and a randomized algorithm? 2....

    In C++: 1. What is the difference between a deterministic algorithm and a randomized algorithm? 2. What is the difference between a Las Vegas algorithm (pattern) and a Monte Carlo algorithm? 3. Solve the following recurrences, giving the answer in terms of Big-Oh O() F (n) = 4F ( 1 ) +no F (n) = 2 F (*) +2 4. Given the string "DECEMBER", execute the mergesort algorithm by hand to sort it. Show your work to make it clear...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT