Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 2. [ 70 Points ] Rank Sort The RANK-SORT algorithm given in Figure 1 accepts an array of distinct numbers, and rearranges the numbers

image text in transcribed

Task 2. [ 70 Points ] Rank Sort The RANK-SORT algorithm given in Figure 1 accepts an array of distinct numbers, and rearranges the numbers in the array in increasing order of value. RANK-SORT (A) 1. 2. j = 1 while i S A. length k = 0 3. 4. 5. 6. 7. for i = 1 to A. length if A[i] = A[j] then k = k + 1 1/ swap Ali and A[k] A[k] A[] if k = j then j = i + 1 8. 9. 10. Figure 1: The RANK-SORT algorithm: input is an array A[1: n) of n distinct numbers (i.e., no two numbers in A are equal), and the output is A with its items sorted in increasing order of value. (a) [ 5 Points ] Describe in words (using only one sentence) as accurately as possible what the j-th iteration of the outer loop (in lines 2-10) is trying to do. meaning no two numbers in the array are equal (b) [ 5 Points ] Describe in words (using only one sentence) as accurately as possible what the inner loop (in lines 46) is trying to do in the j-th iteration of the outer loop (in lines 2-10). (c) ( 20 Points ] Using the example we used in the class to show how INSERTION-SORT and SELECTION-SORT work, show step-by-step how RANK-SORT works (i.e., sorts the numbers in that example) (d) ( 20 + 20 Points ) Analyze the worst-case and the best-case running times of RANK-SORT

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions