Write a program in which you create an array of random real numbers with a size of 10001. The values should fall between 900 and 1000. Using the provided statistics library, calculate all statistical values represented by the functions in the library and output the results. The median value can only be correctly found after the array is sorted. After sorting using the selection sort method, search for the median value using both the linear search and binary search methods. Return the index of the median value in both searches.
The language is C++
#include<iostream>
#include<math.h>
using namespace std;
//logic for selection sort
void selection(double a[])
{
int i,j;
double t;
for(i=0;i<10001;i++)
{
for(j=i+1;j<10001;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
}
//method for binary search
int binarysearch(double a[], double no)
{
int i,low=0,up=10000;
for(i=(low+up)/2;low<=up;i=(low+up)/2)
{
if(a[i]==no)
{
return
i;
}
else
if(a[i]>no)
up=i-1;
else
low = i+1;
}
}
//method forlinear search
int linearsearch(double a[],double n)
{
int i;
for(i=0;i<10001;i++)
if(a[i]==n)
return i;
}
int main()
{
int i;
double arr[10001],mean,median,variance,sd,sum=0;
for(i=0;i<10001;i++)
arr[i]= 900 + rand()%(1000-900+1);
// cout<<endl<<"Array elements before
sort\n";
for(i=0;i<10001;i++)
{
//cout<<"
"<<arr[i];
sum+=arr[i];
}
//computing mean
mean=sum/11;
//computing variance
sum=0;
for(i=0;i<10001;i++)
{
sum=sum+ (arr[i]-mean) *
(arr[i]-mean);
}
variance = sum/10000;
//computing standard deviation
sd=sqrt(variance);
//display the mean
cout<<endl<<"Mean value is
"<<mean;
//call to selection() to sort
selection(arr);
//display the elements after sorting
// cout<<endl<<"Array elements after
sort\n";
// for(i=0;i<10001;i++)
// cout<<" "<<arr[i];
//find the median
median=arr[(10001/2)];
//display the median
cout<<endl<<"Median value is
"<<median;
//display the variance
cout<<endl<<"Variance is
"<<variance;
//display the standard variance
cout<<endl<<"Standard Deviation is
"<<sd;
//call to linearsearch() to find the position of
median
i=linearsearch(arr,median);
cout<<endl<<median<<" value is at
"<<i<<" position";
//call to binarysearch() to find the position of
median
i=binarysearch(arr,median);
cout<<endl<<median<<" value is at
"<<i<<" position";
}
OUTPUT
For the output i have taken the array size as 11

This output is taking with array size 10001. Here you will observe the variations of position of the median value in linearsearch and binary search because the array having duplicate elements.

NOTE: SINCE YOU HAVE NOT GIVEN THE STATISTICS LIBRARY SO I HAVE COMPUTED MEAN,MEDIAN VARIANCE AND STANDARD DEVIATION ONLY.
Write a program in which you create an array of random real numbers with a size...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...
Using the various sorting methods discussed create arrays of integers, doubles and strings with at least 25 values in each. Query the user on what array they want to sort and how they want to sort each array. –Bubble sort –Selection sort –Insertion sort –Quicksort Part II with your arrays creates a means to search the arrays for values using sequential and binary searches.
Using Arrays with Sorting and Searching Algorithms 1) This program has six required outputs and involves searching and sorting an array of integers. Write a java application that initializes an array with the following numbers, in this order: 23, 17, 5, 90, 12, 44, 38, 84, 77, 3, 66, 55, 1, 19, 37, 88, 8, 97, 25, 50, 75, 61, and 49. Then display the unsorted values. This is required output #1 of 6 for this program. 2) Using a...
Write a java program: Create a method fillRandom() that accepts an array of int as input and populates it with random numbers in the range -999 to 1000 Explicitly store zero in index [0] and 900 in index [1]. (0 and 900 will be used as search keys) Create a method DisplayLastInts() that accepts an array of int as input and displays the last hundred elements to the screen in rows of 10 elements. Format the output so the 10...
Declare an array of integers of size 8 and initialize it with any non-duplicate integer values you like. Don’t enter the values in any order. Print the unsorted array. Sort the array using selection sort or insertion sort in descending order. Print what sort you are using. Write any additional functions that you need for sorting. Keep monitoring the number of comparisons and number of swaps performed while sorting. Report both after sorting. Print the sorted array. in C++
**C++ only, use standard library, no vectors Write a program to generate a list of 5000 random numbers between 1 and 10,000 stored in an array. Sorts: Print out the middle 50 numbers of the original list to show the results. Now sort the original numbers using bubble sort. Print out the number of swaps made. Now sort the original numbers using selection sort. Print out the number of swaps made. Now sort the original numbers using insertion sort. Print...
Program with generic merge sort and binary search
method help. The programming language I'm using is Java.
This program should show understanding generic merge sort methods and generic binary search methods in java. The execution should include at least 5 found items including one from the first three items in the sorted array and one from the last three items in the sorted array as well as at least two items not found Create a generic merge sort method that...
(Use C programming language) 1-)Write a program that • Sorts a given integer array via Selection Sort • Rotates the sorted array around a random point, e.g., 1 2 3 4 5 à 3 4 5 1 2 is obtained by rotation around 3. • Searches for a key point in the rotated array in O(logn) time, where the rotation point is known in advance. • Repeats above by first finding the unknown rotation point via sequential search and binary...
Question 10: Given an array of data: array1 10 5 15 2 7 21 Write the code for the selection sort to sort the data and draw a table showing how the data is sorted using selection sort. Write the code for Binary search algorithm to find the value 15 from the sorted array. Draw the tree diagram showing the binary search of the list.
Benchmark Searching and Sorting Write a program that has an array of at least 20 strings that you will have your user enter. It should call a function that uses the linear search algorithm to locate one of the values. The function should keep a count of the number of comparisons it makes until it finds the value. The program then should call a function that uses the binary search algorithm to locate the same value. It should also keep...