hi

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the thresholds of traverse_maze function in section 9.2?

0

Consider the following function: void test_b(int n) { if (n>0) test_b(n-2); cout << n << " "; } What is printed by the call test_b(4)?

0 2 4

What are the traditional names for the queue operations that add an item?

enqueue

Suppose you are exploring a rectangular maze containing 10 rows and 20 columns. What is the maximum depth of recursion that can result if you start at the entrance and call traverse_maze?

200

What is the output produced by the function call exercise(4), for the following definition? void exercise(int n) { cout << n << endl; if (n > 1) exercise(n-1); }

4 3 2 1

Under what circumstances is a helper function useful?

A helper function is a private member function that is useful when a class requires an operation that should not be part of the public interface.

What statement is the most appropriate?

A queue can be used to buffer data in a FIFO fashionthat is being sent from a fast computer component to a slower component.

Which statement about queue is accurate?

A queue is a data structure of ordered entries such that entries can only be inserted at one end and removed at the other end .

What is the output of the following function with an argument of 3? void cheers(int n){if (n <= 1)cout << "Hurrah" << endl;else{cout << "Hip" << endl;cheers(n-1);}}

Hip Hip Hurrah

I have implemented the queue with a circular array, keeping track of first, last, and count (the number of items in the array). Suppose first is zero, and last is CAPACITY-1. What can you tell me about count?

count could be zero or CAPACITY, but no other values could occur.

What is the threshold of f1 function? int f1(int n) { if (n < 10) && (n > -10)) return 1; else return 1 + f1(n/10); }

1

What is the thresholds of random_fractal function in section 9.2?

1

What statement of the following is the most appropriate?

A recursive algorithm for a function implementation contains two kinds of cases: one or more cases that include a recursive call and one or more stopping cases in which the problem is solved without the use of any recursive calls.

What is the output of the following function with an argument of 4? void cheers(int n){ if (n <= 1)cout << "Hurrah" << endl;else{ if (n % 2 == 0) cout << "Hip" << endl; cheers(n-1); if (n % 2 == 1) cout << "Hip" << endl; } }

Hip Hip Hurrah Hip

What is the output of the following function with an argument of 4? void cheers(int n){ if (n <= 1)cout << "Hurrah" << endl;else{ if (n % 2 == 0) cout << "Hip" << endl; cheers(n-1); if (n % 2 == 1) cout << "Hop" << endl; }

Hip Hip Hurrah Hop

What is the output of the following function with an argument of 3? void cheers(int n){if (n <= 1)cout << "Hurrah" << endl;else{ cheers(n-1);cout << "Hip" << endl;}}

Hurrah Hip Hip

Suppose you are storing the items of a deque(section 8.4) in an array. Why do we need to use a circular array rather than putting all the items at the front?

If all items were kept at the front of the array, then it would be time-consuming to add or remove at the front.

In a circular array implementation of a queue(section 8.3), why does the constructor set last to the final index of the array?

If last is initialized to the final index of the array, then a new item is inserted correctly into an empty queue. Specifically, the statement last = next_index(last) will place the first item at data[first].

The following f1 function is a new constant member function of the queue class in section 8.3. template <class Item>Item queue<Item>::f1( ) const {assert(size( ) > 0);return data[last];} What is the best statement about f1 function?

It returns a copy of the item at the rear of the queue and is for the array version of the queue.

What technique is often used to prove the correctness of a recursive function?

Mathematical induction.

In the linked-list version of the queue class, which operations require linear time for their worst-case behavior?

None of these operations require linear time.

What information does an activation record(section 9.1) contain?

The activation record contains the return location of the function after it is finished. It also contains the values of the function's local variables and parameters.

Which of the description of the super_write_vertical function in section 9.1 is the most appropriate?

The digits of the number have been written, stacked vertically. If a number is negative, then a negative sign appears on top.

What is the best description of f1 function? unsigned int f1(unsigned int n) { if (n == 1) return 1; else return f1(n-1)+(2*n - 1); }

The f1 is a recursive function that finds the sum of the first n odd positive integers.

What happens if a recursive function does not have a base case?

The function call will never end because of an infinite sequence of recursive calls. In reality, the recursive calls will terminate abnormally when the memory storage for the run-time stack runs out.

In a circular array implementation of a queue(section 8.3), why don't we eliminate the count member variable, since the number of elements inthe queue can be determined from the values of front and rear?

The main problem is that we cannot tell the difference between an empty queue (which has front equal to next_index(rear)) and a full queue (which also has front equal to next_index(rear)).

Suppose top is called on a priority queue that has exactly two entries with equal priority. How is the return value of top selected?(Based on the textbook's implementation)

The one which was inserted first.

What queue function(section 8.1) is used to avoid queue overflow?

The size function returns number of items in the queue.

How are time stamps used in simulations(section 8.2)?

Time stamps are used to record arrival and waiting times for the items in a simulation. The time stamp is the number of simulated seconds that have passed since the start of the simulation. The waiting time of an item is the total number of seconds simulated so far, minus the time stamp.

What should we modify the palindromes program(section 8.2) so that uppercase and lowercase versions of letters are considered different?

We change the following two statements: q.push(toupper(letter));s.push(toupper(letter)); to q.push(letter);s.push(letter);

What statement of the following is the most appropriate? When implementing a stack, you need only keep track of one end of the list of entries, but when implementing a queue, you don't need to keep track of any entry. You Answered When implementing a stack, you do not need only keep track of one end of the list of entries, but when implementing a queue, you need to keep track of both ends of the list entries. When implementing a stack and queue,you need to keep track of both ends of the list entries. Correct Answer When implementing a stack, you need only keep track of one end of the list of entries, but when implementing a queue, you need to keep track of both ends of the list entries. When implementing a stack and queue, you need only keep track of one end of the list of entries.

When implementing a stack, you need only keep track of one end of the list of entries, but when implementing a queue, you need to keep track of both ends of the list entries.

What do we call an remove end of a queue?

front

What is the possible variant expression of f1 function? unsigned int f1(unsigned int n) { if (n == 1) return 1; else return f1(n-1)+(2*n - 1); }

n

Consider the following function: void super_write_vertical(int number) // Postcondition: The digits of the number have been written, // stacked vertically. If number is negative, then a negative // sign appears on top. // Library facilities used: iostream.h, math.h { if (number < 0) { cout << '-' << endl; super_write_vertical(abs(number)); } else if (number < 10) cout << number << endl; else { super_write_vertical(number/10); cout << number % 10 << endl; } } What values of number are directly handled by the stopping case?

number >= 0 && number < 10

Which description about s.pop and q.pop(in the pal.cxx(section 8.2)) is correct?

s.pop is popping an item out from the top of s stack. q.pop is removing an item from the front of q queue.

Which description about s.push and q.push(in the pal.cxx(section 8.2)) is correct?

s.push is pushing an item to the top of s stack. q.push is adding an item to the rear of q queue.

In all our examples of recursive thinking, the series of recursive calls eventuallyreached a call that did not involve further recursion that is, it reached a ___________.

stopping case


Ensembles d'études connexes

Chapter 12 introduction to trusts

View Set

pathophysiology evolve questions

View Set

Chapter 20 and 21 Practice Questions

View Set

Chapter 22: Assessing Peripheral Vascular System: Prep U Practice

View Set

Chapter 21: The Cardiovascular System

View Set

Advanced Control Charts for 6sigma

View Set

What is Knowledge? What is Truth? Vocab

View Set

Chapter 41: Antitubercular Drugs

View Set