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
scoray [572]
3 years ago
7

g Write a program to sort an array of 100,000 random elements using quicksort as follows: Sort the arrays using pivot as the mid

dle element of the array Sort the arrays using pivot as the median of the first, last, and middle elements of the array Sort the arrays using pivot as the middle element of the array. However,, when the size of any sub-list reduces to less than 20, sort the sub-list using insertion sort. Sort the array using pivot as the median of the first, last and middle elements of the array. When the size of any sub-list reduces to less than 20, sort the sub-list using insertion sort. Calculate and display the CPU time for each of the preceding four steps.
Computers and Technology
1 answer:
shtirl [24]3 years ago
7 0

Answer:

header.h->function bodies and header files.

#include<iostream>

#include<cstdlib>

#include<ctime>

using namespace std;

/* Partitioning the array on the basis of piv value. */

int Partition(int a[], int bot, int top,string opt)

{

int piv, ind=bot, i, swp;

/*Finding the piv value according to string opt*/

if(opt=="Type1 sort" || opt=="Type3 sort")

{

piv=(top+bot)/2;

}

else if(opt=="Type2 sort" || opt=="Type4 sort")

{

piv=(top+bot)/2;

if((a[top]>=a[piv] && a[top]<=a[bot]) || (a[top]>=a[bot] && a[top]<=a[piv]))

piv=top;

else if((a[bot]>=a[piv] && a[bot]<=a[top]) || (a[bot]>=a[top] && a[bot]<=a[piv]))

piv=bot;

}

swp=a[piv];

a[piv]=a[top];

a[top]=swp;

piv=top;

/*Getting ind of the piv.*/

for(i=bot; i < top; i++)

{

if(a[i] < a[piv])

{

swp=a[i];

a[i]=a[ind];

a[ind]=swp;

ind++;

}

}

swp=a[piv];

a[piv]=a[ind];

a[ind]=swp;

return ind;

}

void QuickSort(int a[], int bot, int top, string opt)

{

int pindex;

if((opt=="Type3 sort" || opt=="Type4 sort") && top-bot<19)

{

/*then insertion sort*/

int swp,ind;

for(int i=bot+1;i<=top;i++){

swp=a[i];

ind=i;

for(int j=i-1;j>=bot;j--){

if(swp<a[j]){

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

ind=j;

}

else

break;

}

a[ind]=swp;

}

}

else if(bot < top)

{

/* Partitioning the array*/

pindex =Partition(a, bot, top,opt);

/* Recursively implementing QuickSort.*/

QuickSort(a, bot, pindex-1,opt);

QuickSort(a, pindex+1, top,opt);

}

return ;

}

main.cpp->main driver file

#include "header.h"

int main()

{

int n=100000, i;

/*creating randomized array of 100000 numbers between 0 and 100001*/

int arr[n];

int b[n];

for(i = 0; i < n; i++)

arr[i]=(rand() % 100000) + 1;

clock_t t1,t2;

t1=clock();

QuickSort(arr, 0, n-1,"Type1 sort");

t2=clock();

for( i=0;i<n;i++)

arr[i]=b[i];

cout<<"Quick sort time, with pivot middle element:"<<(t2 - t1)*1000/ ( CLOCKS_PER_SEC );

cout<<"\n";

t1=clock();

QuickSort(arr, 0, n-1,"Type2 sort");

t2=clock();

for( i=0;i<n;i++)

arr[i]=b[i];

cout<<"Quick sort time, with pivot median element:"<<(t2 - t1)*1000/ ( CLOCKS_PER_SEC );

cout<<"\n";

t1=clock();

QuickSort(arr, 0, n-1,"Type3 sort");

t2=clock();

for( i=0;i<n;i++)

arr[i]=b[i];

cout<<"Quick sort time and insertion sort time, with pivot middle element:"<<(t2 - t1)*1000/ ( CLOCKS_PER_SEC );

cout<<"\n";

t1=clock();

QuickSort(arr, 0, n-1,"Type4 sort");

t2=clock();

cout<<"Quick sort time and insertion sort time, with pivot median element:"<<(t2 - t1)*1000/ ( CLOCKS_PER_SEC );

return 0;

}

Explanation:

Change the value of n in the main file for different array size. Output is in the same format as mentioned, time is shown in milliseconds.

You might be interested in
I need help to find out what is wrong with this program and my variable, "exponent" comes out as 0 in the output instead of the
sweet-ann [11.9K]

You're substracting one from the variable "exponent" with every iteration of the loop, and you told it to break out of the loop once "exponent" is 0, therefore, it's always going to end up as 0 at the end.


If you want to keep the input from the user, then declare another variable like "counter" and assign the value of "exponent" to it and use it for the loop


Or even better, do this for the loop:

for(int i = 0; i < exponent; i++)

{

//Code here

}

3 0
3 years ago
you have just finished developing a new application. before putting it on the website for users to download, you want to provide
Nostrana [21]

If you have just finished developing a new application, but before putting it on the website for users to download, you want to provide a checksum to verify that the object has not been modified, a process which you must implement is: C. Code signing.

<h3>What is SDLC?</h3>

SDLC is an abbreviation for software development life cycle and it can be defined as a strategic methodology that defines the key steps, phases, or stages for the design, development and implementation of high quality software programs.

<h3>What is code signing?</h3>

In Computer technology, code signing can be defined as a process through which software developer and computer programmers digitally sign executable software codes and scripts in order to confirm the author of the software, as well as guaranteeing that the software code has not been altered (modified) or corrupted, especially through the use of a cryptographic hash so as to validate authenticity and integrity.

In this context, we can reasonably infer and logically deduce that it is important for software developer and computer programmers to implement code signing before making a software available for download on a website.

Read more on software development here: brainly.com/question/28262663

#SPJ1

Complete Question:

You have just finished developing a new application. Before putting it on the website for users to download, you want to provide a checksum to verify that the object has not been modified.

Which of the following would you implement?

answer choices

Normalization

Code obfuscation

Code signing

Memory management

3 0
1 year ago
Which pillar in the cisco iot system describes embedded networks that include compact form factor switch and router cards runnin
kolezko [41]
<span>The network connectivity pillar in the Cisco IoT system describes embedded networks that include compact form factor switch and router cards running Cisco IOS software to provide secure data, voice, and video communications.
</span>The network connectivity is one of the six pillars <span>supporting Cisco's IoT system. It </span>includes purpose-built routing, switching and wireless products;
8 0
3 years ago
What are the technique CSP does for the Cloud Storage Security?
Trava [24]

Answer:

Encryption are the technique CSP does for the cloud storage security.

7 0
4 years ago
Type the correct answer in each box. Spell all words correctly.
andrew11 [14]

Answer:

1. Tablet

2. Flat

Explanation:

5 0
3 years ago
Other questions:
  • Wendy is an attacker who recently gained access to a vulnerable web server running Microsoft Windows. What command can she use t
    9·1 answer
  • In a _____, if any link between nodes is severed, the entire network is affected, and failure of a single node disrupts the enti
    9·1 answer
  • You discover memory is corrupted, what would be an indication of a software vs. a hardware issue?
    5·1 answer
  • Ruth knows the name of a presentation file and the folder it's in, but there are many files in that folder. How can Ruth quickly
    8·1 answer
  • What is Boolean algebra
    14·2 answers
  • Many loop control variable values are altered by ____ or adding to them
    11·1 answer
  • How long would it take a 8 bit computer to calculate π to the thousandth place?
    8·1 answer
  • Jack started a job as a consultant with an IT firm he will be interacting with various customers and employees from different pa
    13·1 answer
  • 5. Compare the telephone network and the internet. What are the similarities? What are the differences?
    12·1 answer
  • Using the _____, you can direct the browser to retrieve specific information about the URL, to reload the current page, or to lo
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!