Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Race between Selection sort and Bubble sort Implement both selection sort and bubble sort, so that they sort an array of strings into ascending

A Race between Selection sort and Bubble sort Implement both selection sort and bubble sort, so that they sort an array of strings into ascending order. Accept a number form the command line, and create two identical copies of an array of random ten character strings of that length. Measure how long selection sort takes to sort one array. Measure how long bubble sort takes to sort the other copy. Repeat the experiment for a number of different array sizes, and provide some meaningful conclusions about the algorithms' relative speeds. Here is a special timing function you can include. #include  #include  double get_cpu_time() { struct rusage ruse; getrusage(RUSAGE_SELF, &ruse); return ruse.ru_utime.tv_sec+ruse.ru_utime.tv_usec/1000000.0 + ruse.ru_stime.tv_sec+ruse.ru_stime.tv_usec/1000000.0; } Example run: a.out 10000 It took 3.179 seconds for selection sort to sort 10000 strings It took 3.330 seconds for bubble sort to sort the same strings. 

this might be helpful hint that is needed to be used in the code :-

image text in transcribed

#include #include #include #include using namespace std; double get cpu time() struct rusage ruse; getrusage (RUSAGE_SELF, &ruse); return ruse.ru utime.tv sec+ruse.ru utime.tv usec/1000000.0+ ruse.ru stime.tv sec+ruse.ru stime.tv usec/1000000.0: void selection_sort (string A[], int N) int sum = 0; for (int i - 0 i N; i +- 1) for (int j =0; j <>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

8.1. Using Eq. (8.4), determine when and .

Answered: 1 week ago

Question

7 years? (Round your answer to the nearest cent.)

Answered: 1 week ago