Filters
Question type

Study Flashcards

In the binary search,if the array being searched has 32 elements in it,how many elements of the array must be examined to be certain that the array does not contain the key? What about 1024 elements? Note: the answer is the same regardless of whether the algorithm is recursive or iterative.

Correct Answer

verifed

verified

The binary search examines the midpoint ...

View Answer

In the binary search,each pass (recursion or iteration)selects a subproblem of the original problem to solve.What fraction of the array sent to an initial call is eliminated in the next iterative pass or recursive call?

Correct Answer

verifed

verified

Half the array is eliminated i...

View Answer

Overloading and recursion look similar.Both situations call functions with the same name.Explain the difference.

Correct Answer

verifed

verified

In C++ overloading is based on the signa...

View Answer

A proper recursive solution requires at least two cases: a recursive function that calls the recursive function with a smaller problem,and a base,or stopping case.

Correct Answer

verifed

verified

Here is a recursive function that is supposed to return the factorial.Identify the line(s)with the logical error(s).Hint: This compiles and runs,and it computes something.What is it? int fact( int n )//a { int f = 1;//b if ( 0 == n || 1 == n )//c return f;//d else { f = fact(n - 1);//f f = (n-1)* f;//g return f;//h } }

Correct Answer

verifed

verified

The function computes (n-1)! T...

View Answer

Describe the stack memory (or data)structure.Give a four-word description of the stack discipline.

Correct Answer

verifed

verified

A stack data structure is analogous to a...

View Answer

A design technique is to break a problem into smaller tasks,with the prospect that a smaller problem will be easier to solve.If the smaller task is the identical to the original task excepting only that the size is smaller,the problem may be solved using a recursive algorithm,and implemented with a recursive function.

Correct Answer

verifed

verified

You are doing a binary search of the dictionary for page where a word should be,using the recursive binary search.What is done to guarantee that the successive dictionaries to be searched are smaller?


A) Search a dictionary with one less page.
B) Search a dictionary with one less word.
C) Search a dictionary with half the words.
D) Recursively search the half the dictionary where the word should be.

Correct Answer

verifed

verified

A recursive function can have only one recursive case.

Correct Answer

verifed

verified

You are doing a binary search of the dictionary for page where a word should be,using the recursive binary search What are stopping cases?


A) The dictionary being searched has one page.
B) The second half the dictionary being searched has one page.
C) The middle of the dictionary is at page one.
D) The dictionary being searched has one word

Correct Answer

verifed

verified

The binary search algorithm in the text makes recursive calls on subarrays of the array passed to the algorithm.The range passed to the search function is first to last.The search algorithm makes recursive calls on the left or right subarray that target will be in,if the target is present.What are the left and right ends of the right subarray?


A) Last ,mid - 1
B) last ,mid + 1
C) mid - 1,last
D) mid + 1,last
E) last,mid

Correct Answer

verifed

verified

Here is an iterative function.Write a recursive function that does the same thing.Be sure you write the correct number of copies of the cheer,"Hip,Hip,Hurray!".For this problem,ignore namespace issues. void iter_cheers(int n) { for(int i = 0;i < n-1;i++)//this is the tricky part! cout << "Hip,"; cout << "Hurray!" << endl; }

Correct Answer

verifed

verified

void rec_cheers(int n)
{
usin...

View Answer

A binary search works with any array of numbers.

Correct Answer

verifed

verified

A recursive function can have only one stopping case.

Correct Answer

verifed

verified

Explain in your own words what recursion means (in connection with definitions of ideas and as a programming technique. )

Correct Answer

verifed

verified

Any definition that refers to things alr...

View Answer

Here is a recursive function.Write an iterative version of it.Hint: Be sure you get the number of copies of "Hip" right. void rec_cheers(int n) { using namespace std; if(1==n) cout << "Hurray!" << endl; else { cout << "Hip,"; rec_cheers(n-1); } }

Correct Answer

verifed

verified

void iter_cheers(int n)
{
for(...

View Answer

Write a recursive version of this iterative function: int g(int n) { int h = 1; while (n > 1) { h = h * n; n--; } return h; }

Correct Answer

verifed

verified

int g(int n)
{
if(0=...

View Answer

Iterative solutions are always possible.Why then,would we bother with recursive solutions to problems? What advantages do some recursive algorithms have over the iterative versions?

Correct Answer

verifed

verified

The recursive version may be c...

View Answer

A recursive function can have local variables.

Correct Answer

verifed

verified

The binary search algorithm in the text makes recursive on subarrays of the array passed to the algorithm.The range passed to the search function is first to last.The search algorithm makes recursive calls on the left or right subarray that target will be in,if the target is present.What are the left and right ends of the left subarray?


A) first,mid - 1
B) first,mid + 1
C) mid - 1,left
D) mid + 1,left
E) left,mid

Correct Answer

verifed

verified

Showing 21 - 40 of 40

Related Exams

Show Answer