set2

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the meaning of the acronym LIFO?

LIFO refers to a Last-In/First-Out data structure, in which items are taken out in the reverse order of their insertion.

What is the istream peek operation?

The istream peek operation returns the next character of the input stream without actually reading it. An istream processes characters in the order they are received.

What statement of the following is the most appropriate?

The node class defined in the textbook can be implemented as a template class, providing more flexibility to implement other container classes.

What is the possible variant expression of traverse_maze function in section 9.2?

The number of locations in the maze that do not yet have your name written on the ground

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 is the stack pop operation?

The pop operation reads and discards the next character from the input stream. A stack processes characters in the LIFO fashion.

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

The operation for removing an entry from a stack is traditionally called:

pop

Which of the following stack operations could result in stack underflow?

pop

The operation for adding an entry to a stack is traditionally called:

push

What do we call an entry end of a queue?

rear

For the array version of the stack(section 7.3), which one of the following maxNumberItem will return the maximum number of items that can be added to the stackwithout stack overflow?

size_type maxNumberItem( ) const { return CAPACITY - used; } and place it in stack2.h public member function area.

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.

void list_head_remove(node*& head_ptr) {node *remove_ptr; remove_ptr = previous_ptr->link( );previous_ptr->set_link( remove_ptr->link( ) ); delete remove_ptr;} Which one of the following selection is the implementation of the template version of the above function?

template <class Item>void list_head_remove(node<Item>*& head_ptr) {node<Item> *remove_ptr; remove_ptr = head_ptr;head_ptr = head_ptr->link( );delete remove_ptr; }

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

What is RAND_MAX in C++?

It is an integral constant expression. It specifies the largest return value of the rand function.

In the section 8.3 queue implementation, what is the value of the rear_ptr in an empty queue?

It is not specified and could be any value.

Which one of the expression is equivalent to the following? 2 * (A - B) + 3 + C

(((2 * (A - B)) + 3) + C)

If data is a circular array of CAPACITY elements, and last is an index into that array, what is the formula for the index after last?

(last + 1) % CAPACITY

What is the thresholds of random_fractal function in section 9.2?

1

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

1 2 3

"What is the value for the following postfix expression? 5 3 2 * + 4 - 5 +

12

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

Consider the usual algorithm for determining whether a sequence of parentheses is balanced. What is the maximum number of parentheses that will appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(()))?

3

What is the postfix of the following infix expression? 3 / A + (B + 12) - C.

3 A / B 12 + +C -

Suppose we call random_fractal with a width of 16 and an epsilon of 1. Then random_fractal will make two recursive calls, and each of those will make two more calls, and so on until width is less than or equal toepsilon. How many total calls will be made of random_fractal, including the original call?

31

Suppose we call random_fractal with a width of 8 and an epsilon of 0.5. Then random_fractal will make two recursive calls, and each of those will make two more calls, and so on until width is less than or equal toepsilon. How many total calls will be made of random_fractal, including the original call?

31

Here is an infix expression: 4+3*(6*3-12). Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. What is the maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression?

4

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 statement of the following is the most appropriate?

A stack is a Last-In/First-Out data structure.

What statement of the following is the most appropriate?

A template function is similar to an ordinary function with one important difference: The definition of a template function can depend on an underlying data type. The underlying data type is given a name—such as Item—but Item is not pinned down to a specific type anywhere in the function's implementation.

Which of the following applications may use a stack?

All of the above.

If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed?

DCBA

What statement of the following is the most appropriate?

Attempting to push an entry onto a full stack is an error known as a stack overflow.

Why is it a bad idea to have a size_t parameter for a template function?

Because many compilers, an int argument does not provide an exact match to size_t.

Which of the const iterator categories(section 6.3) is provided by a multiset?

Bidirectional iterator.

Consider the implementation of the stack using a partially-filled array. What goes wrong if we try to store the top of the stack at location [0] and the bottom of the stack at the last used position of the array?

Both push and pop would require linear time.

What is the meaning of FIFO?

FIFO (First-In/First-Out) refers to a data structure in which entries must be removed in exactly the same order that they were added.

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

Hip Hip Hip Hurrah Hip Hip Hip

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

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

Hurrah Hip Hip Hip

What statement of the following is the most appropriate?

In a single program, several different usages of a template function can result in several different instantiations.

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 are the prefix and postfix notation of the following expression? ((7+3) * 2)

Prefix: * + 7 3 2 Postfix: 7 3 + 2 *

When we declare a bag template class in bag.h and the bag class implementation in bag.template, how do we make a conncetion in between the bag.h and bag.template?

Put "#include "bag.template" " statement in the bag.h and right before "#endif" statement

When we declare a bag template class in bag.h and the bag class implementation in bag.template, how do we make a conncetion in between the bag.h and bag.template?

Put #include "bag.template" " statement in the bag.h and right before "#endif" statement"

What would be the best pseudocode for an algorithm to do the following? It reads an even number of characters then prints the first character, third character, fifth character, and so on. On a second output line, it prints the second character, fourth character, sixth character, and so on. Use two queues to store the characters.

Read the characters two at a time. Each pair of characters has the first character placed in queue number 1 and the second character placed in queue number 2. After all the reading is done, print all characters from queue number 1 on one line, and print all characters from queue number 2 on a second line.

What goes wrong if we try to put the front of the queue at the tail of the linked list?

Removals will be hard to implement.

What is the value of the postfix expression 6 3 2 4 + - *:

Something between -15 and -100

Consider the stack class given in section 7.1. Which of the following pseudo code(description) will define a new member function that returns the second entry from the top of the stack without changing the stack.

Store the top item in a local variable called t,then pop it. Look at the next item, storing it in another local variable called result. Push the t back on the stack, and return the result.

Consider the stack class given in section 7.1. Which of the following pseudo code(description) will define a new member function that returns the second entry from the top of the stack without changing the stack.

Store the top item in a local variable called t,then pop it. Look at the next item, storing it in another local variable called result. Push the t back on the stack, and return the result.

Why does the new node template class require two versions of the data member function, but the node in Chapter 5 needed only one? (Ch6)

The Chapter 5 data function returned a copy of the data, but the data function for the node template class returns a reference to the data.

Consider the following definition: template <class Item> Item maximal (Item a, Item b) { if (a > b) return a; else return b; } What restrictions are placed on the Item data type for a program that uses the maximal function?

The Item data type must have a copy constructor and a > operator defined.

What is the typical implementation of an STL stack?

The STL stack is typically implemented using a dynamic array.

Which of the following description of the reserve function in section 6.2 is the most appropriate?

The bag's current capacity is changed to the new_capacity (but not less than the number of items already in the bag). The insert function will work efficiently (without allocating new memory) until the new capacity is reached.

What is the bool_source class role in the car wash simulation(section 8.2)?

The bool_source class has one member variable, probability, which stores the probability that an activation of query will return true. This provides the possibility of a new customer at a second.

Which of the following description of the get_items function in section 6.2 is the most appropriate?

The description has been written as a prompt to the screen. Then n items have been read from cin and added to the collection.

In the section 8.3 queue implementation, what statement about destructor(linked list) is correct?

The destructor requires that front_ptr is NULL for an empty queue. Otherwise the call to list_clear does not work.

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 is the best statement about the following function, f1? void f1(unsigned int n) { if (n > 0) { cout << '*'; f1(n-1); cout << '!'; } }

The f1 is a recursive function that has one parameter that is a non-negative integer. The function writes out that number of asterisks ('*') to the screen, followed by that number of exclamation points ('!').

What is the istream ignore operation?

The ignore operation reads and discards the next character from the input stream. An istream processes characters in the order they are received.

How does the node iterator's implementation differentiate between the prefix and postfix versions of the ++ operator?

The postfix version puts the keyword int in its parameter list, whereas the prefix version leaves its parameter list empty. This is an artificial use of int; there is no actual int parameter.

What version of ++(prefix or postfix) is generally more efficient? and why?

The prefix version is more efficient because it doesn't have to make a copy of the iterator.

In a real computer, what will happen if you make a recursive call without making the problem smaller?

The run-time stack overflows, halting the program

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

The size function returns number of items in the queue.

What is a major difference between the header file for a toolkit of template functions and the header file for a toolkit of ordinary functions?

The template function toolkit header file must have a #include for the implementation file, but the ordinary version does not have this #include.

What is the best dexcription regarding where do we have the template prefix in a template function?

The template prefix defines the list of underlying data types that a template function depends upon. It appears immediately before the prototype and immediately before the implementation of the template function.

Entries in a stack are ordered". What is the meaning of this statement?"

There is a first entry, a second entry, and so on.

What would be the best description at the point in time when the car wash (section 8.2) simulation finishes?

These are cars that arrived during the simulation, but they are still waiting in line at the end of the simulation.

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 is the primary purpose of template functions?

To allow a single function to be used with varying types of arguments

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);

Which of the description on the section 6.6 bag is accurate?

We use a template parameter.

Which of the description on the chapter 5 bag is accurate?

We used a typedef to define the item.

What statement of the following is the most appropriate?

When a class depends on an underlying data type, the class can be implemented as a template class.

When should a function be implemented as a template function?

When the function depends on an underlying data type.

What is a stack overflow?

When the stack pointer exceeds the stack maximun boundary is called a stack overflow.

Suppose that a program wants to use both a bag of doubles and a bag of strings. Which version of the bag could you use?

You can use the array version of the template bag

Which functions from the node template class should not be used in the linked-list implementation of a stack(section 7.3)? And why? a. set_data b. set_link c. list_insert d. list_locate e. list_remove f. list_search

a, b, c, d, e, and f Because only the top item of the stack can be accessed.

What do we call the entry at the front end of the queue?

first entry.

Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

bag<int> b;

Which C++ library provides isalpha function?

cctype

Suppose we have an array implementation of the stack class, with ten items in the stack stored at data[0] through data[9]. The CAPACITY is 42. Where does the push member function place the new entry in the array?

data[10]


Conjuntos de estudio relacionados

PHP and MySQL Web Development - Chapter 5

View Set

Chapter 10: Interest Groups and Lobbying

View Set

Exam 2 - Ch. 8, 9, 10, 11, 12, 13, 14

View Set

PSI National Exam for Real Estate

View Set

Q2 Cumulative Test Review (U.S History)

View Set

Quiz 11 Burns and Emergency/Trauma

View Set