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. 

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

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

Students also viewed these Databases questions

Question

Find the exact value of expression. COS csc cos 2 2.

Answered: 1 week ago