Final Exam

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

True or False: During the sorting phase of insertion sort, the array containing the list is divided into two sublists, sorted and unsorted.

True

True or False: Every (recursive) call also has its own set of parameters and local variables.

True

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

True

True or False: If no exception is thrown in a try block, all catch blocks associated with that try block are ignored.

True

True or False: In C++, any class can be considered an exception class.

True

True or False: In a linked list, if a new item is always inserted at the beginning or at the end of the list and the data read is unsorted, the linked list will be unsorted.

True

True or False: In a linked list, if a new item is always inserted at the beginning or at the end of the list and the data we read is unsorted, the linked list will be unsorted.

True

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

True

True or False: It is difficult to construct an iterative solution for the Tower of Hanoi problem.

True

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

True

True or False: One of the typical ways of dealing with exceptions is to use an if statement.

True

True or False: Suppose that L is a sorted list of size 1024, and we want to determine whether an item x is in L. From the binary search algorithm, it follows that every iteration of the while loop cuts the size of the search list by half.

True

True or False: The binary search algorithm can be written iteratively or recursively.

True

True or False: The following is a valid recursive definition to determine the factorial of a non-negative integer. 0! = 1 1! = 1 n! = n * (n - 1)! If n > 0

True

True or False: The following is an example of a recursive function. void print(int x) { if (x > 0) { cout << x << " " ; print (x - 1); }

True

True or False: The length of a linked list is the number of nodes in the list.

True

True or False: The length of a linked list is the number of nodes in the list. Selected Answer: Answers:

True

True or False: The selection sort algorithm finds the location of the smallest element in the unsorted portion of the list.

True

True or False: The sequential search algorithm does not require that the list be sorted.

True

True or False: There are usually two ways to solve a particular problem: iteration and recursion.

True

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

True

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

True

The behavior of merge sort is ____ in the worst case and ____ in the average case.

a. O(nlog2n), O(nlog2n)

Which of the following solutions is easier to construct for the Tower of Hanoi problem? a. Recursive c. Procedural b. Iterative d. Step-by-step

a. Recursive

A queue is a data structure in which the elements are ____.

a. added to the rear and deleted from the front

The postfix expression 3 5 + 2 ; 6 - = will generate an error, because it ____.

a. contains an illegal operator

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

a. one

A(n) ____ is a list of homogenous elements in which the addition and deletion of elements occurs only at one end.

a. stack

The ____ element of the stack is the last element added to the stack.

a. top

After the second iteration of bubble sort for a list of length n, the last ____ elements are sorted.

a. two

When a stack is implemented as an array, the array is empty if the value of stackTop is ____.

a. zero

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

a. IDE

Consider the accompanying statements. The list is empty if the pointer first is ____.

a. NULL

To use the assert function in your program, you should include the statement ____.

#include <cassert>

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;

a. Stores 50 in the info field of the newNode

True of False: If the catch block with an ellipses (in the heading) is needed, then it should be the first catch block in a sequence of try/catch blocks.

False

True of False: If you try to add a new item to a full stack, the resulting condition is called an outflow.

False

True of False: In the array representation of a stack, an unlimited number of elements can be pushed onto the stack.

False

True of False: In the linked implementation of stacks, the memory to store the stack elements is allocated statically.

False

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

False

True of False: The bottom element of the stack is the last element added to the stack.

False

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

False

True of False: The order of the catch blocks does not affect the program.

False

True or False: A catch block specifies the type of exception it can catch and immediately terminates the program.

False

True or False: A linked list is a random access data structure.

False

True or False: An object that is being thrown cannot be an anonymous object.

False

True or False: During the second iteration of a selection sort, the smallest item is moved to the top of the list.

False

True or False: If a recursive solution to a problem exists, a programmer should always opt to use it over any iterative solution that exists.

False

True or False: If n = 1000, then to sort the list, selection sort makes about 50,000 key comparisons.

False

True or False: In a binary search, first, the search item is compared with the last element of the list.

False

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

False

True or False: In the Tower of Hanoi recursive program, if needle 1 contains three disks, then the number of moves required to move all three disks from needle 1 to needle 3 is 8.

False

True or False: Infinite recursions execute forever on a computer.

False

True or False: It is not possible to create an ordered linked list.

False

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

False

True or False: The following is an example of a recursive function, where nextNum is a function such that nextNum(x) = x + 1. int recFunc(int x) { return nextNum(nextNum(x)); }

False

True or False: The swap function of quick sort is written differently from the swap function for selection sort.

False

True or False: We deallocate the memory for a linked list by calling the operator clear.

False

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

False

True or False: When you build a linked list in the backward manner, a new node is always inserted at the end of the linked list. Selected Answer: Answers:

False

True or False: With recursion, the base case must eventually be reduced to a general case.

False

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

False

True or False: You can use the pointer head of a linked list to traverse the list. Selected Answer: Answers:

False

True or False: You deallocate the memory for a linked list by calling the operator clear.

False

Any sorting algorithm that sorts a list of n distinct elements by comparison of the keys only, in its worst case, makes at least ____________________ key comparisons.

O(nlog2n) O(nlogn)

Consider the following list: int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95} When performing a binary search for 75, after the first comparison, the search is restricted to ____.

d. list[6]...list[11]

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;

a. Stores 50 in the info field of the newNode

Which of the following is a valid C++ statement? a. assert(divisor != 0); b. assert(divisor is 0); c. assert(divisor 0); d. assert(0 = divisor);

a. assert(divisor != 0);

The try block is followed by one or more ____ blocks.

a. catch

The class ____ is the base of the classes designed to handle exceptions.

a. exception

Each node of a singly linked list has two components: ____ and ____.

a. info, link

The link field of the last node of a linked list is ____.

a. nullptr

Data can be organized and processed sequentially using an array, called a(n) ____ list.

a. sequential

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

a. terminate

A sequential search of an n-element list takes ____ key comparisons on average to determine whether the search item is in the list.

b. n/2

In evaluating a postfix expression, when an equal sign (=) is encountered, how many elements must the stack contain so that no error is generated?

b. one

You can perform the add operation, called ____, to add an element onto the stack.

b. push

A definition in which something is defined in terms of a smaller version of itself is called a(n) ____definition.

b. recursive

To describe a queuing system, we use the term ____ for the object that provides the service.

b. server

A recursive function in which the last statement executed is the recursive call is called a(n) ____recursive function.

b. tail

How many pointers are needed to build a linked list in a backward manner?

b. Two

The ____________________ search algorithm is the optimal worst-case algorithm for solving search problems by using the comparison method.

binary

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

bottom

If a formal parameter is a value parameter, the ____________________ constructor provides the formal parameter with its own copy of the data.

copy

The ____________________ constructor can make an identical copy of a linked list.

copy

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

copy

The ____________________ constructor is called when a stack object is passed as a (value) parameter to a function.

copy

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

d. Make a copy of the linked list.

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

d. assert

template <class Type> ____ doublyLinkedList<Type>::isEmptyList() const { return (first == NULL); } Consider the accompanying statements. The operation returns true if the list is empty; otherwise, it returns false. The missing code is ____.

d. bool

template <class Type> ____ doublyLinkedList<Type>::isEmptyList() const { return (first == nullptr); } Consider the accompanying statements. The operation returns true if the list is empty; otherwise, it returns false. The missing code is ____.

d. bool

In a sequence of try/catch blocks, the last catch block of that sequence should be ____.

d. catch(...){ }

Which of the following blocks is designed to catch any type of exception? a. catch(exception){ } b. catch(){ } c. catch(*){ } d. catch(...){ }

d. catch(...){ }

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

d. count++;

Which of the following correctly initializes a doubly linked list in the default constructor? a. head = NULL; back = NULL; b. head = 0; back = 0; count = 0; c. first = 0; last = 0; d. first = NULL; last = NULL; count = 0;

d. first = NULL; last = NULL; count = 0;

When building a linked list in the ____ manner, a new node is always inserted at the end of the linked list.

d. forward

In a linked list, the address of the first node in the list is stored in a separate location, called the ____ or first.

d. head

The class ____ is designed to deal with illegal arguments used in a function call.

d. invalid_argument

Which of the following classes is derived from the class runtime_error? a. out_of_range b. length_error c. bad_alloc d. overflow_error

d. overflow_error

Suppose that the pointer head points to the first node in the list, and the link of the last node is nullptr. The first node of the linked list contains the address of the ____ node.

d. second

Every node (except of the last node) in a singly linked list contains ____.

d. the address of the next node

When an exception is thrown in a function, the function-call stack is ____ so that the exception can be caught in the next try/catch block.

d. unwound

What is the output of the following code? stackType<int> stack; int x, y; x = 4; y = 2; stack.push(6); stack.push(x); stack.push(x + 1); y = stack.top(); stack.pop(); stack.push(x + y); x = stack.top(); stack.pop(); cout << "x = " << x << endl;

d. x = 9

The ____________________ operator advances the iterator to the next node in the linked list.

increment

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

A(n) ____________________ is an object that produces each element of a container, such as a linked list, one element at a time.

iterator

In a circular linked list with more than one node, it is convenient to make the pointer first point to the ____________________ node of the list.

last

To deal with logical errors in a program, such as a string subscript out of range or an invalid argument to a function call, several classes are derived from the class ____.

logic_error

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

memory

The ____________________ elements of a stack and queue should not be accessed directly.

middle

For a list of length n, the bubble sort makes exactly ____________________ key comparisons.

n(n-1)/2

Every recursive definition must have at least ____ base case(s).

one

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

overloaded

In a quick sort, all of the sorting work is done by the function ____________________.

partition

A sequence of branches in a comparison tree is called a(n) ____________________.

path

The first step in the quick sort partition algorithm is to determine the ____________________ and swap it with the first element in the list.

pivot

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

pointer

In ____________________ notation, operators are written after the operands.

postfix

A(n) ____________________ system consists of servers and queues of objects waiting to be served.

queuing

An array is a(n) ____________________ access data structure.

random

Every ____ call requires that the system allocate memory space for its formal parameters and local variables and then deallocate the memory space when the function exits.

recursive

Recursive algorithms are implemented using ____________________ functions.

recursive

The top node of a comparison tree is call the ____________________ node.

root

The class ____ is designed to deal with errors that can be detected only during program execution.

runtime_error

A linked list must be searched ____________________, starting from the first node.

sequentially

In a queuing system, we use a(n) ____________________ variable to set the status of the server.

string

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

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 one.

time driven

When describing a queuing system, we use the term ____________________ time to refer to the time it takes to serve a customer.

transaction

The statements that may generate an exception are placed in a ____ block.

try

In a queuing system, every customer has a customer number, arrival time, ____________________ time, transaction time, and departure time.

waiting

If you want to include members in your exception class, you typically include the function ____.

what

In C++, the dereferencing operator is represented by the ____________________ symbol.

*

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

0 zero

In the case of an unsuccessful search, it can be shown that for a list of length n, a binary search makes approximately ____________________ key comparisons.

2log2n 2logn

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

Which of the following rules should you follow to solve the Tower of Hanoi problem?

A smaller disk can be placed into a larger disk.

Let f and g be real-valued functions. Assume that f and g are nonnegative, that is, for all real numbers n, f (n) 0 and g(n) 0. We say that f (n) is ____________________ of g(n), written f (n) = O(g(n)), if there exist positive constants c and n0 such that f (n) cg(n) for all n n0.

Big-O

____ control structures use a looping structure to repeat a set of statements.

Iterative

In general, the selection sort algorithm is good only for small lists because ____________________ grows rapidly as n grows.

O(n2)

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

True

In the late 1950s, the Australian philosopher and early computer scientist Charles L. Hamblin proposed a scheme in which the operators follow the operands (postfix operators), resulting in the ____________________ notation.

Reverse Polish reverse polish reverse Polish

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

Simulation simulation

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

True

True of False: 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

True of False: The default constructor for the linked implementation of a stack initializes the stack to an empty state when a stack object is declared.

True

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

True

____ control structures use a looping structure, such aswhile,for, ordo...while, to repeat a setof statements.

a. Iterative

Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << recFunc(10) << endl;

a. 10

Assuming the following list declaration, which element is at the position 0 after the first iteration of selection sort? int list[] = {16, 30, 24, 7, 62, 45, 5, 55}

a. 5

Which of the following solution methods would be the best choice for a mission control system? a. Iterative c. Indirect recursive b. Direct recursive d. Infinite recursive

a. Iterative

____ sort requires knowing where the middle element of the list is.

a. Merge

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

address

The nodes of a standard ordered list (as constructed in the text) are in ____________________ order.

ascending

Let f be a function of n. By the term ____________________, we mean the study of the function f as n becomes larger and larger without bound.

asymptotic

With insertion sort, the variable firstOutOfOrder is initialized to ____, assuming n is the length of the list.

b. 1

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

b. 14

For a list of length n, selection sort makes ____ item assignments.

b. 3(n - 1)

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 represents the base case?

b. Statements in Lines 3 and 4.

The ____ case is the case for which the solution to an equation is obtained directly.

b. base

The sequential search algorithm uses a(n) ____ variable to track whether the item is found.

b. bool

Tracing through ____ recursion is more tedious than tracing other recursive forms.

b. indirect

For a list of length n, insertion sort makes ____ key comparisons, in the worst case.

b. n(n - 1)/2

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 != NULL) { temp = first; first = first->next; ____ } last = NULL; count = 0; } Which of the following is the missing statement?

b. delete temp;

The ____ deallocates the memory occupied by the nodes of a list when the class object goes out of scope.

b. destructor

In a linked list, the order of the nodes is determined by the address, called the ____, stored in each node.

b. link

A linked list is a collection of components called ____.

b. nodes

A linked list is a collection of components, called ____.

b. nodes

template <class Type> ____ doublyLinkedList<Type>::isEmptyList() const { return (first == nullptr); } Consider the statements above. The list is empty if the pointer first is ____.

b. nullptr

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

b. return count;

Which of the following statements throws a valid exception in C++? a. throw.function(); b. throw 2; c. 4 throw; d. throws str;

b. throw 2;

If you try to add a new item to a full stack, the resulting condition is called a(n) ____.

b. overflow

The deleteNode operation (if the item to be deleted is in a doubly linked list) requires the adjustment of ____ pointer(s) in certain nodes.

b. two

Popping an element from an empty stack is called ____.

b. underflow

The ____ algorithm attempts to find solutions to a problem by constructing partial solutions and then making sure that any partial solution does not violate the problem requirements.

backtracking

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

base case

A comparison tree is a(n) ____________________ tree.

binary

To construct a search algorithm of the order less than log2n, it cannot be ____________________ based.

comparison

The following C++ function implements the ____________________ sort algorithm. template <class elemType> void Sort(elemType list[], int length) { for (int iteration = 1; iteration < length; iteration++) { for (int index = 0; index < length - iteration; index++) { if (list[index] > list[index + 1]) { elemType temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp; } } } }

bubble

The formula to find the index of the middle element of a list is ____.

c. (first + last) / 2

Assume that list consists of the following elements. What is the result after bubble sort completes? int list[] = {2, 56, 34, 25, 73, 46, 89, 10, 5, 16};

c. 2 5 10 16 25 34 46 56 73 89

If n = 1000, to sort the list, bubble sort makes about ____ item assignments.

c. 250,000

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

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

c. 4 3 2 1

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

c. 42

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?

c. Statements in Lines 3-6

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

c. The removed disk must be placed on one of the needles.

A stack can be implemented as either a(n) ____ or a linked structure.

c. array

We can trace the execution of a comparison-based algorithm by using a graph called a ____.

c. comparison tree

To describe a queuing system, we use the term ____ for the object receiving the service.

c. customer

A function is called ____ if it calls itself.

c. directly recursive

Which of the following correctly states the quick sort algorithm? a. if (the list size is greater than 1) { a. Partition the list into four sublists. b. Quick sort sublist1. c. Quick sort sublist2. d. Quick sort sublist3. e. Quick sort sublist4. d. Combine the sorted lists. } b. a. Find the location of the smallest element. b. Move the smallest element to the beginning of the unsorted list. c. if (the list size is greater than 1) { a. Partition the list into two sublists, say lowerSublist and upperSublist. b. Quick sort lowerSublist. c. Quick sort upperSublist. d. Combine the sorted lowerSublist and sorted upperSublist. } d. if the list is of a size greater than 1 { a. Divide the list into two sublists. b. Merge sort the first sublist. c. Merge sort the second sublist. d. Merge the first sublist and the second sublist. }

c. if (the list size is greater than 1) { a. Partition the list into two sublists, say lowerSublist and upperSublist. b. Quick sort lowerSublist. c. Quick sort upperSublist. d. Combine the sorted lowerSublist and sorted upperSublist. }

Which of the following is a basic operation performed on a queue? a. push b. pop c. isEmptyQueue d. top

c. isEmptyQueue

In a bubble sort for list of length n, the first step is to compare elements ____.

c. list[0] and list[1]

When working with the unsorted portion of a list, the second step in a selection sort is to ____.

c. move the smallest element to the beginning of the unsorted list

A sequential search of an n-element list takes ____ key comparisons if the item is not in the list.

c. n

In the average case, sequential search typically searches ____.

c. one half of the list

You can perform the operation ____ to remove the top element from the stack.

c. pop

A technique in which one system models the behavior of another system is called ____.

c. simulation

The addition and deletion of elements of the stack occurs only at the ____ of the stack.

c. top

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;

c. x = 2 y = 3

What is the purpose of the following code? current = head; while (current != NULL) { //Process current current = current->link; }

c. Traversal of a linked list

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

c. a b - c d + *

Every node in a doubly linked list has two pointers: ____ and ____.

c. back; next

Because each node of a linked list has two components, we need to declare each node as a(n) ____.

c. class or struct

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

c. count++;

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? a. clear temp; b. delete first; c. delete temp; d. destroy temp;

c. delete temp;

A(n) ____ is an occurrence of an undesirable situation that can be detected during program execution.

c. exception

Which of the following correctly initializes a doubly linked list in the default constructor? a. first = 0; last = 0; b. head = nullptr; back = nullptr; c. first = nullptr; last = nullptr; count = 0; d. head = 0; back = 0; count = 0;

c. first = nullptr; last = nullptr; count = 0;

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

c. return count;

Suppose that the pointer head points to the first node in the list, and the link of the last node is NULL. The first node of the linked list contains the address of the ____ node.

c. second

Data can be organized and processed sequentially using an array called a(n) ____ list.

c. sequential

The logic_error and runtime_error classes are defined in the header file ____.

c. stdexcept

The function ____ returns a string containing an appropriate message.

c. what

What is the output of the following program segment? (The class unorderedLinkedList is as defined in the book.) unorderedLinkedList<int> list; list.insertFirst(6); list.insertLast(5); list.insertFirst(4); list.insertFirst(8); list.insertLast(10); list.deleteNode(4); list.insertFirst(1); list.print();

c. 1 8 6 5 10

A stack is a(n) ____ data structure.

c. LIFO

A linked list in which the last node points to the first node is called a(n) ____________________ linked list.

circular

In a(n) ____________________ array, the first array position immediately follows the last array position.

circular

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

d. 6 4 2 3

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(8) << endl;

d. 720

The behavior of quick sort is ____ in the worst case and ____ in the average case.

d. O(n^2), O(nlog<2>n)

Consider the accompanying definition of a recursive function. Which of the statements represent the general case?

d. Statements in Lines 5 and 6

Consider the accompanying definition of a recursive function. Which of the statements represent the general case?

d. Statements in Lines 7-11

When moving array values for insertion sort, to move list[4] into list[2], first ____.

d. copy list[4] into temp

A stack can be implemented as either an array or a(n) ____ structure.

d. linked

If a list of eight elements is sorted using selection sort, the unsorted list is ____ after the second iteration.

d. list[2] ... list[7]

In the bubble sort algorithm, the following code accomplishes swapping values in elements at positions index and index + 1.

d. temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp;

The postfix expression 14 2 5 + = will generate an error, because ____.

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

What is the output of the following code? stackType<int> stack; int x, y; x = 5; y = 3; stack.push(4); stack.push(x); stack.push(x + 1); y = stack.top(); stack.pop(); stack.push(x + y); x = stack.top(); stack.pop(); cout << "x = " << x << endl; cout << "y = " << y << endl;

d. x = 11 y = 6

The steps involved in inserting a new item at the beginning of an unordered linked list are ____.

d. 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.

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

d. Make a copy of the linked list.

In a linked list, the ____________________ operator returns the info of the current node.

dereferencing

A function is called ____ recursive if it calls itself.

directly

The quick sort algorithm uses the ____________________ technique to sort a list.

divide and conquer

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

doubly

The ____________________ Fibonacci number in a sequence is the sum of the second and third Fibonacci numbers.

fourth 4th

In the linked implementation of stacks, the stack is ____________________ only if you run out of memory space.

full


Kaugnay na mga set ng pag-aaral

BYS 120-UAH Quiz Answers for Final Exam Prep

View Set

prep u chap 40: Management of Patients with Gastric and Duodenal Disorders

View Set

Rosetta Stone French: Level 1; Unit 1; Core Lesson 4

View Set