Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need this in a C++ program using this Pseudocode that implements and test the Binary search algorithm. Please follow the Linear Search algorithm C++ code

need this in a C++ program using this Pseudocode that implements and test the Binary search algorithm. Please follow the Linear Search algorithm C++ code I posted below. And please follow the pseudocode binary algorithm exactly as in the photo too do not use different algorithms. make sure able to type a number and get the location of index or not found if entered a number not in the arraySize, Thank you.


//Linear Search Algorithm to follow and use for Binary Search Algorithm

#include
using namespace std;

int linear_search(int, int [], int);

int main() {

const int arraySize = 5;
int myArray[arraySize] = {3,4,6,2,8};
int value;
cout
cin >> value;

if(linear_search(value, myArray,arraySize) != -1){
cout
cout
}
else
cout

return 0;
} // end main

int linear_search(int x, int a[], int n){

int i = 0, location;
while(i
i = i + 1;
}
if(i
location = i;
else
location = -1;

return location;
}

image text in transcribed

MAC281 Assignment The pseudocode below describes the binary search algorithm. Use the pseudocode to write a C++ program that implements and tests the binary search algorithm. Note: YOU MUST FOLLOW THE STEPS IN THE GIVEN PSEUDOCODE. DO NOT USE ALTERNATIVE ALGORITHMS. Pseudocode: The Binary Search Algorithm 1 procedure binary search (x: integer, a1, a2,...,an: increasing integers) 2 ili is left endpoint of search interval) 3jnj is right endpoint of search interval} 4 while i < j 5 6 7 8 m = [(i+j)/2] if xam then i := m + 1 else jm if x=a, then location = i 9 else location := 0 10 return location (location is the subscript i of the term a, equal to x, 11 or 0 if x is not found}

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

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions

Question

What is managements primary objective?

Answered: 1 week ago

Question

What is a classifi ed balance sheet?

Answered: 1 week ago