Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This program requires to be written in C++. Please provide comments on the code so that I might understand how it was achieved. Thank you
This program requires to be written in C++. Please provide comments on the code so that I might understand how it was achieved. Thank you in advance
Task Write the following functions: Function Description int bubble_sort_comparisons(int* arr, int n) [1 Point] int insertion_sort_comparisons(int* arr, int n) [2 Points] Returns the number of comparisons performed by Bubble Sort when sorting arr. Returns the number of comparisons performed by Insertion Sort when sorting arr. Returns an array of size n having exactly k inversions at the beginning of the array. int* generate_k_inversion(int k, int n) [2 Points] Task Write a function called test1() that uses bubble_sort_comparisons and insertion_sort_comparisons to print the table below, where n is the size of the array. Run the test by calling test1 in main. (2.5 Points] Bubble Sort - Best Bubble Sort - Worst Insertion Sort - Best Insertion Sort - Worst 0 0 1 2 0 1 1 1 3 3 3 6 6 6 10 10 4 6 000 W NO 10 15 15 15 21 21 21 28 28 28 36 36 36 10 45 45 45 Task Write a function called test20) (which will be called in main) that 1- Uses generate_k_inversion to generate 11 arrays with sizes ne{5,6,7,8,9,10,11,12,13,14,15) each having n/4 inversions. 2- Then calls bubble_sort_comparisons and insertion_sort_comparisons on each array to print the following table: n bubble sort comparisons insertion sort comparisons 5 6 4 5 6 8 8 9 10 11 12 13 14 15 10 15 21 28 36 45 55 66 78 91 105 10 11 13 14 15 16Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started