Question: 4. A binary search algorithm is written (as in the modules, for example) which searches a pre-sorted array for some user-defined value, clientData . If

4.

A binary search algorithm is written (as in the modules, for example) which searches a pre-sorted array for some user-defined value, clientData. If clientData is stored in the array, it returns its array position, and if not found, it returns -1 (again, just like in the modules). Assume the array to be searched has 100 data elements in it. (Check all that apply):

[NOTE: due to common off-by-one interpretations when counting such things, if your predicted answer is within one (+1 or -1) of a posted option below, you can assume your prediction and the choice you are looking at are equivalent and check that option.]

A. It might return to the client with an answer after only one comparison of data.
B. It may require as many as 99 comparisons of data before it returns.
C. It will always return with an answer in 7 or fewer comparisons of data.
D.

It will always return with an answer in 3 or fewer comparisons of data.

3.

Assume MyClass defines two nested exception classes, BadNumber and BadString. Also, assume that MyClass's method doSomething() throws these exceptions under certain error conditions, and returns without throwing anything when it decides no error has occurred. We call doSomething four times in a try/catch block:

 MyClass a; try { a.doSomething(); a.doSomething(); a.doSomething(); a.doSomething(); } catch (MyClass::BadNumber) { cout << " bad number " << endl; } catch (MyClass::BadString) { cout << " bad string " << endl; } catch (...) { cout << " just generally bad " << endl; } 

Check the true statements (there will be more than one correct answer).

[Ignore whether spaces or ' ' are displayed - it is the words of the cout statements that we are interested in.]

A. It is possible neither "bad number" nor "bad string" is displayed on the screen after this block.
B. It is possible none of "bad number", "bad string" or "just generally bad" is displayed on the screen after this block.
C. It is possible both "bad number" and "bad string" is displayed on the screen after this block.
D. It is possible that doSomething() will return without error in one or more of these invocations, yet we still have one of "bad number", "bad string" or "just generally bad" displayed on the screen after this block.
E.

It is possible that this block will be called without anything being displayed on the screen.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!