Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; int linearSearch(int [], int,int); void selectionSort(int[],int); int main(){ int max=10; int ar[10]; cout cout for(int i=0;i cin>>ar[i]; } cout int searchNumber;

image text in transcribed

#include

using namespace std;

int linearSearch(int [], int,int);

void selectionSort(int[],int);

int main(){

int max=10;

int ar[10];

cout

cout

for(int i=0;i

cin>>ar[i];

}

cout

int searchNumber;

cout

cout

cin>>searchNumber;

int result = linearSearch(ar,max,searchNumber);

if(result>=0){

cout

}

else{

cout

}

selectionSort(ar,max);

cout

cout

for (int i=0; i

cout

return 0; }

int linearSearch(int array[], int size,int numb){

for(int i=0; i

{

if(numb==array[i])

{

return i;

}

}

return -1; }

void selectionSort(int ar[],int size)

{

int min;

for(int i=0;i

{

min = i;

for(int j = i+1 ;j

if(ar[j]

{

min=j; }

}

swap (ar[i], ar[min]);

}

}

Develop algorithms to perform binary search. Extend your previous lab, and implement your algorithm in a separate function. Add a counter to your linear search function for the number of iterations required for the search. Additionally, add a similar counter to your binary search function Furthermore, change your array to handle 10,000 elements. Prompt the user for 10,000 values and then prompt the user for a query. Perform linear search. Sort the numbers, but remove the code to display the numbers in sorted order. Perform binary search. Not the difference between the number of iterations for linear search and binary search

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

For what values of integer x will branch 3 execute?

Answered: 1 week ago

Question

Write short notes on departmentation.

Answered: 1 week ago

Question

What are the factors affecting organisation structure?

Answered: 1 week ago

Question

What are the features of Management?

Answered: 1 week ago

Question

Briefly explain the advantages of 'Management by Objectives'

Answered: 1 week ago