1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
icang [17]
3 years ago
5

Create an integer variable named ‘listSize’ and initialize the value to 1000.

Computers and Technology
1 answer:
Natalija [7]3 years ago
3 0

Answer:

The code is given in C++. The variable name is arraySize. It should be replaced with listSize

Explanation:

// header file

#include<iostream>

#include<fstream>

#include<cstdlib>

#include<chrono>

using namespace std;

using namespace std::chrono;

// bubble sort algorithm

void bubbleSort(int *a, int size) {

for (int i = 0; i<size - 1; i++) {

for (int j = 0; j<size - i - 1; j++) {

if (a[j]>a[j + 1]) {

//swap

int temp = a[j];

a[j] = a[j + 1];

a[j + 1] = temp;

}

}

}

}

// selection sort

void selectionSort(int *a, int size) {

for (int i = 0; i<size - 1; i++) {

int m_i = i;

for (int j = i + 1; j<size; j++) {

if (a[j]<a[m_i]) {

m_i = j;

}

}

//swap

int temp = a[i];

a[i] = a[m_i];

a[m_i] = a[i];

}

}

// insertion sort

void insertionSort(int *a, int size) {

for (int i = 1; i<size; ++i) {

int key = a[i];

int j=i-1;

for (; (j >= 0 && key < a[j]); j--) {

a[j + 1] = a[j];

}

a[j + 1] = key;

}

}

// make partition on array

int getPartition(int *a, int l, int h) {

int pvt = a[h];

int i = (l - 1);

for (int j = l; j <= h - 1; j++) {

if (a[j]<pvt) {

i++;

//swap

int tmp = a[i];

a[i] = a[j];

a[j] = tmp;

}

}

//swap

int tmp = a[i + 1];

a[i + 1] = a[h];

a[h] = tmp;

return(i + 1);

}

// quick sort

void quickSort(int *a, int l, int h) {

if (l<h) {

int p = getPartition(a, l, h);

quickSort(a, l, p - 1);

quickSort(a, p + 1, h);

}

}

// merge array

void merge(int *a, int l, int m, int r) {

int n1 = m - l + 1;

int n2 = r - m;

int *L = new int[n1];

int *R = new int[n2];

for (int i = 0; i<n1; i++) {

L[i] = a[i + l];

}

for (int j = 0; j<n2; j++) {

R[j] = a[m + j + 1];

}

int i = 0, j = 0, k = 1;

while (i<n1 && j<n2) {

if (L[i] <= R[j]) {

a[k] = L[i];

i++;

}

else {

a[k] = R[j];

j++;

}

k++;

}

while (i<n1) {

a[k] = L[i];

i++;

k++;

}

while (j<n2) {

a[k] = R[j];

j++;

k++;

}

}

// merge sort

void mergeSort(int *a, int l, int r) {

if (l<r) {

int m = l + (r - l) / 2;

mergeSort(a, l, m);

mergeSort(a, m + 1, r);

merge(a, l, m, r);

}

}

int* randomData(int size) {

int *ar = new int[size];

for (int i = 0; i<size; i++) {

ar[i] = rand();

}

return(ar);

}

void copyAry(int *a, int *b, int size) {

for (int i = 0; i < size; i++) {

a[i] = b[i];

}

}

int main() {

int arraySize = 1000;

int *arrLst = new int[arraySize];

int *arLst = new int[arraySize];

arrLst = randomData(arraySize);

//copy array

// because after sorting arry will be sorted

copyAry(arLst, arrLst, arraySize);

auto start1 = high_resolution_clock::now();

bubbleSort(arLst, arraySize);

auto end1 = high_resolution_clock::now();

auto duration1 = duration_cast<microseconds>(end1 - start1);

cout << duration1.count()<<endl;

// copy array for new sort

copyAry(arLst, arrLst, arraySize);

auto start2 = high_resolution_clock::now();

selectionSort(arLst, arraySize);

auto end2 = high_resolution_clock::now();

auto duration2 = duration_cast<microseconds>(end2 - start2);

cout << duration2.count() << endl;

// copy array for new sort

copyAry(arLst, arrLst, arraySize);

auto start3 = high_resolution_clock::now();

insertionSort(arLst, arraySize);

auto end3 = high_resolution_clock::now();

auto duration3 = duration_cast<microseconds>(end3 - start3);

cout << duration3.count() << endl;

// copy array for new sort

copyAry(arLst, arrLst, arraySize);

auto start4 = high_resolution_clock::now();

mergeSort(arLst, 0,arraySize-1);

auto end4 = high_resolution_clock::now();

auto duration4 = duration_cast<microseconds>(end4 - start4);

cout << duration4.count() << endl;

// copy array for new sort

copyAry(arLst, arrLst, arraySize);

auto start5 = high_resolution_clock::now();

quickSort(arLst, 0,arraySize-1);

auto end5 = high_resolution_clock::now();

auto duration5 = duration_cast<microseconds>(end5 - start5);

cout << duration5.count() << endl;

ofstream out("GroupAssignment2Results.csv");

out << "Array Size,Bubble Sort Time,Selection Sort Time,Insertion Sort Time,Quick Sort Time,Merge Sort Time\n";

out << arraySize << "," << duration1.count() << "," << duration2.count() << "," << duration3.count() << "," << duration5.count() << "," << duration4.count();

cout << "\nOutput in File.";

out.close();

cin.get();

return(0);

}

You might be interested in
An is auditor reviewing a network log discovers that an employee ran elevated commands on his/her pc by invoking the task schedu
yarga [219]
<span>I would say a cyber attack.since it is any kind of offensive act on a computer system including pc's that steals, alters or destroys confidential information and which is considered hacking a computer. Using the task scheduler to launch restrictive applications seems to qualify as such an attack since it is violating the restrictive applicatios.</span>
5 0
2 years ago
Jeanne writes a song, and Raul wants to perform
Goryan [66]
B) ask jeanne for permission
6 0
3 years ago
Read 2 more answers
Determine the number of cache sets (S), tag bits (t), set index bits (s), and block offset bits (b) for a 40964096-byte cache us
pogonyaev

Complete Question:

Determine the number of cache sets (S), tag bits (t), set  index bits (s), and block offset bits (b) for a 4096-byte cache using 32-bit memory addresses, 8-byte cache blocks and a 8-way associative design. The cache has :

Cache size = 1024 bytes, sets t = 26.8, tag bits, s = 3.2, set index bit =2

Answer:

Check below for explanations

Explanation:

Cache size = 4096 bytes = 2¹² bytes

Memory address bit = 32

Block size = 8 bytes = 2³ bytes

Cache line = (cache size)/(Block size)

Cache line = \frac{2^{12} }{2^{3} }

Cache line = 2⁹

Block offset = 3 (From 2³)

Tag = (Memory address bit - block offset - Cache line bit)

Tag = (32 - 3 - 9)

Tag = 20

Total number of sets = 2⁹ = 512

3 0
2 years ago
A ________ is a device used to illegally capture the data stored on the magnetic stripe of an ATM card, credit card, or debit ca
Ksenya-84 [330]

Answer:

skimmer

Explanation:

8 0
2 years ago
What command launches the remote desktop client for windows?
Ksju [112]
%windir%\system32\mstsc.exe

launches the RDP client.
7 0
3 years ago
Other questions:
  • What's the best option if you can't show your PowerPoint presentation at all? A. Create PDF/XPS Document B. Prepare a Package Pr
    11·2 answers
  • Write a class named Car that has the following member variables: - yearModel. An int that holds the car’s year model. - make. A
    6·1 answer
  • Name types of operating system with example
    5·1 answer
  • Indicate the proper order (1-4) of the following PR strategic planning 4-step process. 1 Defining the problem 2 Evaluating the p
    10·1 answer
  • Public static String doSomething(String s) { final String BLANK = " "; //BLANK contains a single space String str = ""; //empty
    6·1 answer
  • Dave has to create animations for a game. Which tool can Dave use?
    6·1 answer
  • Which of the following does not use a Graphic User Interface?
    14·1 answer
  • NAT is able to stop ________. Group of answer choices a) scanning probes sniffers from learning anything about the internal IP a
    8·2 answers
  • Help!!
    15·1 answer
  • Kenny is asked to submit a photo for the annual photographic competition. He decided to capture a photo with the light-painting
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!