Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I need help with my C++ code. It shows a stack overflow problem and needs to follow the following requeriments. Requeriments: Assignment Sorting Benchmark

Hi, I need help with my C++ code. It shows a stack overflow problem and needs to follow the following requeriments.

Requeriments:

Assignment Sorting

Benchmark each of the sorting methods listed below.

Insertion Sort

Bubble Sort

Selection Sort

Heap Sort.

Quick Sort.

Merge Sort.

Benchmark each of the above sorting methods for data sizes of 10000, 20000, 30000, 40000 and 50000. Display the results in a table as shown below. The table should have rows and columns. However, the rows and columns need not be separated by lines. Add two more columns for Selection and Insertion Sorts

Data Size

Heap Sort Time In Seconds

Merge Sort Time In Seconds

Quick Sort Time In Seconds

Bubble Sort

100000

200000

300000

400000

500000

Notes:

Do not use a local array for keeping data values. Use a global array for this purpose. You can use dynamically allocated arrays if you wish.

Generate the data using a random generator and store it in a global array for use in sorting. If you use a local array of large size, you will run out of stack space.

Calculate the time taken by a sort routine in seconds as below:

#include

clock_t start, finish; start =clock( ); //time in milliseconds sort( ); finish=clock( ); //time in milliseconds //the constant CLOCKS_PER_SEC below is equal to 1000 double duration = (double) ( (finish-start)/CLOCKS_PER_SEC ); //time in secs. cout

Code:

#include #include #include #include using namespace std; int *ins_el; int *bubble_el; int *sel_el; int *heap_el; int *quick_el; int *merge_el; void insertionSort(int n) { int i, j; int temp; for (i = 1; i 0 && ins_el[j] > temp) { ins_el[j + 1] = ins_el[j]; j = j - 1; } ins_el[j + 1] = temp; } } void bubbleSort(int n) { int i, j; for (i = 0; i bubble_el[j + 1]) { int t = bubble_el[j]; bubble_el[j] = bubble_el[j + 1]; bubble_el[j + 1] = t; } } } } void selectionSort(int n) { int i, j; for (i = 0; i sel_el[j]) { int temp = sel_el[i]; sel_el[i] = sel_el[j]; sel_el[j] = temp; } } } } void heapify(int n, int i) { int largest = i; int l = 2 * i + 1; int r = 2 * i + 2; if (l heap_el[largest]) largest = l; if (r heap_el[largest]) largest = r; if (largest != i) { int temp = heap_el[i]; heap_el[i] = heap_el[largest]; heap_el[largest] = temp; heapify(n, largest); } } void heapSort(int n) { int i = 0; for (i = n; i >= 0; i--) heapify(n, i); for (i = n; i > 0; i--) { int temp = heap_el[0]; heap_el[0] = heap_el[i]; heap_el[i] = temp; heapify(i, 0); } } int partition(int low, int high) { int pivot = quick_el[high]; int i = (low - 1), j; for (j = low; j

start = clock(); //time in milliseconds heapSort(i); finish = clock(); //time in milliseconds double heap_duration = (double)((finish - start) / CLOCKS_PER_SEC); //time in secs.

start = clock(); //time in milliseconds mergeSort(0, i - 1); finish = clock(); //time in milliseconds double merge_duration = (double)((finish - start) / CLOCKS_PER_SEC); //time in secs.

start = clock(); //time in milliseconds quickSort(0, i - 1); finish = clock(); //time in milliseconds double quick_duration = (double)((finish - start) / CLOCKS_PER_SEC); //time in secs.

start = clock(); //time in milliseconds bubbleSort(i); finish = clock(); //time in milliseconds //the constant CLOCKS_PER_SEC below is equal to 1000 double bubble_duration = (double)((finish - start) / CLOCKS_PER_SEC); //time in secs.

cout

}

system("pause"); return 0; }

Capture about the error:

image text in transcribed

80 Bvoid heapSort(int n) 81 82 83 84 85 86 87 heapify(n, i); for (i- n; Microsoft Visual Studio int temp-heap_el[e]; heap_el[0]heap_el[i]; heap-el[i] temp; heapify(i, 0); Unhandled exception at 0x01252E69 in Assignment 10.exe: OxC00000FD: Stack 89 90 91 92 93 int partition(int low, int high) 94 95 96 97 98 99 E 100 101 102 103 104 int pivot - quick el[high]: int i- (low 1), j; for (j low; j

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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

Provide a detailed mechanism for the following reaction. H,SO + H2O

Answered: 1 week ago