{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Solutions of Theory of Algorithms assignment 8-2

# Solutions of Theory of Algorithms assignment 8-2 - time...

This preview shows pages 1–2. Sign up to view the full content.

Solutions of Theory of Algorithms Assignment 5 Problem 8-2 a. Choose a field in this record that is integer to sort according to it If key ==0 A1 = CountSort (A,B,k) Else A2=CountSort (A,B,k) Sorted Array = A1 + A2 b. Choose a field in this record that is integer to sort according to it BucketSort (A) c. Choose a field in this record that is integer to sort according to it QuickSort (A,p,r) d. We can use the radix sort to sort the array according to its key especially if they are all distinct keys. As the size of the array of records is n and the key we are sorting is of size b bits, so its running

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: time will be bn. e. COUNTING-SORT(A, B, k) 1 for i ← 0 to k 2 do C[i] ← 0 3 for j ← 1 to length[A] 4 do C[A[j]] ← C[A[j]] + 1 5 ▹ C[i] now contains the number of elements equal to i. 6 for i ← 1 to k 7 do C[i] ← C[i] + C[i - 1] 8 ▹ C[i] now contains the number of elements less than or equalto i. 9 for j ← length[A] downto 1 10 do Repeatedly move the displaced element (b = A[j]) to its sorted position (k). 11 b ← A[j] 12 k ← C[b] 13 C[b] ← C[b] − 1 14 A[j] ← a Now b must be moved to its sorted position 15 a ← b 16 j ← k 17 A[j] ← a...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Solutions of Theory of Algorithms assignment 8-2 - time...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online