CS 3305 - Exam 2 Practice

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

Consider the binary tree: 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40 Suppose we remove the root, replacing it with something from the left subtree. What will be the new root?

5

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

push

Consider the following pseudocode: 1. Declare a stack of characters. 2. While ( there are more characters in the word to read ): 2a. Read a character. 2b. Push the character on the stack. 3. While ( the stack is not empty ): 3a. Print the stack's top character to the screen. 3b. Pop a character off the stack. What is printed for the input "carpets"?

steprac

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

pop

Consider this function declaration: void quiz(int i) { if (i > 1) { quiz(i / 2); quiz(i / 2); } std::cout << "*"; } What is printed by the function call quiz(5)?

"*******" (7 asterisks)

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

"4 2 0"

Select the one FALSE statement about binary trees: (A) Every binary tree has at least one node. (B) Every non-empty tree has exactly one root node. (C) Every node has at most two children. (D) Every non-root node has exactly one parent.

(A) Every binary tree has at least one node.

I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer. Which of these pointers will change during an insertion into a NONEMPTY queue? (A) Neither changes (B) Only front_ptr changes. (C) Only rear_ptr changes. (D) Both change.

(A) Neither changes

Suppose top is called on a priority queue that has exactly two entries with equal priority. How is the return value of top selected? (A) The implementation gets to choose either one. (B) The one which was inserted first. (C) The one which was inserted most recently. (D) This can never happen (violates the precondition)

(A) The implementation gets to choose either one.

Consider the binary tree: 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40 Consider the binary tree in the box at the top of this section. Which statement is correct? (A) The tree is neither complete nor full (B) The tree is complete but not full (C) The tree is full but not complete (D) The tree is both full and complete

(A) The tree is neither complete nor full

What is the primary purpose of template functions? (A) To allow a single function to be used with varying types of arguments (B) To hide the name of the function from the linker (preventing duplicate symbols) (C) To implement container classes (D) To permit the use of the debugger without the -gstabs flag

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

Suppose bag is a template class, what is the syntax for declaring a bag b of integers? (A) bag b; (B) bag<int> b; (C) bag of int b; (D) int bag b;

(B) bag<int> b;

Consider this prototype for a template function: template <class Item> void foo(Item x); What is the right way to call the foo function with an integer argument i? (A) foo( i ); (B) foo<int>( i ); (C) foo<Item>( i ); (D) foo(<int> i ); (E) foo(<Item> i );

(B) foo<int>( i );

Select the one true statement (A) Every binary tree is either complete or full. (B) Every complete binary tree is also a full binary tree. (C) Every full binary tree is also a complete binary tree. (D) No binary tree is both complete and full.

(C) Every full binary tree is also a complete binary tree.

One difference between a queue and a stack is: (A) Queues require dynamic memory, but stacks do not. (B) Stacks require dynamic memory, but queues do not. (C) Queues use two ends of the structure; stacks use only one. (D) Stacks use two ends of the structure, queues use only one.

(C) Queues use two ends of the structure; stacks use only one.

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? (A) The Item data type must be either int, double, or float. (B) The Item data type must be one of the built-in C++ data types. (C) The Item data type must have a copy constructor and a > operator defined. (D) None of the above restrictions apply.

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

Which of the following applications may use a stack? (A) A parentheses balancing program. (B) Keeping track of local variables at run time. (C) Syntax analyzer for a compiler. (D) All of the above.

(D) All of the above.

I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer. Which of these pointers will change during an insertion into an EMPTY queue? (A) Neither changes (B) Only front_ptr changes. (C) Only rear_ptr changes. (D) Both change.

(D) Both change.

When you write a template class, where does the template prefix occur? (A) Before the template class definition (B) Before each member function implementation. (C) Before any other template functions that manipulate the template class. (D) TWO of the above answers are correct. (E) All of the (A), (B), and (C) are correct.

(E) All of the (A), (B), and (C) are correct.

Consider the binary tree: 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40 There is a tree in the box at the top of this section. What is the order of nodes visited using an in-order traversal?

1 2 3 14 7 10 11 40 30

What is the minimum number of nodes in a full binary tree with depth 3?

15

What is the minimum number of nodes in a complete binary tree with depth 3?

8

In a single function declaration, what is the maximum number of statements that may be recursive calls?

There is no fixed maximum

What is the maximum depth of recursive calls a function may make?

There is no fixed maximum

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

data[10]

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

number < 10


Conjuntos de estudio relacionados

Chapter 15: Organizational Design, Effectiveness, and Innovation

View Set

Ch 27_ Child with Cerebral Dysfunction

View Set

Pentest+ Lesson 11 - Targeting Mobile Devices

View Set