SlideShare a Scribd company logo
1 of 4
Download to read offline
please help me to find bugs in my coding! thanks!
#include
#include
#include
#include
#include
using namespace std;
using namespace std::chrono;
//heap sort function
void swap(int &p1, int &p2){
int temp = p1;
p1 = p2;
p2 = temp;
}
void maxheapify(vector &arr, int root, int length){
int left = 2*root;
int right = 2*root;
int l; //largest
if(left <= length && arr[left] > arr[root]){
l = left;
}else{
l = root;
}
if(right <=length && arr[right] > arr[l]){
l = right;
}
if(l != root){
swap(arr[l], arr[root]);
maxheapify(arr, l, length);
}
}
void buildmaxheap(vector arr){
for(int i = (int)arr.size()/2; i>=1; i--){
maxheapify(arr, i, (int)arr.size()-1);
}
}
void heapsort(vector &arr){
arr.insert(arr.begin(), 0);
buildmaxheap(arr);
int size= (int)arr.size() - 1;
for(int i = (int)arr.size()-1; i>=2; i--){
swap(arr[1], arr[i]);
size--;
maxheapify(arr, 1, size);
}
}
//insertion sort function
void insertionsort(int arr[], int n){
int i, k, j;
for(i = 1; i < n; i++){
k = arr[i];
j = i-1;
while(j>= 0 && arr[j] > k){
arr[j+1] = arr[j];
j = j-1;
}
arr[j+1] = k;
}
}
//merge sort function1
void merge(int arr[], int a, int b, int c){
int i, j, k;
int n1 = b - a +1;
int n2 = c - b;
int arr1[n1], arr2[n2];
for(i = 0; i < n1; i++){
arr1[i] = arr[a + i];
}
for(j = 0; j < n2; j++){
arr2[j] = arr[b + 1 +j];
}
i = 0;
j = 0;
k = a;
while( i < n1 && j < n2){
if(arr1[i] <= arr2[j]){
arr[k] = arr1[i];
i++;
}else{
arr[k] = arr2[j];
j++;
}
}
while( i < n1){
arr[k] = arr1[i];
i++;
k++;
}
while( j < n2){
arr[k] = arr2[j];
j++;
k++;
}
}
//merge sort function2
void mergesort(int arr[], int a, int b){
if(a < b){
int c = a + 0.5*(b - a);
mergesort(arr, a, c);
mergesort(arr, c+1, b);
merge(arr, a, c, b);
}
}
// Main function
int main() {
int n = 100;
while (n <= 100000) {
// Randomly generate array
int arr[n];
srand(time(NULL));
for (int i = 0; i < n; i++) {
arr[i] = rand() % n;
}
vector arr2;
arr2.insert(arr2.begin(), std::begin(arr), std::end(arr));
// Measure time for insertion sort
auto start_insertion = high_resolution_clock::now();
insertionsort(arr, n);
auto stop_insertion = high_resolution_clock::now();
auto duration_insertion = duration_cast(stop_insertion - start_insertion);
cout << "Insertion sort time for " << n << " elements: " << duration_insertion.count() << "
microseconds" << endl;
// Measure time for merge sort
auto start_merge = high_resolution_clock::now();
mergesort(arr, 0, n - 1);
auto stop_merge = high_resolution_clock::now();
auto duration_merge = duration_cast(stop_merge - start_merge);
cout << "Merge sort time for " << n << " elements: " << duration_merge.count() << "
microseconds" << endl;
// Measure time for heap sort
auto start_heap = high_resolution_clock::now();
heapsort(arr2);
auto stop_heap = high_resolution_clock::now();
auto duration_heap = duration_cast(stop_heap - start_heap);
cout << "Heap sort time for " << n << " elements: " << duration_heap.count() << "
microseconds" << endl;
// Increase array size by 10x
n *= 10;
}
return 0;
}

More Related Content

Similar to please help me to find bugs in my coding! thanks!#includeiostream.pdf

#include iostream using namespace std; void InsertionSort(int .pdf
#include iostream using namespace std; void InsertionSort(int .pdf#include iostream using namespace std; void InsertionSort(int .pdf
#include iostream using namespace std; void InsertionSort(int .pdfbrijmote
 
i am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdfi am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdfANJALIENTERPRISES1
 
Write a program to implement and test the following sorting algorithm.docx
 Write a program to implement and test the following sorting algorithm.docx Write a program to implement and test the following sorting algorithm.docx
Write a program to implement and test the following sorting algorithm.docxajoy21
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CSAAKASH KUMAR
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matchingShakila Mahjabin
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturialWayne Tsai
 
Function recap
Function recapFunction recap
Function recapalish sha
 
Function recap
Function recapFunction recap
Function recapalish sha
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskellujihisa
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
I am asked to provide the testing cases for the following co.pdf
I am asked to provide the testing cases for the following co.pdfI am asked to provide the testing cases for the following co.pdf
I am asked to provide the testing cases for the following co.pdfacecomputertcr
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfaptcomputerzone
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfkostikjaylonshaewe47
 

Similar to please help me to find bugs in my coding! thanks!#includeiostream.pdf (20)

Lab 6 (1)
Lab 6 (1)Lab 6 (1)
Lab 6 (1)
 
#include iostream using namespace std; void InsertionSort(int .pdf
#include iostream using namespace std; void InsertionSort(int .pdf#include iostream using namespace std; void InsertionSort(int .pdf
#include iostream using namespace std; void InsertionSort(int .pdf
 
i am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdfi am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdf
 
Write a program to implement and test the following sorting algorithm.docx
 Write a program to implement and test the following sorting algorithm.docx Write a program to implement and test the following sorting algorithm.docx
Write a program to implement and test the following sorting algorithm.docx
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
 
Arrays
ArraysArrays
Arrays
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturial
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Vcs16
Vcs16Vcs16
Vcs16
 
Function recap
Function recapFunction recap
Function recap
 
Function recap
Function recapFunction recap
Function recap
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskell
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
I am asked to provide the testing cases for the following co.pdf
I am asked to provide the testing cases for the following co.pdfI am asked to provide the testing cases for the following co.pdf
I am asked to provide the testing cases for the following co.pdf
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 

More from amarrex323

Please help me with the linux commands for the following tasks. I am.pdf
Please help me with the linux commands for the following tasks. I am.pdfPlease help me with the linux commands for the following tasks. I am.pdf
Please help me with the linux commands for the following tasks. I am.pdfamarrex323
 
Please help make class diagram. below is final tableFinal Table.pdf
Please help make class diagram. below is final tableFinal Table.pdfPlease help make class diagram. below is final tableFinal Table.pdf
Please help make class diagram. below is final tableFinal Table.pdfamarrex323
 
please help me on the case! provide step by step explainations!.pdf
please help me on the case! provide step by step explainations!.pdfplease help me on the case! provide step by step explainations!.pdf
please help me on the case! provide step by step explainations!.pdfamarrex323
 
Please provide class diagram. 2) The admin module will allow car .pdf
Please provide class diagram. 2) The admin module will allow car .pdfPlease provide class diagram. 2) The admin module will allow car .pdf
Please provide class diagram. 2) The admin module will allow car .pdfamarrex323
 
Please Prove using pumping lemma 2. Show that the language Lnp={w{a,.pdf
Please Prove using pumping lemma 2. Show that the language Lnp={w{a,.pdfPlease Prove using pumping lemma 2. Show that the language Lnp={w{a,.pdf
Please Prove using pumping lemma 2. Show that the language Lnp={w{a,.pdfamarrex323
 
Please help me to solve this one! (a) Let X1,X2,�,Xn,Xn+1,�,X2n be.pdf
Please help me to solve this one! (a) Let X1,X2,�,Xn,Xn+1,�,X2n be.pdfPlease help me to solve this one! (a) Let X1,X2,�,Xn,Xn+1,�,X2n be.pdf
Please help me to solve this one! (a) Let X1,X2,�,Xn,Xn+1,�,X2n be.pdfamarrex323
 
Please make the program runs at O(nlogm) see arrayfun. h for doc.pdf
Please make the program runs at O(nlogm)  see arrayfun. h for doc.pdfPlease make the program runs at O(nlogm)  see arrayfun. h for doc.pdf
Please make the program runs at O(nlogm) see arrayfun. h for doc.pdfamarrex323
 
Please help me to critique this articleAgency Theory Perspect.pdf
Please help me to critique this articleAgency Theory Perspect.pdfPlease help me to critique this articleAgency Theory Perspect.pdf
Please help me to critique this articleAgency Theory Perspect.pdfamarrex323
 
please match each of these terms with the best description each o.pdf
please match each of these terms with the best description  each o.pdfplease match each of these terms with the best description  each o.pdf
please match each of these terms with the best description each o.pdfamarrex323
 
Please look at the customer-introduced variable and service designed.pdf
Please look at the customer-introduced variable and service designed.pdfPlease look at the customer-introduced variable and service designed.pdf
Please look at the customer-introduced variable and service designed.pdfamarrex323
 
Please I want an exact and correct answerQuality Management Modu.pdf
Please I want an exact and correct answerQuality Management Modu.pdfPlease I want an exact and correct answerQuality Management Modu.pdf
Please I want an exact and correct answerQuality Management Modu.pdfamarrex323
 
please i need help to write paper and which should be 5-8 pages i.pdf
please i need help to write paper  and which should be 5-8 pages i.pdfplease i need help to write paper  and which should be 5-8 pages i.pdf
please i need help to write paper and which should be 5-8 pages i.pdfamarrex323
 
please helpWrite the vhdl code of a delay flip flop with the .pdf
please helpWrite the vhdl code of  a delay flip flop with the .pdfplease helpWrite the vhdl code of  a delay flip flop with the .pdf
please helpWrite the vhdl code of a delay flip flop with the .pdfamarrex323
 
Please Help!5.list of all sentences along with criminals informati.pdf
Please Help!5.list of all sentences along with criminals informati.pdfPlease Help!5.list of all sentences along with criminals informati.pdf
Please Help!5.list of all sentences along with criminals informati.pdfamarrex323
 
please help asap!!! Alternation of generationsThe paragraph below.pdf
please help asap!!! Alternation of generationsThe paragraph below.pdfplease help asap!!! Alternation of generationsThe paragraph below.pdf
please help asap!!! Alternation of generationsThe paragraph below.pdfamarrex323
 
Please help with this question.Please help with this question. O.pdf
Please help with this question.Please help with this question. O.pdfPlease help with this question.Please help with this question. O.pdf
Please help with this question.Please help with this question. O.pdfamarrex323
 
please help implement the following in C. below are instructions and.pdf
please help implement the following in C. below are instructions and.pdfplease help implement the following in C. below are instructions and.pdf
please help implement the following in C. below are instructions and.pdfamarrex323
 
Please help me with this. Thank you. .pdf
Please help me with this. Thank you.                            .pdfPlease help me with this. Thank you.                            .pdf
Please help me with this. Thank you. .pdfamarrex323
 
Please help with ALL parts of the question. I will upvote if correct.pdf
Please help with ALL parts of the question. I will upvote if correct.pdfPlease help with ALL parts of the question. I will upvote if correct.pdf
Please help with ALL parts of the question. I will upvote if correct.pdfamarrex323
 
please help and include explanations for a better understanding than.pdf
please help and include explanations for a better understanding than.pdfplease help and include explanations for a better understanding than.pdf
please help and include explanations for a better understanding than.pdfamarrex323
 

More from amarrex323 (20)

Please help me with the linux commands for the following tasks. I am.pdf
Please help me with the linux commands for the following tasks. I am.pdfPlease help me with the linux commands for the following tasks. I am.pdf
Please help me with the linux commands for the following tasks. I am.pdf
 
Please help make class diagram. below is final tableFinal Table.pdf
Please help make class diagram. below is final tableFinal Table.pdfPlease help make class diagram. below is final tableFinal Table.pdf
Please help make class diagram. below is final tableFinal Table.pdf
 
please help me on the case! provide step by step explainations!.pdf
please help me on the case! provide step by step explainations!.pdfplease help me on the case! provide step by step explainations!.pdf
please help me on the case! provide step by step explainations!.pdf
 
Please provide class diagram. 2) The admin module will allow car .pdf
Please provide class diagram. 2) The admin module will allow car .pdfPlease provide class diagram. 2) The admin module will allow car .pdf
Please provide class diagram. 2) The admin module will allow car .pdf
 
Please Prove using pumping lemma 2. Show that the language Lnp={w{a,.pdf
Please Prove using pumping lemma 2. Show that the language Lnp={w{a,.pdfPlease Prove using pumping lemma 2. Show that the language Lnp={w{a,.pdf
Please Prove using pumping lemma 2. Show that the language Lnp={w{a,.pdf
 
Please help me to solve this one! (a) Let X1,X2,�,Xn,Xn+1,�,X2n be.pdf
Please help me to solve this one! (a) Let X1,X2,�,Xn,Xn+1,�,X2n be.pdfPlease help me to solve this one! (a) Let X1,X2,�,Xn,Xn+1,�,X2n be.pdf
Please help me to solve this one! (a) Let X1,X2,�,Xn,Xn+1,�,X2n be.pdf
 
Please make the program runs at O(nlogm) see arrayfun. h for doc.pdf
Please make the program runs at O(nlogm)  see arrayfun. h for doc.pdfPlease make the program runs at O(nlogm)  see arrayfun. h for doc.pdf
Please make the program runs at O(nlogm) see arrayfun. h for doc.pdf
 
Please help me to critique this articleAgency Theory Perspect.pdf
Please help me to critique this articleAgency Theory Perspect.pdfPlease help me to critique this articleAgency Theory Perspect.pdf
Please help me to critique this articleAgency Theory Perspect.pdf
 
please match each of these terms with the best description each o.pdf
please match each of these terms with the best description  each o.pdfplease match each of these terms with the best description  each o.pdf
please match each of these terms with the best description each o.pdf
 
Please look at the customer-introduced variable and service designed.pdf
Please look at the customer-introduced variable and service designed.pdfPlease look at the customer-introduced variable and service designed.pdf
Please look at the customer-introduced variable and service designed.pdf
 
Please I want an exact and correct answerQuality Management Modu.pdf
Please I want an exact and correct answerQuality Management Modu.pdfPlease I want an exact and correct answerQuality Management Modu.pdf
Please I want an exact and correct answerQuality Management Modu.pdf
 
please i need help to write paper and which should be 5-8 pages i.pdf
please i need help to write paper  and which should be 5-8 pages i.pdfplease i need help to write paper  and which should be 5-8 pages i.pdf
please i need help to write paper and which should be 5-8 pages i.pdf
 
please helpWrite the vhdl code of a delay flip flop with the .pdf
please helpWrite the vhdl code of  a delay flip flop with the .pdfplease helpWrite the vhdl code of  a delay flip flop with the .pdf
please helpWrite the vhdl code of a delay flip flop with the .pdf
 
Please Help!5.list of all sentences along with criminals informati.pdf
Please Help!5.list of all sentences along with criminals informati.pdfPlease Help!5.list of all sentences along with criminals informati.pdf
Please Help!5.list of all sentences along with criminals informati.pdf
 
please help asap!!! Alternation of generationsThe paragraph below.pdf
please help asap!!! Alternation of generationsThe paragraph below.pdfplease help asap!!! Alternation of generationsThe paragraph below.pdf
please help asap!!! Alternation of generationsThe paragraph below.pdf
 
Please help with this question.Please help with this question. O.pdf
Please help with this question.Please help with this question. O.pdfPlease help with this question.Please help with this question. O.pdf
Please help with this question.Please help with this question. O.pdf
 
please help implement the following in C. below are instructions and.pdf
please help implement the following in C. below are instructions and.pdfplease help implement the following in C. below are instructions and.pdf
please help implement the following in C. below are instructions and.pdf
 
Please help me with this. Thank you. .pdf
Please help me with this. Thank you.                            .pdfPlease help me with this. Thank you.                            .pdf
Please help me with this. Thank you. .pdf
 
Please help with ALL parts of the question. I will upvote if correct.pdf
Please help with ALL parts of the question. I will upvote if correct.pdfPlease help with ALL parts of the question. I will upvote if correct.pdf
Please help with ALL parts of the question. I will upvote if correct.pdf
 
please help and include explanations for a better understanding than.pdf
please help and include explanations for a better understanding than.pdfplease help and include explanations for a better understanding than.pdf
please help and include explanations for a better understanding than.pdf
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 

please help me to find bugs in my coding! thanks!#includeiostream.pdf

  • 1. please help me to find bugs in my coding! thanks! #include #include #include #include #include using namespace std; using namespace std::chrono; //heap sort function void swap(int &p1, int &p2){ int temp = p1; p1 = p2; p2 = temp; } void maxheapify(vector &arr, int root, int length){ int left = 2*root; int right = 2*root; int l; //largest if(left <= length && arr[left] > arr[root]){ l = left; }else{ l = root; } if(right <=length && arr[right] > arr[l]){ l = right; } if(l != root){ swap(arr[l], arr[root]); maxheapify(arr, l, length); } } void buildmaxheap(vector arr){ for(int i = (int)arr.size()/2; i>=1; i--){ maxheapify(arr, i, (int)arr.size()-1);
  • 2. } } void heapsort(vector &arr){ arr.insert(arr.begin(), 0); buildmaxheap(arr); int size= (int)arr.size() - 1; for(int i = (int)arr.size()-1; i>=2; i--){ swap(arr[1], arr[i]); size--; maxheapify(arr, 1, size); } } //insertion sort function void insertionsort(int arr[], int n){ int i, k, j; for(i = 1; i < n; i++){ k = arr[i]; j = i-1; while(j>= 0 && arr[j] > k){ arr[j+1] = arr[j]; j = j-1; } arr[j+1] = k; } } //merge sort function1 void merge(int arr[], int a, int b, int c){ int i, j, k; int n1 = b - a +1; int n2 = c - b; int arr1[n1], arr2[n2]; for(i = 0; i < n1; i++){ arr1[i] = arr[a + i]; } for(j = 0; j < n2; j++){
  • 3. arr2[j] = arr[b + 1 +j]; } i = 0; j = 0; k = a; while( i < n1 && j < n2){ if(arr1[i] <= arr2[j]){ arr[k] = arr1[i]; i++; }else{ arr[k] = arr2[j]; j++; } } while( i < n1){ arr[k] = arr1[i]; i++; k++; } while( j < n2){ arr[k] = arr2[j]; j++; k++; } } //merge sort function2 void mergesort(int arr[], int a, int b){ if(a < b){ int c = a + 0.5*(b - a); mergesort(arr, a, c); mergesort(arr, c+1, b); merge(arr, a, c, b); } } // Main function int main() {
  • 4. int n = 100; while (n <= 100000) { // Randomly generate array int arr[n]; srand(time(NULL)); for (int i = 0; i < n; i++) { arr[i] = rand() % n; } vector arr2; arr2.insert(arr2.begin(), std::begin(arr), std::end(arr)); // Measure time for insertion sort auto start_insertion = high_resolution_clock::now(); insertionsort(arr, n); auto stop_insertion = high_resolution_clock::now(); auto duration_insertion = duration_cast(stop_insertion - start_insertion); cout << "Insertion sort time for " << n << " elements: " << duration_insertion.count() << " microseconds" << endl; // Measure time for merge sort auto start_merge = high_resolution_clock::now(); mergesort(arr, 0, n - 1); auto stop_merge = high_resolution_clock::now(); auto duration_merge = duration_cast(stop_merge - start_merge); cout << "Merge sort time for " << n << " elements: " << duration_merge.count() << " microseconds" << endl; // Measure time for heap sort auto start_heap = high_resolution_clock::now(); heapsort(arr2); auto stop_heap = high_resolution_clock::now(); auto duration_heap = duration_cast(stop_heap - start_heap); cout << "Heap sort time for " << n << " elements: " << duration_heap.count() << " microseconds" << endl; // Increase array size by 10x n *= 10; } return 0; }