Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language is C++ Given the below algorithms. Compare both algorithms in terms of number of swaps, assignments and comparisons are done. Steps to follows are

Language is C++

Given the below algorithms. Compare both algorithms in terms of number of "swaps", "assignments" and "comparisons" are done.

Steps to follows are here:

- Define two char array with 8K and 16K items in them. Let's assume the first array is 8K, and second array on is 16K. Both arrays will be randomly fill out with numbers between -125 and +125. - Sort both arrays with selection sort and report how many "swaps", "assignments" and "comparisons" are done within each arrays. - Sort both arrays with insertion sort and report how many "swaps", and "comparisons" are done within each arrays.

Make sure that the arrays shuffles before second sort.

// Selection sort for (int i = 0; i < N; i++) { int min = i; for (int j = i+1; j < N; j++) { if ( small(A[j], A[min]) == true) min = j; // compare } swap(A, i, min); // swap } // Insertion sort for (int i = 0; i < N; i++) { for (int j = i; j > 0; j--) if ( small(A[j], A[j-1]) == true) // compare swap(A, j, j-1); // swap else break; }

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

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions

Question

Are robots going to displace all workers? Explain your answer.

Answered: 1 week ago