Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose that we are given a sequence A of n positive real numbers (a, a2,.., an) to sort. a) (2 points) Can you use

  

Suppose that we are given a sequence A of n positive real numbers (a, a2,.., an) to sort. a) (2 points) Can you use Count Sort AS IS to sort A? Explain b) (28 points) How can you adapt Counting Sort to sort the sequence A? Clearly state your assumptions and describe clearly using pseudocode your new Counting Sort algorithm COUNTING-SORT (A, B, k) 1 2 3 4 5 6 7 8 9 10 11 12 let C[0..k] be a new array for i 0 to k C[i] = 0 for j 1 to A.length C[A[j]] = C[A[j]] + 1 // C[i] now contains the number of elements equal to i. for i=1 to k C[i] = C[i] + C [i 1] // C[i] now contains the number of elements less than or equal to i. for j = A.length downto 1 B[C[A[j]]]= A[j] = C[A[j]] = C[A[j]] - 1

Step by Step Solution

3.45 Rating (161 Votes )

There are 3 Steps involved in it

Step: 1

i We should not use counting sort AS IS for sorting infinite set of real numbers as Counting sort wi... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Programming questions