In: Computer Science

Sort 101, 55, 64, 23, 12, 09, 45, 32, 19, 65, 89 using Quick sort. Write the algorithm.

Please show steps.

Solutions:-

code:-

#include <stdio.h>

#include<conio.h>

void swap(int *a, int *b)

{

int t=*a;

*a=*b;

*b=t;

}

int partition(int arr[],int l,int h)

{

int p=arr[h];

int i=(l-1);

for(int j=l;j<h;j++)

{

if(arr[j]<=p)

{

i++;

swap(&arr[i],&arr[j]);

}

}

swap(&arr[i+1],&arr[h]);

return (i+1);

}

void Quick_Sort(int arr[],int l,int h)

{

if(l<h)

{

int pi=partition(arr,l,h);

Quick_Sort(arr,l,pi-1);

Quick_Sort(arr,pi+1,h);

}

}

void printing(int arr[],int s)

{

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

{

printf("%d\n",arr[i]);

}

}

int main()

{

int data[] = {101, 55, 64, 23, 12, 9, 45, 32, 19, 65, 89};

int n=(sizeof(data)/sizeof(data[0]));

Quick_Sort(data,0,n-1);

printf("Sorted array:\n");

printing(data,n);

}

output:

Algorithm:-

Quick_Sort(arr, LMI, RMI)

if (LMI <RMI)

PI <- partition(arr, LMI, RMI)

Quick_Sort(arr, LMI, PI)

Quick_Sort(arr, PI + 1, RMI)

partition(arr,LMI, RMI)

set RMI as PI

store_Index<-LMI - 1

for (i <- LMI + 1 to RMI)

if (element[i] < P_Element)

swap element[i] and element[store_Index]

store_Index++

swap P_Element and element[store_Index+1]

return store_Index + 1

NOte:-

LMI=Left Most Index

RMI=Right Most Index

P_Element=Pivot element

PI=pivot index

arr=Array

Provide all steps
b) Sort the keys 20, 31, 29, 45, 09,
98, 12, 23, 99, 66 in descending order using the Heap sort. Also
write the algorithm.
a) Sort 99, 54, 64, 23, 12, 09, 45, 32, 19, 65, 89 using Quick
sort. Write the algorithm.
b) Sort 69, 74, 64, 23, 12, 09, 45,
32, 19, 65, 88, 33, 60, 38 using Shell sort. Write the
algorithm.

Write a program in Java to sort the given array using merge
sort, quick sort, insertion sort, selection sort and bubble sort
based on the input from the user which sorting technique they
wanted to use. Get the array size, array elements from the user,
and also display the sorted array along with the name of the
sorting technique used.

Given the data set below
25 52 67 23 78 89 57 90 32 77
45 48 62 54 94 69 46 79 40 33
21 57 84 54 23 34 68 63 61 76
87 78 39 50 70 60 32 65 73 45
28 82 66 79 71 80 46 66 24 90
A)What is the probability of an impossible even?
B) What is the probability of a certain event?
C) find the approximate mean using the Frequency...

Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Quick sort. Write
the algorithm. show work

Question 1 contains the actual values for 12 periods (listed in
order, 1-12). In Excel, create forecasts for periods 6-13 using
each of the following methods: 5 period simple moving average; 4
period weighted moving average (0.63, 0.26, 0.08, 0.03);
exponential smoothing (alpha = 0.23 and the forecast for period 5 =
53); linear regression with the equation based on all 12 periods;
and quadratic regression with the equation based on all 12
periods. Round all numerical answers to two...

Question 1 contains the actual values for 12 periods (listed in order, 1-12). In Excel, create forecasts for periods 6-13 using each of the following methods: 5 period simple moving average; 4 period weighted moving average (0.63, 0.26, 0.08, 0.03); exponential smoothing (alpha = 0.23 and the forecast for period 5 = 53); linear regression with the equation based on all 12 periods; and quadratic regression with the equation based on all 12 periods. Round all numerical answers to two...

{4, 6, 12, 15, 19, 23, 24}
Write one statement to print out (cout) the first character
and the last character of the vector you
initialized
Write one statement to insert an integer 9 to myvec between
numbers 6 and 12.
in c++

Question 1 contains the actual values for 12 periods (listed in
order, 1-12). In Excel, create forecasts for periods 6-13 using
each of the following methods: 5 period simple moving average; 4
period weighted moving average (0.63, 0.26, 0.08, 0.03);
exponential smoothing (alpha = 0.23 and the forecast for period 5 =
53); linear regression with the equation based on all 12 periods;
and quadratic regression with the equation based on all 12
periods. Round all numerical answers to two...

Question 1 contains the actual values for 12 periods (listed in
order, 1-12). In Excel, create forecasts for periods 6-13 using
each of the following methods: 5 period simple moving average; 4
period weighted moving average (0.63, 0.26, 0.08, 0.03);
exponential smoothing (alpha = 0.23 and the forecast for period 5 =
53); linear regression with the equation based on all 12 periods;
and quadratic regression with the equation based on all 12
periods.
The actual values for 12 periods...

ADVERTISEMENT

ADVERTISEMENT

Latest Questions

- TechMaster is an information technology (IT) consulting company offering services to small firms. TechMaster bills clients...
- How can ground improvement methods be classified in terms of their functions?
- We are evaluating a project that costs $744,000, has a six-year life, and has no salvage...
- A pin-ended chord of a truss is treated as a member in a braced frame. Its...
- This is your lucky day. You have won a $20,000 prize. You are setting aside $8,000...
- DeLuxe Limo Service has the following information for March. Sales revenue $ 310,000 Variable costs of...
- A 1.5 KVA, 220/120 V, 60Hz real step-down transformer has the following parameters that are all...

ADVERTISEMENT