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
What is the foundational domain for business
mr Goodwill [35]

a fundamental domain or fundamental region is a subset of the space which contains exactly one point from each of these orbits . It serves as a geometric realisation for the abstract set of representatives of the orbits . There are many ways to choose a fundamental domain .

hope this help

7 0
3 years ago
Renee's creating a plan for her business's information system. What should she do after she determines the goals for her busines
stiks02 [169]

get organized because of the beging when she start she will want ot be nice and fresh on everything

7 0
3 years ago
Mary needs to choose the menu in order to place the text in a desired fashion around the image.
n200080 [17]
Can you be more specific?

7 0
3 years ago
Read 2 more answers
Where does an MPLS label go in a PDU?
Natalija [7]

Answer: Between Layers 2 and 3

Explanation:

In between Layer 2 and Layer 3 the MPLS header is present and is known as Shim header. It is also said to be in 2.5.

6 0
2 years ago
Complete this truth Table. Write a program that you can enter from the keyboard, a 1 or 0 into three Boolean variables, A,B,C. W
SSSSS [86.1K]

Answer:

Following are the code to this question:

#include<stdio.h>//defining header file

int AND(int x,int y) //defining a method AND that hold two variable in its parameter

{

if(x==1 && y==1)//defining if block to check x and y value is equal to 1

{

return 1;//return value 1

}

else //defining else block

{

   return 0;//return value 0

}

}

int OR(int x,int y)//defining method OR that hold two variable in its parameter

{

if(x==0&&y==0)//defining if block to check x and y value is equal to 1

{

return 0;//return value 0

}

else //defining else block

{

   return 1;//return value 1

}

}

int main()//defining main method

{

int a,b,c;//defining integer variable  

int k=1;//defining integer variable k that holds a value 1

while(k<=8)//defining while loop for 8 time input

{

printf("Please insert 3 numbers in (0 0r 1):\n ");//print message

scanf("%d%d%d", &a, &b, &c);//input value

k++;//increment the value of k by 1

printf("value: %d\n",AND(OR(a,b),c));

}

return 0;

}

Output:

please find the attachment.

Explanation:

In the above-given C language code two methods "AND and OR" is declared, holds two integer variable "x and y" in its parameters, inside the method a conditional it used that can be defined as follows:

  • In the AND method, inside a conditional statement, if block check x and y both value is same that is 1 it will return 1 or it will goto else block in this it will return value 0.      
  • In the OR method, inside a conditional statement, if block check x and y both value is the same, that is 0 it will return 0 or it will goto else block in this it will return value 1.
  • In the main method, four integers "a,b,c, and k" is declared in which variable "a, b, c" is used in the loop for 8 times input values from the user and print method is used to call the method and prints its return values.

8 0
3 years ago
Other questions:
  • You receive an offer for a credit card that can be use to accrue points that
    11·1 answer
  • Theâ ______ is a large worldwide collection of networks that use a common protocol to communicate with one another.
    5·1 answer
  • How did tafts accomplishments regarding conservation and trust-busting compare to roosevelt?
    11·1 answer
  • Which is an advantage that electronic scheduling tools have over paper calendars?
    13·2 answers
  • A software process describes the interrelationship among the phases by expressing their order and frequency, but does not define
    14·1 answer
  • Consider a system consisting of processes P1 , P2 , ..., Pn , each of which has a unique priority number. Write a monitor that a
    14·1 answer
  • Write a program that keeps track of a simple inventory for a store. While there are still items left in the inventory, ask the u
    12·2 answers
  • 6. The following is a dump of a DATA chunk in hexadecimal format. 00000015 00000005 0003000A 00000000 48656C6C 6F000000 a. Is th
    7·1 answer
  • Is this even possible
    9·2 answers
  • In a selection, the else clause executes ______________. a. always b. when the tested condition is false c. when the tested cond
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!