
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
I need help making these search functions please using the correct parameters in C++ please
![Searching:
bool linear_search(const
bool binary_search(const
int arr[], int n, int value, int& comparisons);
int arr[], int start, int end, int value, int& comparisons);
The linear_search function is to perform linear search iteratively from the beginning of a sorted
array. It returns true if the target value is found in the array, false otherwise. In addition, the
function shall store the number of comparisons performed by the algorithm in comparisons
parameter. Since the array is sorted, it is important for the search to stop searching when all
elements smaller than the given value have been evaluated.
The binary_search function is to perform binary search recursively. It returns true if the target
value is found in the array, false otherwise. In addition, the function shall store the number of
comparisons performed by the algorithm in comparisons parameter.](https://content.bartleby.com/qna-images/question/46c0fb16-724b-4726-818c-9156075ac6cc/07047c6f-f3a0-41b4-98b9-a2d999852d90/42fcwqk_thumbnail.png)
Transcribed Image Text:Searching:
bool linear_search(const
bool binary_search(const
int arr[], int n, int value, int& comparisons);
int arr[], int start, int end, int value, int& comparisons);
The linear_search function is to perform linear search iteratively from the beginning of a sorted
array. It returns true if the target value is found in the array, false otherwise. In addition, the
function shall store the number of comparisons performed by the algorithm in comparisons
parameter. Since the array is sorted, it is important for the search to stop searching when all
elements smaller than the given value have been evaluated.
The binary_search function is to perform binary search recursively. It returns true if the target
value is found in the array, false otherwise. In addition, the function shall store the number of
comparisons performed by the algorithm in comparisons parameter.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 2 images

Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
The binary search is not working help please C++,
For example, return wrong number of comparisons and it should return true but it returns false
![int comparisons1 = 0;
int a1[50], size1, item1;;
int n1-sizeof(al) / sizeof(a1[0]);
int start=0;
int end1=n1;
cout<<"Enter number of elements\n";
cin>>size1;
cout << "Enter " << size1 << " elements:\n- ";
for(int i=0; i<size1; i++) {
cin>>a1[i];
cout << "-
}
- ";
cout<<"Enter element to be searched=";
cin>>item1;
bool result1 = binary_search(a1, start, end1, item1, comparisons1);
cout <<boolalpha;
cout << result1 << endl;
cout << "Comparisons made are: ';
cout <<comparisons1<<endl;](https://content.bartleby.com/qna-images/question/46c0fb16-724b-4726-818c-9156075ac6cc/2a7af6fb-5cd7-4a04-8ff0-3d50604c986d/kwsoye5_thumbnail.jpeg)
Transcribed Image Text:int comparisons1 = 0;
int a1[50], size1, item1;;
int n1-sizeof(al) / sizeof(a1[0]);
int start=0;
int end1=n1;
cout<<"Enter number of elements\n";
cin>>size1;
cout << "Enter " << size1 << " elements:\n- ";
for(int i=0; i<size1; i++) {
cin>>a1[i];
cout << "-
}
- ";
cout<<"Enter element to be searched=";
cin>>item1;
bool result1 = binary_search(a1, start, end1, item1, comparisons1);
cout <<boolalpha;
cout << result1 << endl;
cout << "Comparisons made are: ';
cout <<comparisons1<<endl;

Transcribed Image Text:Enter number of elements
7
Enter 7 elements:
3
- 9
- 5
4
7
1
0
Enter element to be searched=7
false
Comparisons made are: 6
-
-
-
-
Solution
by Bartleby Expert
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
The binary search is not working help please C++,
For example, return wrong number of comparisons and it should return true but it returns false
![int comparisons1 = 0;
int a1[50], size1, item1;;
int n1-sizeof(al) / sizeof(a1[0]);
int start=0;
int end1=n1;
cout<<"Enter number of elements\n";
cin>>size1;
cout << "Enter " << size1 << " elements:\n- ";
for(int i=0; i<size1; i++) {
cin>>a1[i];
cout << "-
}
- ";
cout<<"Enter element to be searched=";
cin>>item1;
bool result1 = binary_search(a1, start, end1, item1, comparisons1);
cout <<boolalpha;
cout << result1 << endl;
cout << "Comparisons made are: ';
cout <<comparisons1<<endl;](https://content.bartleby.com/qna-images/question/46c0fb16-724b-4726-818c-9156075ac6cc/2a7af6fb-5cd7-4a04-8ff0-3d50604c986d/kwsoye5_thumbnail.jpeg)
Transcribed Image Text:int comparisons1 = 0;
int a1[50], size1, item1;;
int n1-sizeof(al) / sizeof(a1[0]);
int start=0;
int end1=n1;
cout<<"Enter number of elements\n";
cin>>size1;
cout << "Enter " << size1 << " elements:\n- ";
for(int i=0; i<size1; i++) {
cin>>a1[i];
cout << "-
}
- ";
cout<<"Enter element to be searched=";
cin>>item1;
bool result1 = binary_search(a1, start, end1, item1, comparisons1);
cout <<boolalpha;
cout << result1 << endl;
cout << "Comparisons made are: ';
cout <<comparisons1<<endl;

Transcribed Image Text:Enter number of elements
7
Enter 7 elements:
3
- 9
- 5
4
7
1
0
Enter element to be searched=7
false
Comparisons made are: 6
-
-
-
-
Solution
by Bartleby Expert
Knowledge Booster
Similar questions
- Write a function with one integer parameter that will return the sum of the divisors of its argument c++arrow_forwardI need this coded in c++, please.arrow_forwardThis is very helpful thank you. If possible can you please show me how to make the function with the original parameters C++arrow_forward
- Write a function in C++ that accepts a single number, calculates the number of positive odd numbers below the parameter value and returns the calculated result to the main method.arrow_forwardplease code this for me in c++ using void, functions, loops, (basic c++ not complicated or highlevel please). I tried to code it myself but there are many mistakes I dont know how to fix so please write a similar one for me but it works. The question is only 1 but it has 2 parts (2 different functions that should be in one code) MY CODE: #include <iostream>using namespace std; int IsPalindrome(int p);void GCD(); int main (){ int choice; cout << "Please enter a choice: "<<endl; cout << "Enter one for IsPalindrome "<<endl; cout << "Enter 2 for GCD "<<endl; cout << "Enter 3 to exit the program "<<endl; cout << "Choice: "<<endl; cin >> choice; if (choice == 1) { int p; cout << "Please enter a 3 digit number: "<<endl; cin >> p; if(p%10==p/100) { cout<<p<<" is a palindrome " <<endl; } else {…arrow_forwardIn C++ fill in the blanksarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY