Question
Implement, in C++, the following three advanced sorting algorithms: merge sort, quick-sort, and heap sort. Investigate their performance over arrays of sizes n = 102, 103, 104, 105, and 106. For each of these sizes consider the following three types of input: randomly-generated integers between 1 and n (inclusive). You may use a distribution where each integer is equally likely. increasing integers 1, 2, ..., n. decreasing integer n, n - 1, . . ., 1. For each of the above types of data, generate a graph which compares input size with (actual) running time. In a brief report containing the graphs and conclusions that you've drawn from the experiment.
Explanation / Answer
#include #include #define max 5 /*Here we declare a Stack with the help of Structure where we used an Array to store the data in the array. The Top or Head of the stack is denoted by a integer data called top. */ struct stack { int top; //Data to hold top of stack stackarray[max]; //Data to hold stack item }; //This function is used to check wheter the stack is empty or not int isempty(tmp) struct stack tmp; { printf("%d",tmp.top); if (tmp.top==0) return 0; else return 1; } //This function is used to put an item in the stack. void push(tmp,item) struct stack *tmp; /*We have refrence the stack by pointer the value of stack is chaced by the func*/ int item; { if(tmp->top==max) printf("Data overflow "); else { tmp->top++; tmp->stackarray[tmp->top]=item; printf("The item is Push %d in %d ",item,tmp->top); } } //This is used to delete or take out an item from the stack. void pop(tmp) struct stack *tmp; { if(tmp->top==0) printf("Data underflow "); else { printf("The Data Poped is %d ",tmp->stackarray[tmp->top--]); } } void main() { int l; struct stack stk={0}; if(isempty(stk)) printf("Stack is Empty "); else printf("Stack is not empty "); for(l=1; l