CS 202 Final

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The infix expression (a + b) * (c - d / e) + f is equivalent to the postfix expression ab + cde /-* f + -True -False

True

The performance of bubble sort can be improved if we stop the sorting process as soon as we find that, in an iteration, no swapping of elements takes place. -True -False

True

The sequential search algorithm does not assume that the list is sorted. -True -False

True

To design a recursive function, you must determine the limiting conditions. -True -False

True

You can use a recursive algorithm to find the largest element in an array. -True -False

True

How many pointers are needed to build a linked list in a backward manner? -Three -Two -Four -One

Two

A queue is a data structure in which the elements are ____. -added and deleted in the middle -added to and deleted from the rear -added to and deleted from the front -added to the rear and deleted from the front

added to the rear and deleted from the front

Each node of a linked list must store the data as well as the ____________________ of the next node in the list.

address

The function ____ can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program. -what -look -assert -check

assert

Which of the following is a valid C++ statement? -assert(0 = divisor); -assert(divisor != 0); -assert(divisor is 0); -assert(divisor 0);

assert(divisor != 0);

In a linked list, the link component of each node is a(n) ____________________.

pointer

You can perform the operation ____ to remove the top element from the stack. -push -dequeue -top -pop

pop

The type vector provides the expression ____________________, which deletes the last element of vecList.

pop_back()

If you initially declare a vector object and do not specify its size, then in order to add elements to the vector object, we use the function ____________________.

push_back

The type vector provides the expression ____________________, which inserts a copy of elem into vecList at the end.

push_back(elem)

Consider the following code: template <class Type> int doublyLinkedList<Type>::length() const { ____ } The statement that provides the length of the linked list is ____. -cout <<< count; -return count; -return next; -destroy();

return count;

The class ____ is designed to deal with errors that can be detected only during program execution. -error -exception -runtime_error -logic_error

runtime_error

Data can be organized and processed sequentially using an array, called a(n) ____ list. -linked -ascending -sequential -ordered

sequential

The logic_error and runtime_error classes are defined in the header file ____. -exception -stdexcept -stdex -stdlib

stdexcept

Consider the following code. int fact(int num) { if (num == 0) return 1; else return num * fact(num - 1); } The function fact is an example of a(n) ____________________ recursive function.

tail

When an exception is thrown, if the program does not handle the exception, then the function ____ is called to terminate the program. -what -close -log -terminate

terminate

Every node in a doubly linked list has two pointers: ____ and ____. -back; next -previous; forward -current; forward -top; bottom

back; next

If the operator new cannot allocate memory space, this operator throws a(n) ____________________ exception.

bad_alloc

The recursive algorithm must have one or more base cases, and the general solution must eventually be reduced to a(n) ____________________.

base case

A(n) ____________________ search uses the "divide and conquer" technique to search the list.

binary

In order to apply a(n) ____________________ search, the list must be sorted.

binary

A(n) ____ is an occurrence of an undesirable situation that can be detected during program execution. -crash -bug -misfire -exception

exception

The class ____ is the base of the classes designed to handle exceptions. -runtime_error -exception -logic_error -class

exception

An exception is an occurrence of an undesirable situation that can be detected during program compilation. -True -False

false

____________________ techniques are used when it is too expensive or dangerous to experiment with real systems.

Simulation

If you want to use the class vector in your program, you must include the following statement: ____________________.

#include <vector>

The steps involved in inserting a new item at the beginning of an unordered linked list are ____. -1. Create a new node. 2. Store the new item in the new node. 3. Insert the node before first. 4. Decrement the counter by 1. -1. Create a new node. 2. Store the new item in the new node. 3. Insert the node before first. 4. Increment the counter by 1. -1. Create a new node. 2. Insert the node before first. 3. Increment the counter by 1. -1. Create a new node. 2. Store the new item in the new node. 3. Insert the node before first.

-1. Create a new node. 2. Store the new item in the new node. 3. Insert the node before first. 4. Increment the counter by 1.

int mystery(int list[], int first, int last) { if (first == last) return list[first]; else return list[first] + mystery(list, first + 1, last); } Consider the accompanying definition of the recursive function mystery. Given the declaration: int alpha[5] = {1, 4, 5, 8, 9}; what is the output of the following statement? cout << mystery(alpha, 0, 4) << endl; -1 -27 -18 -35

27

int recFunc(int num) { if (num >= 10) return 10; else return num * recFunc(num + 1); } Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << recFunc(10) << endl; -11 -10 -100 -110

10

In a sequential search, if a search item is not in a list of 1000 elements, then ____ key comparisons will be made. -100,000 -1000 -100 -10,000

1000

The postfix expression 2 4 6 * + 15 - 21 7 / + = evaluates to ____. -24 -14 -4 -26

14

Consider the following list: int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95} When performing a binary search, the element to be found is first compared with ____. -95 -25 -39 -4

39

Consider the following definition of the recursive function print. void print(int num) { if (num > 0) { cout << num << " "; print(num - 1); } } What is the output of the following statement? print(4); -4 3 2 1 0 -0 1 2 3 4 -4 3 2 1 -1 2 3 4

4 3 2 1

The postfix expression 5 6 + 4 * 10 5 / - = evaluates to ____. -44 -10 -42 -30

42

Consider the following recursive definition, where n is a positive integer. F(1) = 3 F(n) = F(n - 1) + 1 if n > 1 The value of F(3) is ____________________.

5

Consider the following definition of the recursive function mystery. int mystery(int num) { if (num <= 0) return 0; else if (num % 2 == 0) return num + mystery(num - 1); else return num * mystery(num - 1); } What is the output of the following statement? cout << mystery(5) << endl; -50 -180 -120 -65

50

Which of the following rules should you follow to solve the Tower of Hanoi problem? -You can remove disks only from the first needle. -A smaller disk can be placed on top of a larger disk. -The removed disk must be placed on a smaller disk. -Only two disks can be moved at a time.

A smaller disk can be placed on top of a larger disk.

C++ provides all the exception classes you will ever need. -True -False

False

In a bubble sort, the smaller elements move toward the bottom, and the larger elements move toward the top of the list. -True -False

False

Infinite recursions execute forever on a computer. -True -False

False

Memory for the components of an array does not need to be contiguous. -True -False

False

Postfix notation requires the use of parentheses to enforce operator precedence. -True -False

False

The expression a + b is the same in both infix notation and postfix notation. -True -False

False

The size of a list is fixed and cannot be increased or decreased. -True -False

False

When you build a linked list in the backward manner, a new node is always inserted at the end of the linked list. -True -False

False

You can use the pointer head of a linked list to traverse the list. -True -False

False

When division by zero occurs and the problem is not addressed, the program crashes with an error message that is ____ dependent. -platform -code -computer -IDE

IDE

Which of the following is a basic operation on singly linked lists? -Determine whether the list is nearly full. -Retrieve the data of an arbitrary node. -Make a copy of the linked list. -Swap the head and the last nodes.

Make a copy of the linked list.

void printNum(int num) // Line 1 { // Line 2 if (n < 0) // Line 3 cout << "Num is negative" << endl; // Line 4 else if (num == 0) //Line 5 cout << "Num is zero" << endl; //Line 6 else //Line 7 { //Line 8 cout << num << " "; //Line 9 printNum(num - 1); //Line 10 } //Line 11 } //Line 12 Consider the accompanying definition of a recursive function. Which of the statements represent the base case? -Statements in Lines 3-6 -Statements in Lines 5 and 6 -Statements in Lines 5-10 -Statements in Lines 3 and 4

Statements in Lines 3-6

int foo(int n) //Line 1 { //Line 2 if (n == 0) //Line 3 return 0; //Line 4 else //Line 5 return n + foo(n - 1); //Line 6 } //Line 7 Consider the accompanying definition of a recursive function. Which of the statements represent the general case? -Statements in Lines 4, 5, and 6 -Statements in Lines 5 and 6 -Statements in Lines 1-6 -Statements in Lines 3 and 4

Statements in Lines 5 and 6

struct nodeType { int info; nodeType *link; }; nodeType *head, *p, *q, *newNode; newNode = new nodeType; Consider the accompanying code. What is the effect of the following statement? newNode->info = 50; -Places the node at location 50 -Cannot be determined from this code -Creates a new node -Stores 50 in the info field of the newNode

Stores 50 in the info field of the newNode

A doubly linked list can be traversed in either direction. -True -False

True

A queue is a First In First Out data structure. -True -False

True

All of the values in a list have the same type. -True -False

True

Assume that n = 1000. To sort the list, insertion sort makes about 250,000 item assignments. -True -False

True

Every call to a recursive function requires the system to allocate memory for the local variables and formal parameters. -True -False

True

In a recursive function, the base case stops the recursion. -True -False

True

In the array representation of a stack, if a value called stackTop indicates the number of elements in the stack, then stackTop-1 points to the top item of the stack. -True -False

True

Linked lists allow you to overcome the size limitations of an array data type. -True -False

True

The following expression (a - b) * (c + d) is equivalent to which of the following postfix expressions? a b - c d + * - + * a b c d a b - + c d * a b c d - + *

a b - c d + *

The elements at the ____________________ of the stack have been in the stack the longest.

bottom

A(n) ____________________ block specifies the type of exception it can catch and contains an exception handler.

catch

Which of the following blocks is designed to catch any type of exception? -catch(...){ } -catch(exception){ } -catch(*){ } -catch(){ }

catch(...){ }

Which of the following statements creates a new exception class? -class myExceptionClass {} throws exception; -class myExceptionClass {} extends exception; -class myClass {} implements exception; -class myClass {};

class myClass {};

The ____________________ constructor executes when an object is declared and initialized using another object.

copy

Which of the following statements appears in the insert function of a doubly linked list? -trailCurrent++; -newNode++; -count++; -current++;

count++;

To describe a queuing system, we use the term ____ for the object receiving the service. -customer -server -provider -receiver

customer

The ____________________ of the catch block parameter specifies the type of exception that the catch block can catch.

data type

Consider the following code which deletes all the nodes in a linked list. void doublyLinkedList<Type>::destroy() { nodeType<Type> *temp; //pointer to delete the node while (first != nullptr) { temp = first; first = first->next; ____ } last = nullptr; count = 0; } Which of the following is the missing statement? -destroy temp; -delete first; -delete temp; -clear temp;

delete temp;

A(n) ____________________ linked list is a linked list in which every node has a next pointer and a back pointer.

doubly

The type vector provides the function ____________________, which returns the first element in the vector object.

front()

In a linked list, the address of the first node in the list is stored in a separate location, called the ____ or first. -top -head -pointer -front

head

If a function A calls a function B and function B calls function A, then function A is ____________________ recursive.

indirectly

Suppose that function A calls function B, function B calls function C, function C calls function D, and function D calls function A. Function A is then ____________________ recursive.

indirectly

If every recursive call results in another recursive call, then the recursive function (algorithm) is said to have ____ recursion. -infinite -indefinite -unlimited -tail

infinite

For classes that include pointer data members, the assignment operator must be explicitly ____________________.

overloaded

The class ____ is designed to deal with illegal arguments used in a function call. -bad_argument -invalid_argument -invalid_call -illegal_argument

invalid_argument

In a bubble sort for list of length n, the first step is to compare elements ____. -list[0] and list[1] -list[0] and list[n-1] -list[0] and list[n] -list[n-1] and list[n+1]

list[0] and list[1]

If you execute an infinite recursive function on a computer, the function executes until the system runs out of ____________________.

memory

With the binary search algorithm, ____ key comparison(s) is/are made in the successful case—the last time through the loop. -n -n-2 -two -one

one

The class ____________________ deals with the string subscript out of range error.

out_of_range

The postfix expression 14 2 5 + = will generate an error, because ____. -it contains an illegal operator -there will be too many elements in the stack when the equal sign is encountered -it does not have enough operands -it has too many operators

there will be too many elements in the stack when the equal sign is encountered

How many needles are used in the Tower of Hanoi problem? -four -three -one -two

three

Throwing an exception is typically done using the ____________________ statement.

throw

In a(n) ____________________ simulation, the clock is implemented as a counter, and the passage of, say, one minute can be implemented by incrementing the counter by 1.

time driven

The ____ element of the stack is the last element added to the stack. -bottom -head -tail -top

top

The statements that may generate an exception are placed in a ____ block. -finally -try -catch -throw

try

A variable declared using the vector type is called a ____. -vector container -vector array -vector element -vector list

vector container

The statement ____ creates the vector object vecList of size size. -vector<elemType> vecList(size); -vector(size) vecList<elementType> -vector[elemType] vecList(size); -vector{elemType::size} vecList;

vector<elemType> vecList(size);

Which statement declares intList to be an empty vector? -vector<int> intList(0); -vector intList(); -vector<int> intList(10); -vector<int> intList;

vector<int> intList;

The function ____ returns a string containing an appropriate message. -log -where -when -what

what

What is the output of the following code? queueType<int> queue; int x, y; x = 2; y = 3; queue.addQueue(x); queue.addQueue(y); x = queue.front(); queue.deleteQueue(); queue.addQueue(x+2); queue.addQueue(x); queue.addQueue(y - 3); y = queue.front(); queue.deleteQueue(); cout << "x = " << x << endl; cout << "y = " << y << endl; -x = 2 y = 3 -x = 4 y = 3 -x = 2 y = 4 -x = 3 y = 2

x = 2 y = 3

In the array representation of a stack, the stack is initialized simply by setting stackTop to ____________________.

zero

When a stack is implemented as an array, the array is empty if the value of stackTop is ____. -nonzero -one -zero -equal to the size of the array

zero


संबंधित स्टडी सेट्स

Chpt 2 differential cost, an opportunity cost, or a sunk cost

View Set

Drug resistant bacteria (MRSA, VRE)

View Set

Final Exam (Balance Sheet & Income Statement)

View Set

Lecture 5 - The Dark Triad of Personality

View Set