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; }.