Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need the following C++ code listed below to fit the information that is provided: #include #include #include #include #define N 20 using namespace std;

I need the following C++ code listed below to fit the information that is provided:

#include #include #include #include #define N 20

using namespace std;

void swap(int A[], int i, int min); bool small(int a, int b); void print(int A[]); void fillRandom(int A[], int size);

void sort(int A[], int lo, int hi); int partition(int A[], int lo, int hi);

int main(int argc, const char * argv[]) { int A[N]={0}; fillRandom(A,N); print(A); //Shuffle(A); shuffle the array. commented out for now sort(A, 0, N-1); print(A); }

void sort(int A[], int lo, int hi) { if (hi int j = partition(A, lo, hi); sort(A, lo, j-1); sort(A, j+1, hi); }

int partition(int A[], int lo, int hi) { int i = lo, j = hi+1; while (true) { while (small(A[++i], A[lo])) // find item on left to swap if (i == hi) break;

while (small(A[lo], A[--j])) // find item on right to swap if (j == lo) break; if (i >= j) break; //check if pointers cross swap(A, i, j); } swap(A, lo, j); return j; // return index of item now known to be in place }

void swap(int A[], int i, int min) { int tmp= A[i]; A[i]=A[min]; A[min]=tmp; }

void fillRandom(int A[], int size) { for (int i = 0; i A[i]=rand() % 50; }

void print(int A[]) { for (int i = 0; i cout cout }

bool small(int a, int b) { if (a return false; }

This is the information that needs to be worked into the C++ code above:

Your task in this activity is to compare running time of radix sort on an array of integer using r=10 and r=100.

For decimal numbers, r=10, the size of the alphabet is 10 since there are 10 items in the set of {0, 1, ...9}. Because of this, size of the counter array is 10, which is given in the example code as int cnt[RB]= {0}.

We want to fasten radix sort by expanding size of the alphabet from 10 to 100. With r=100, the alphabet will be {00, 01, 02,... 97, 98, 99}.

Follow these steps:

  • Randomly create 64K integers between 100000 and 999999 and keep in array A. These are min and max 6-digits integers.
  • Copy A to another same size array B.
  • Sort A with regular radix sort (r=10). You process last digit per iteration, such as 5, 3, 1, 0, 9, and 7 for 790135. Report the running time.
  • Develop a new radix sort function to sort integers with r=100. You process last two digits per iteration, such as 35, 01, and 79 for 790135.
  • Sort B with with regular r=100 radix sort. Report the running time
  • Report speed-up in sorting, such as \"r=100 sorting is 4.5 times faster than r=10.\"

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions