Computers and Technology
Computers and Technology, 16.08.2021 23:40, normakite

Find the implementation of the sorting algorithms given below. I am trying to compare the efficiency of some of the sorting algorithms. I need to implement the algorithms for insertion sort, Merge Sort and Quicksort and use timing in C++ to compare the run time of the algorithms on inputs consisting of positive integers. I want to try the algorithms on input sizes of 1000, 10,000, 50,000, 100000, 150000, 200,000, 250,000, 300,000. The input can be generated randomly using the rand() function in C++. I need to use a vector structure in C++ STL to store the integers. Tabulate the results and plot the time Vs. input size. I must use the code provided below. I need to submit code with tabulated results and plot. Implementation of additional sorting algorithms will receive extra points. When testing algorithms, I need to use a small input (size 20) and print the list to make sure the algorithm sorts the list properly.
Code is given below:
#include
#include
#include
#include
using namespace std;
const int SIZE = 20;
void initializeList(vector& l)
{
//srand(time(0));
for (int i = 0; i < SIZE; i++)
l. push_back(rand() % 500);
}
template
void printVector(const vector& l)
{
cout << "Elements of the vector: ";
for (int i = 0; i < l. size(); i++)
cout << l[i] << " ";
cout << endl;
}
template
int linearSearch(const vector& l, T key)
{
for (int i = 0; i < l. size(); i++)
if (l[i] == key)
return i; // return first instance of the key. Function terminates
return -1; // search failed, return index -1.
}
//Binary Search iterative
template
int BinarySearchIterative(const vector& numbers, int numbersSize, T key)
{
int low = 0;
int mid= 0;
int high = numbersSize - 1;
while (high >= low)
{
mid = (low + high) / 2; // index of the middle element
if (numbers[mid] < key)
low = mid + 1;
else if (numbers[mid] > key)
high = mid - 1;
else if (numbers[mid] == key)
return mid;
}
return -1; // failed
}
//Binary Search Recursive
template
int BinarySearchRec(const vector& numbers, int low, int high, T key)
{
if (high < low)
return -1;
else
{
int mid = (low + high) / 2; // index of the middle element
if (numbers[mid] < key)
return BinarySearchRec(numbers, mid + 1, high, key);
else if (numbers[mid] > key)
return BinarySearchRec(numbers, low, mid-1, key);
else if (numbers[mid] == key)
return mid;
}
}
template
void selectionSort(vector& l)
{
for (int i = 0; i < l. size() -1 ; i++)
{
int minIndex = i;
for (int j = i+1; j < l. size(); j++)
if (l[minIndex] > l[j])
minIndex = j;
//swap elements in locations i and minIndex
T temp = l[i];
l[i] = l[minIndex];
l[minIndex] = temp;
}
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 02:00, vivian2020
Read this excerpt from helen keller’s autobiography, the story of my life. have you ever been at sea in a dense fog, when it seemed as if a tangible white darkness shut you in, and the great ship, tense and anxious, groped her way toward the shore with plummet and sounding-line, and you waited with beating heart for something to happen? i was like that ship before my education began, only i was without compass or sounding-line, and had no way of knowing how near the harbour was. "light! give me light! " was the wordless cry of my soul, and the light of love shone on me in that very hour. . the morning after my teacher came she led me into her room and gave me a doll. the little blind children at the perkins institution had sent it and laura bridgman had dressed it; but i did not know this until afterward. when i had played with it a little while, miss sullivan slowly spelled into my hand the word "d-o-l-l." i was at once interested in this finger play and tried to imitate it. when i finally succeeded in making the letters correctly i was flushed with childish pleasure and pride. running downstairs to my mother i held up my hand and made the letters for doll. i did not know that i was spelling a word or even that words existed; i was simply making my fingers go in monkey-like imitation. in the days that followed i learned to spell in this uncomprehending way a great many words, among them pin, hat, cup and a few verbs like sit, stand and walk. based on this excerpt, which words best describe helen keller?
Answers: 2
image
Computers and Technology, 23.06.2019 06:40, euniceyi56
How many nibbles can be stored in a 16-bit word?
Answers: 1
image
Computers and Technology, 23.06.2019 07:30, cireland
Write a program that inserts the digits of an integer into an array in originalorderfollowed by reverse order. first, promptthe user to enter a positive integer(> 0). determine the number of digits of the integer. create a dynamically allocated integer arrayof a size twice the number of digits. now insert the digits in original order which will occupy half of the array. then, insert the digits in reverse order. finally, output thedigits in thearray. use at least two functions to organize your program.
Answers: 3
image
Computers and Technology, 23.06.2019 12:30, legend101xD
Animations and transitions are added from the
Answers: 1
Do you know the correct answer?
Find the implementation of the sorting algorithms given below. I am trying to compare the efficiency...

Questions in other subjects:

Konu
Mathematics, 05.10.2019 13:00
Konu
Computers and Technology, 05.10.2019 13:00