SlideShare a Scribd company logo
I have written the code but cannot complete the assignment please help me to complete.
Please don't just copy other s answers as your own.
// Insertion sort
/*
#include <ctime>
#include <iostream>
using namespace std;
void insertionSort(int arr[], int n) {
int i, key, j;
for (i = 1; i < n; i++) {
key = arr[i];
j = i - 1;
// Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current
position
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int num = sizeof(arr) / sizeof(arr[0]);
clock_t start, end;
double timetaken;
start = clock();
insertionSort(arr, num);
end = clock();
cout << "Sorted array: n";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
cout << endl;
timetaken = ((double) (end - start)) / CLOCKS_PER_SEC;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
return 0;
}
*/
// Shell Sort
/*
#include <ctime>
#include <iostream>
using namespace std;
int shellSort(int arr[], int n) {
for (int gap = n/2; gap > 0; gap /= 2) {
for (int i = gap; i < n; i += 1) {
int temp = arr[i];
int j;
for (j = i; j >= gap && arr[j - gap] > temp; j -= gap)
arr[j] = arr[j - gap];
arr[j] = temp;
}
}
return 0;
}
void printArray(int arr[], int n) {
for (int i=0; i<n; i++)
cout << arr[i] << " ";
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int num = sizeof(arr) / sizeof(arr[0]);
clock_t start, end;
double timetaken;
start = clock();
shellSort(arr, num);
end = clock();
cout << "nArray after sorting: n";
printArray(arr, n);
cout << endl;
timetaken = (double)(end - start) / CLOCKS_PER_SEC;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
return 0;
}
*/
// MergeSort
/*
#include <ctime>
#include <iostream>
using namespace std;
void merge(int arr[], int l, int m, int r) {
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1 + j];
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
}
else {
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
void mergeSort(int arr[], int l, int r) {
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int arr_size = sizeof(arr) / sizeof(arr[0]);
clock_t start;
clock_t end;
double timetaken;
start = clock();
mergeSort(arr, 0, arr_size - 1);
end = clock();
timetaken = (double)(end - start) / CLOCKS_PER_SEC;
cout << "nSorted array is n";
for (int i = 0; i < arr_size; i++)
cout << arr[i] << " ";
cout << endl;
cout << "Time taken: " << fixed << timetaken << " s" << endl;
return 0;
}
*/
// Radix Sort
/*
#include <ctime>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void countingSort(vector<int>& arr, int exp)
{
int n = arr.size();
vector<int> output(n);
vector<int> count(10, 0);
for (int i = 0; i < n; i++)
count[(arr[i] / exp) % 10]++;
for (int i = 1; i < 10; i++)
count[i] += count[i - 1];
for (int i = n - 1; i >= 0; i--) {
output[count[(arr[i] / exp) % 10] - 1] = arr[i];
count[(arr[i] / exp) % 10]--;
}
for (int i = 0; i < n; i++)
arr[i] = output[i];
}
void radixSort(vector<int>& arr)
{
int n = arr.size();
int max_val = *max_element(arr.begin(), arr.end());
for (int exp = 1; max_val / exp > 0; exp *= 10)
countingSort(arr, exp);
}
int main()
{
int n;
cout << "Enter the size of the array: ";
cin >> n;
vector<int> arr(n);
cout << "Enter " << n << " integers: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
clock_t start;
clock_t end;
double timetaken;
start = clock();
radixSort(arr);
end = clock();
timetaken = (end - start) / (double)CLOCKS_PER_SEC;
cout << "Sorted array: ";
for (int x : arr)
cout << x << " ";
cout << endl;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
return 0;
}
*/
// std::sort
/*
#include <ctime>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n;
cout << "Enter the size of the array: ";
cin >> n;
vector<int> arr(n);
cout << "Enter " << n << " integers: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
clock_t start = clock();
sort(arr.begin(), arr.end());
clock_t end = clock();
double timetaken = double(end - start) / CLOCKS_PER_SEC;
cout << "Sorted array: ";
for (int x : arr) {
cout << x << " ";
}
cout << endl;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
return 0;
}
*/
#include <ctime>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n;
cout << "Enter the size of the array: ";
cin >> n;
vector<int> arr(n);
cout << "Enter " << n << " integers: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
clock_t start;
clock_t end;
double timetaken;
// pre-sorted
start = clock();
sort(arr.begin(), arr.end());
end = clock();
timetaken = (end - start) / (double)CLOCKS_PER_SEC;
cout << "Pre-sorted array: ";
for (int x : arr) {
cout << x << " ";
}
cout << endl;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
// reverse-sorted
reverse(arr.begin(), arr.end());
start = clock();
sort(arr.begin(), arr.end());
end = clock();
timetaken = (end - start) / (double)CLOCKS_PER_SEC;
cout << "Reverse-sorted array: ";
for (int x : arr) {
cout << x << " ";
}
cout << endl;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
// rand%N
random_shuffle(arr.begin(), arr.end());
start = clock();
sort(arr.begin(), arr.end());
end = clock();
timetaken = (end - start) / (double)CLOCKS_PER_SEC;
cout << "Rand%N array: ";
for (int x : arr) {
cout << x << " ";
}
cout << endl;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
// rand%10
for (int i = 0; i < n; i++) {
arr[i] = rand() % 10;
}
start = clock();
sort(arr.begin(), arr.end());
end = clock();
timetaken = (end - start) / (double)CLOCKS_PER_SEC;
cout << "Rand%10 array: ";
for (int x : arr) {
cout << x << " ";
}
cout << endl;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
// zeros
for (int i = 0; i < n; i++) {
arr[i] = 0;
}
start = clock();
sort(arr.begin(), arr.end());
end = clock();
timetaken = (end - start) / (double)CLOCKS_PER_SEC;
cout << "Zeros array: ";
for (int x : arr) {
cout << x << " ";
}
cout << endl;
cout << "Time taken : " << fixed << timetaken << "s" << endl;
return 0;
}
Sorting experiments In this assignment, you will implement 5 different sorting algorithms and
test their performance on different types of input. You may use any of the code provided on
moodle so far. Algorithms: - Insertion sort - Shell sort - Mergesort - Quicksort - Radix sort -
std::sort (on std::vector, it is already implemented in ) Input types - Pre-sorted array from 1..N -
Reverse-sorted array from N..1 - Random array with few duplicates (use rand()%N) - Array
with many duplicates (use rand()%10) - Array of all duplicates (all zeros) For each type of input
array, test on 5 different sizes: N = 100 , N = 1000 , N = 10000 , N = 100000 , N = 1000000
Results: Provide the results of your sorting experiments in 5 separate tables (one for each input
size) as follow: Discuss and justify your results. Which algorithm performs best overall (when
averaging across all input sizes and input types)? Be sure to mention time complexity when
discussing your results. Also, be sure to used std::move whenever possible in your c + +
implementations, and test in release mode. Submit your c++ source code as well as a pdf
containing your name, the required tables ( 5 x ) and your discussion of the results. if an
algorithm takes > 2 minutes on any of the input sizes, you can stop the Bonus + 5 % : improving
your sorting algorithms - Use insertion sort on the divided sub-arrays of mergesort once they get
below a certain size - This speeds up mergesort because it removes the need for copying
elements into new arrays, which adds a lot of overhead to the running time - Use a random pivot
for quicksort to improve its running time on the pre-sorted and reversesorted arrays - Try
different gap sequences for shell sort

More Related Content

Similar to I have written the code but cannot complete the assignment please help.pdf (20)

Merge radix-sort-algorithm
Merge radix-sort-algorithmMerge radix-sort-algorithm
Merge radix-sort-algorithm
Rendell Inocencio
 
Merge radix-sort-algorithm
Merge radix-sort-algorithmMerge radix-sort-algorithm
Merge radix-sort-algorithm
Rendell Inocencio
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
乐群 陈
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
Pranav Ghildiyal
 
Ds program-print
Ds program-printDs program-print
Ds program-print
Chaitanya Kn
 
ch16.pptx
ch16.pptxch16.pptx
ch16.pptx
lordaragorn2
 
ch16 (1).pptx
ch16 (1).pptxch16 (1).pptx
ch16 (1).pptx
lordaragorn2
 
Programming Fundamentals lecture-14.pptx
Programming Fundamentals lecture-14.pptxProgramming Fundamentals lecture-14.pptx
Programming Fundamentals lecture-14.pptx
singyali199
 
C++ practical
C++ practicalC++ practical
C++ practical
Rahul juneja
 
Chapter Two.pdf
Chapter Two.pdfChapter Two.pdf
Chapter Two.pdf
abay golla
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdf
apexelectronices01
 
Sortings
SortingsSortings
Sortings
maamir farooq
 
Implement a function in c++ which takes in a vector of integers and .pdf
Implement a function in c++ which takes in a vector of integers and .pdfImplement a function in c++ which takes in a vector of integers and .pdf
Implement a function in c++ which takes in a vector of integers and .pdf
feelingspaldi
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
josies1
 
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
BANSALANKIT1077
 
lecture7.ppt
lecture7.pptlecture7.ppt
lecture7.ppt
EdFeranil
 
its arrays ppt for first year students .
its arrays ppt for first year students .its arrays ppt for first year students .
its arrays ppt for first year students .
anilkumaralaparthi6
 
C++ adt c++ implementations
C++   adt c++ implementationsC++   adt c++ implementations
C++ adt c++ implementations
Rex Mwamba
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx
ajoy21
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
BackPack3
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
乐群 陈
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
Pranav Ghildiyal
 
Programming Fundamentals lecture-14.pptx
Programming Fundamentals lecture-14.pptxProgramming Fundamentals lecture-14.pptx
Programming Fundamentals lecture-14.pptx
singyali199
 
Chapter Two.pdf
Chapter Two.pdfChapter Two.pdf
Chapter Two.pdf
abay golla
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdf
apexelectronices01
 
Implement a function in c++ which takes in a vector of integers and .pdf
Implement a function in c++ which takes in a vector of integers and .pdfImplement a function in c++ which takes in a vector of integers and .pdf
Implement a function in c++ which takes in a vector of integers and .pdf
feelingspaldi
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
josies1
 
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
BANSALANKIT1077
 
lecture7.ppt
lecture7.pptlecture7.ppt
lecture7.ppt
EdFeranil
 
its arrays ppt for first year students .
its arrays ppt for first year students .its arrays ppt for first year students .
its arrays ppt for first year students .
anilkumaralaparthi6
 
C++ adt c++ implementations
C++   adt c++ implementationsC++   adt c++ implementations
C++ adt c++ implementations
Rex Mwamba
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx
ajoy21
 
#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf#include algorithm #include vector #include iostream usi.pdf
#include algorithm #include vector #include iostream usi.pdf
BackPack3
 

More from shreeaadithyaacellso (20)

In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdfIn c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
shreeaadithyaacellso
 
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdfIn Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
shreeaadithyaacellso
 
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdfIn C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
shreeaadithyaacellso
 
In C Programming- not C++ Write a function which takes two formal pa.pdf
In C Programming- not C++   Write a function which takes two formal pa.pdfIn C Programming- not C++   Write a function which takes two formal pa.pdf
In C Programming- not C++ Write a function which takes two formal pa.pdf
shreeaadithyaacellso
 
In chapter 17 you learned about the big picture of circulation through.pdf
In chapter 17 you learned about the big picture of circulation through.pdfIn chapter 17 you learned about the big picture of circulation through.pdf
In chapter 17 you learned about the big picture of circulation through.pdf
shreeaadithyaacellso
 
In cell M11- enter a formula that will calculate the total amount due.pdf
In cell M11- enter a formula that will calculate the total amount due.pdfIn cell M11- enter a formula that will calculate the total amount due.pdf
In cell M11- enter a formula that will calculate the total amount due.pdf
shreeaadithyaacellso
 
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdfIn C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
shreeaadithyaacellso
 
In C++ Complete the program with the bold requirements #include #i.pdf
In C++  Complete the program with the bold requirements   #include  #i.pdfIn C++  Complete the program with the bold requirements   #include  #i.pdf
In C++ Complete the program with the bold requirements #include #i.pdf
shreeaadithyaacellso
 
I am studying for a test tomorrow in my 494 Population Biology class-.pdf
I am studying for a test tomorrow in my 494 Population Biology class-.pdfI am studying for a test tomorrow in my 494 Population Biology class-.pdf
I am studying for a test tomorrow in my 494 Population Biology class-.pdf
shreeaadithyaacellso
 
I got the codes written down below- Basically- I am trying to implemen.pdf
I got the codes written down below- Basically- I am trying to implemen.pdfI got the codes written down below- Basically- I am trying to implemen.pdf
I got the codes written down below- Basically- I am trying to implemen.pdf
shreeaadithyaacellso
 
I am trying to write a program that will converts a 32bit float number.pdf
I am trying to write a program that will converts a 32bit float number.pdfI am trying to write a program that will converts a 32bit float number.pdf
I am trying to write a program that will converts a 32bit float number.pdf
shreeaadithyaacellso
 
I am stuck on this question- please show the solution step by step- Re.pdf
I am stuck on this question- please show the solution step by step- Re.pdfI am stuck on this question- please show the solution step by step- Re.pdf
I am stuck on this question- please show the solution step by step- Re.pdf
shreeaadithyaacellso
 
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdfI et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
shreeaadithyaacellso
 
I am working on a coding project- and it asked me to combine five sets.pdf
I am working on a coding project- and it asked me to combine five sets.pdfI am working on a coding project- and it asked me to combine five sets.pdf
I am working on a coding project- and it asked me to combine five sets.pdf
shreeaadithyaacellso
 
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdfI am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
shreeaadithyaacellso
 
i cant figure out this excel equation For the Year Ended December 31-.pdf
i cant figure out this excel equation For the Year Ended December 31-.pdfi cant figure out this excel equation For the Year Ended December 31-.pdf
i cant figure out this excel equation For the Year Ended December 31-.pdf
shreeaadithyaacellso
 
I am writing a program that will allow the user to move the crosshairs.pdf
I am writing a program that will allow the user to move the crosshairs.pdfI am writing a program that will allow the user to move the crosshairs.pdf
I am writing a program that will allow the user to move the crosshairs.pdf
shreeaadithyaacellso
 
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdfI need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
shreeaadithyaacellso
 
I need hlep I have posted this proble 4 times have gotten no help can.pdf
I need hlep I have posted this proble 4 times have gotten no help can.pdfI need hlep I have posted this proble 4 times have gotten no help can.pdf
I need hlep I have posted this proble 4 times have gotten no help can.pdf
shreeaadithyaacellso
 
I need question 1 answer in java language- question 1)Create an applic.pdf
I need question 1 answer in java language- question 1)Create an applic.pdfI need question 1 answer in java language- question 1)Create an applic.pdf
I need question 1 answer in java language- question 1)Create an applic.pdf
shreeaadithyaacellso
 
In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdfIn c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
shreeaadithyaacellso
 
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdfIn Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
shreeaadithyaacellso
 
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdfIn C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
shreeaadithyaacellso
 
In C Programming- not C++ Write a function which takes two formal pa.pdf
In C Programming- not C++   Write a function which takes two formal pa.pdfIn C Programming- not C++   Write a function which takes two formal pa.pdf
In C Programming- not C++ Write a function which takes two formal pa.pdf
shreeaadithyaacellso
 
In chapter 17 you learned about the big picture of circulation through.pdf
In chapter 17 you learned about the big picture of circulation through.pdfIn chapter 17 you learned about the big picture of circulation through.pdf
In chapter 17 you learned about the big picture of circulation through.pdf
shreeaadithyaacellso
 
In cell M11- enter a formula that will calculate the total amount due.pdf
In cell M11- enter a formula that will calculate the total amount due.pdfIn cell M11- enter a formula that will calculate the total amount due.pdf
In cell M11- enter a formula that will calculate the total amount due.pdf
shreeaadithyaacellso
 
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdfIn C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
shreeaadithyaacellso
 
In C++ Complete the program with the bold requirements #include #i.pdf
In C++  Complete the program with the bold requirements   #include  #i.pdfIn C++  Complete the program with the bold requirements   #include  #i.pdf
In C++ Complete the program with the bold requirements #include #i.pdf
shreeaadithyaacellso
 
I am studying for a test tomorrow in my 494 Population Biology class-.pdf
I am studying for a test tomorrow in my 494 Population Biology class-.pdfI am studying for a test tomorrow in my 494 Population Biology class-.pdf
I am studying for a test tomorrow in my 494 Population Biology class-.pdf
shreeaadithyaacellso
 
I got the codes written down below- Basically- I am trying to implemen.pdf
I got the codes written down below- Basically- I am trying to implemen.pdfI got the codes written down below- Basically- I am trying to implemen.pdf
I got the codes written down below- Basically- I am trying to implemen.pdf
shreeaadithyaacellso
 
I am trying to write a program that will converts a 32bit float number.pdf
I am trying to write a program that will converts a 32bit float number.pdfI am trying to write a program that will converts a 32bit float number.pdf
I am trying to write a program that will converts a 32bit float number.pdf
shreeaadithyaacellso
 
I am stuck on this question- please show the solution step by step- Re.pdf
I am stuck on this question- please show the solution step by step- Re.pdfI am stuck on this question- please show the solution step by step- Re.pdf
I am stuck on this question- please show the solution step by step- Re.pdf
shreeaadithyaacellso
 
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdfI et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
shreeaadithyaacellso
 
I am working on a coding project- and it asked me to combine five sets.pdf
I am working on a coding project- and it asked me to combine five sets.pdfI am working on a coding project- and it asked me to combine five sets.pdf
I am working on a coding project- and it asked me to combine five sets.pdf
shreeaadithyaacellso
 
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdfI am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
shreeaadithyaacellso
 
i cant figure out this excel equation For the Year Ended December 31-.pdf
i cant figure out this excel equation For the Year Ended December 31-.pdfi cant figure out this excel equation For the Year Ended December 31-.pdf
i cant figure out this excel equation For the Year Ended December 31-.pdf
shreeaadithyaacellso
 
I am writing a program that will allow the user to move the crosshairs.pdf
I am writing a program that will allow the user to move the crosshairs.pdfI am writing a program that will allow the user to move the crosshairs.pdf
I am writing a program that will allow the user to move the crosshairs.pdf
shreeaadithyaacellso
 
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdfI need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
shreeaadithyaacellso
 
I need hlep I have posted this proble 4 times have gotten no help can.pdf
I need hlep I have posted this proble 4 times have gotten no help can.pdfI need hlep I have posted this proble 4 times have gotten no help can.pdf
I need hlep I have posted this proble 4 times have gotten no help can.pdf
shreeaadithyaacellso
 
I need question 1 answer in java language- question 1)Create an applic.pdf
I need question 1 answer in java language- question 1)Create an applic.pdfI need question 1 answer in java language- question 1)Create an applic.pdf
I need question 1 answer in java language- question 1)Create an applic.pdf
shreeaadithyaacellso
 
Ad

Recently uploaded (20)

How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Ad

I have written the code but cannot complete the assignment please help.pdf

  • 1. I have written the code but cannot complete the assignment please help me to complete. Please don't just copy other s answers as your own. // Insertion sort /* #include <ctime> #include <iostream> using namespace std; void insertionSort(int arr[], int n) { int i, key, j; for (i = 1; i < n; i++) { key = arr[i]; j = i - 1; // Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current position while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j = j - 1; } arr[j + 1] = key; } } int main() { int n; cout << "Enter the size of the array: ";
  • 2. cin >> n; int arr[n]; cout << "Enter the elements of the array: "; for (int i = 0; i < n; i++) { cin >> arr[i]; } int num = sizeof(arr) / sizeof(arr[0]); clock_t start, end; double timetaken; start = clock(); insertionSort(arr, num); end = clock(); cout << "Sorted array: n"; for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; timetaken = ((double) (end - start)) / CLOCKS_PER_SEC; cout << "Time taken : " << fixed << timetaken << "s" << endl; return 0; } */ // Shell Sort
  • 3. /* #include <ctime> #include <iostream> using namespace std; int shellSort(int arr[], int n) { for (int gap = n/2; gap > 0; gap /= 2) { for (int i = gap; i < n; i += 1) { int temp = arr[i]; int j; for (j = i; j >= gap && arr[j - gap] > temp; j -= gap) arr[j] = arr[j - gap]; arr[j] = temp; } } return 0; } void printArray(int arr[], int n) { for (int i=0; i<n; i++) cout << arr[i] << " "; } int main() { int n; cout << "Enter the size of the array: ";
  • 4. cin >> n; int arr[n]; cout << "Enter the elements of the array: "; for (int i = 0; i < n; i++) { cin >> arr[i]; } int num = sizeof(arr) / sizeof(arr[0]); clock_t start, end; double timetaken; start = clock(); shellSort(arr, num); end = clock(); cout << "nArray after sorting: n"; printArray(arr, n); cout << endl; timetaken = (double)(end - start) / CLOCKS_PER_SEC; cout << "Time taken : " << fixed << timetaken << "s" << endl; return 0; } */ // MergeSort /* #include <ctime>
  • 5. #include <iostream> using namespace std; void merge(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; int L[n1], R[n2]; for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1 + j]; i = 0; j = 0; k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; }
  • 6. k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } void mergeSort(int arr[], int l, int r) { if (l < r) { int m = l + (r - l) / 2; mergeSort(arr, l, m); mergeSort(arr, m + 1, r); merge(arr, l, m, r); } } int main() { int n;
  • 7. cout << "Enter the size of the array: "; cin >> n; int arr[n]; cout << "Enter the elements of the array: "; for (int i = 0; i < n; i++) { cin >> arr[i]; } int arr_size = sizeof(arr) / sizeof(arr[0]); clock_t start; clock_t end; double timetaken; start = clock(); mergeSort(arr, 0, arr_size - 1); end = clock(); timetaken = (double)(end - start) / CLOCKS_PER_SEC; cout << "nSorted array is n"; for (int i = 0; i < arr_size; i++) cout << arr[i] << " "; cout << endl; cout << "Time taken: " << fixed << timetaken << " s" << endl; return 0; } */
  • 8. // Radix Sort /* #include <ctime> #include <iostream> #include <algorithm> #include <vector> using namespace std; void countingSort(vector<int>& arr, int exp) { int n = arr.size(); vector<int> output(n); vector<int> count(10, 0); for (int i = 0; i < n; i++) count[(arr[i] / exp) % 10]++; for (int i = 1; i < 10; i++) count[i] += count[i - 1]; for (int i = n - 1; i >= 0; i--) { output[count[(arr[i] / exp) % 10] - 1] = arr[i]; count[(arr[i] / exp) % 10]--; } for (int i = 0; i < n; i++) arr[i] = output[i]; }
  • 9. void radixSort(vector<int>& arr) { int n = arr.size(); int max_val = *max_element(arr.begin(), arr.end()); for (int exp = 1; max_val / exp > 0; exp *= 10) countingSort(arr, exp); } int main() { int n; cout << "Enter the size of the array: "; cin >> n; vector<int> arr(n); cout << "Enter " << n << " integers: "; for (int i = 0; i < n; i++) { cin >> arr[i]; } clock_t start; clock_t end; double timetaken; start = clock(); radixSort(arr); end = clock();
  • 10. timetaken = (end - start) / (double)CLOCKS_PER_SEC; cout << "Sorted array: "; for (int x : arr) cout << x << " "; cout << endl; cout << "Time taken : " << fixed << timetaken << "s" << endl; return 0; } */ // std::sort /* #include <ctime> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cout << "Enter the size of the array: "; cin >> n; vector<int> arr(n); cout << "Enter " << n << " integers: ";
  • 11. for (int i = 0; i < n; i++) { cin >> arr[i]; } clock_t start = clock(); sort(arr.begin(), arr.end()); clock_t end = clock(); double timetaken = double(end - start) / CLOCKS_PER_SEC; cout << "Sorted array: "; for (int x : arr) { cout << x << " "; } cout << endl; cout << "Time taken : " << fixed << timetaken << "s" << endl; return 0; } */ #include <ctime> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() {
  • 12. int n; cout << "Enter the size of the array: "; cin >> n; vector<int> arr(n); cout << "Enter " << n << " integers: "; for (int i = 0; i < n; i++) { cin >> arr[i]; } clock_t start; clock_t end; double timetaken; // pre-sorted start = clock(); sort(arr.begin(), arr.end()); end = clock(); timetaken = (end - start) / (double)CLOCKS_PER_SEC; cout << "Pre-sorted array: "; for (int x : arr) { cout << x << " "; } cout << endl; cout << "Time taken : " << fixed << timetaken << "s" << endl; // reverse-sorted
  • 13. reverse(arr.begin(), arr.end()); start = clock(); sort(arr.begin(), arr.end()); end = clock(); timetaken = (end - start) / (double)CLOCKS_PER_SEC; cout << "Reverse-sorted array: "; for (int x : arr) { cout << x << " "; } cout << endl; cout << "Time taken : " << fixed << timetaken << "s" << endl; // rand%N random_shuffle(arr.begin(), arr.end()); start = clock(); sort(arr.begin(), arr.end()); end = clock(); timetaken = (end - start) / (double)CLOCKS_PER_SEC; cout << "Rand%N array: "; for (int x : arr) { cout << x << " "; } cout << endl; cout << "Time taken : " << fixed << timetaken << "s" << endl;
  • 14. // rand%10 for (int i = 0; i < n; i++) { arr[i] = rand() % 10; } start = clock(); sort(arr.begin(), arr.end()); end = clock(); timetaken = (end - start) / (double)CLOCKS_PER_SEC; cout << "Rand%10 array: "; for (int x : arr) { cout << x << " "; } cout << endl; cout << "Time taken : " << fixed << timetaken << "s" << endl; // zeros for (int i = 0; i < n; i++) { arr[i] = 0; } start = clock(); sort(arr.begin(), arr.end()); end = clock(); timetaken = (end - start) / (double)CLOCKS_PER_SEC; cout << "Zeros array: ";
  • 15. for (int x : arr) { cout << x << " "; } cout << endl; cout << "Time taken : " << fixed << timetaken << "s" << endl; return 0; } Sorting experiments In this assignment, you will implement 5 different sorting algorithms and test their performance on different types of input. You may use any of the code provided on moodle so far. Algorithms: - Insertion sort - Shell sort - Mergesort - Quicksort - Radix sort - std::sort (on std::vector, it is already implemented in ) Input types - Pre-sorted array from 1..N - Reverse-sorted array from N..1 - Random array with few duplicates (use rand()%N) - Array with many duplicates (use rand()%10) - Array of all duplicates (all zeros) For each type of input array, test on 5 different sizes: N = 100 , N = 1000 , N = 10000 , N = 100000 , N = 1000000 Results: Provide the results of your sorting experiments in 5 separate tables (one for each input size) as follow: Discuss and justify your results. Which algorithm performs best overall (when averaging across all input sizes and input types)? Be sure to mention time complexity when discussing your results. Also, be sure to used std::move whenever possible in your c + + implementations, and test in release mode. Submit your c++ source code as well as a pdf containing your name, the required tables ( 5 x ) and your discussion of the results. if an algorithm takes > 2 minutes on any of the input sizes, you can stop the Bonus + 5 % : improving your sorting algorithms - Use insertion sort on the divided sub-arrays of mergesort once they get below a certain size - This speeds up mergesort because it removes the need for copying elements into new arrays, which adds a lot of overhead to the running time - Use a random pivot for quicksort to improve its running time on the pre-sorted and reversesorted arrays - Try different gap sequences for shell sort