binary search algorithm computer science homework help

Get perfect grades by consistently using Place your order and get a quality paper today. Take advantage of our current 20% discount by using the coupon code GET20

Order a Similar Paper Order a Different Paper

Problem 1:

To access a subtring of a string str, you can use the function defined by the following function prototype:

string substr(size_t startIndex, size_t length);

However if startIndex > str.size(), this substr function will cause an out_of_range exception and terminate the program.

Write an StrExcept exception class that inherits from the base exception class out_of_range by defining its own constructor and a print() method outputting a custom error message to the user.

Then, in the main method, write a program that asks the user to enter a string before asking him/her to enter the start index of the substring and its length.

This program should throw StrExcept if the start index is larger than the size of the string and handle this exception by surrounding it by try-catch block.

Note that out_of_range class would require you to include stdexcept library.


Write a recursive version of the binary search algorithm.

Function prototype: int bSearch(const int a[],int lo, int hi,int x)

Where lo and hi are the indexes of the first and last element of the binary search.

Note: You can assume that the items of the searched array to test in your main method are sorted/

Do you need help with this or a different assignment? We offer CONFIDENTIAL, ORIGINAL (Turnitin/LopesWrite/SafeAssign checks), and PRIVATE services using latest (within 5 years) peer-reviewed articles. Kindly click on ORDER NOW to receive an A++ paper from our masters- and PhD writers.

Get a 15% discount on your order using the following coupon code SAVE15

Order a Similar Paper Order a Different Paper