Midterm 2

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

(T or F) C++ has a sort function built in, so that you do not have to write your own every time you want to sort a list. True False

True

Which of the following stack configurations are correct in terms of precedence? Let the far left be the bottom of the stack, and the right be the top. A. + % B. * - C. + + D. / *

A. + %

If a particular binary tree is full and has 100 leaf nodes, how many internal nodes does it have? A. 99 B. 100 C. 101 D. Not determinable.

A. 99

What things are necessary in a recursive function? A. A base case and a recursive call. B. Adding the word "recursive" before the function name. C. Returning either true or false. D. All of the above.

A. A base case and a recursive call.

Which of the following would not be a good application for a binary tree? A. A family tree. B. A Huffman tree. C. A search tree. D. An expression tree.

A. A family tree.

What happens when a recursive function calls itself? A. A new instance of the function is called. B. The function starts over. C. The old variables get saved and then the function starts over. D. None of the above.

A. A new instance of the function is called.

What is recursion? A. A problem solving approach that causes functions to call themselves with different arguments. B. A trivial solution to a small problem. C. A way to remove the first element of a list. D. Returning the result of another function.

A. A problem solving approach that causes functions to call themselves with different arguments.

Which representation of a queue has the most favorable Big Ohs for the operations (as discussed in class)? A. Circular array B. Double-linked C. Single-linked, links pointing toward the front D. Single-linked, links pointing toward the rear

A. Circular array

With the recursive linear search algorithm given in the book, how many items in the list need to be checked if the item is not in the list? A. Every item in the list. B. Half of the items in the list. C. log(n), where n is the number of items in the list. D. None, you don't have to search if the item is not in the list.

A. Every item in the list.

Which of the following most accurately describes the behavior of a queue? A. First in, first out (FIFO). B. First in, last out (FILO) C. Last in, first out (LIFO) D. None of the above.

A. First in, first out (FIFO).

Let H(value) be a function that returns the hash code of "value". If A == B, then ________. A. H(A) == H(B) B. H(A) != H(B) C. H(A) may be equal to H(B), but it is not likey because it is random D. There is no known relation between H(A) and H(B).

A. H(A) == H(B)

Suppose you have a binary search tree. Which kind of traversal would print the contents in increasing order? A. Inorder. B. Preorder. C. Postorder. D. It doesn't matter, all would work.

A. Inorder.

What is the expected run time for inserting into a hash table? A. O(1) B. O(log n) C. O(n) D. O(n*log n)

A. O(1)

Recursion typically is justified when it reduces ______________. A. design and coding time B. execution time C. memory usage D. program errors

A. design and coding time

If the size of a heap is n, the performance A. is O(log n) for insertion. B. is O(1) for deletion. C. is O(n) for deletion. D. is O(n2) for restructuring.

A. is O(log n) for insertion.

A queue differs from a stack in __________. A. only one operation B. about half the operations C. virtually all the operations D. none of the operations; the names are essentially synonyms

A. only one operation

"Big O" for find, insert, and erase when hashing should be ___, ____, and ____, respectively. A. log n, log n, log n B. 1, 1, 1 C. log n, 1, 1 D. 1, log n, log n

B. 1, 1, 1

A Huffman tree for an alphabet of 15 distinct characters has _____ leaf nodes. A. less than 15 B. 15 C. 16 D. more than 16

B. 15

Suppose set A contains the strings "apples", "oranges", and "pineapples". Then the strings "apples" and "grapes" are inserted. How many items are in A after these two insertions? A. 3 B. 4 C. 5 D. No way to be sure

B. 4

If the number 3 is inserted into the following binary tree, what would be the pre-order traversal order? 5 / \ 1 10 / \ / 0 4 7 \ 9 A. 0 1 3 4 5 7 9 10 B. 5 1 0 4 3 10 7 9 C. 5 1 10 0 4 7 3 9 D. None of the above.

B. 5 1 0 4 3 10 7 9

What is the matching postfix expression to the following infix expression: 7 + ( 2 * 3 ) / 9? A. 7 2 3 * + 9 / B. 7 2 3 * 9 / + C. 2 3 * 9 / 7 + D. There is none, it is an invalid expression

B. 7 2 3 * 9 / +

A Priority Queue is an extension of queue with following properties: A. A typical priority queue supports an insert(item) function. B. An element with high priority is dequeued before an element with low priority. C. Every item has a unique priority associated with it. D. If two elements have the same priority, both are returned when dequeued.

B. An element with high priority is dequeued before an element with low priority.

Suppose the following operations are performed on an empty queue: Push A, push B, push C, push E, pop, and push D. What would be the next value to be accessed from this queue? A. A B. B C. C D. D E. E

B. B

Which of the following functions is the <b>least</b> efficient when implemented recursively? A. Calculating n factorial (n!). B. Calculating the nth Fibonacci number. C. Finding the greatest common divisor of two numbers. D. Raising x to the power of n.

B. Calculating the nth Fibonacci number.

Which of the following most accurately describes the bubble sort algorithm? A. Finding the largest chunk of the sorted list, and then sorting afterward. B. Gradually shifting larger items to the back of the array, or smaller items to the front. C. Picking the smallest item and moving it to the front of the list until the list is sorted. D. Placing each item into the correct position in the list one at a time, like a hand of cards.

B. Gradually shifting larger items to the back of the array, or smaller items to the front.

What is the difference between sort and stable_sort? A. Stable_sort is less likely to crash your program. B. Stable_sort will preserve ordering of duplicate items. C. Stable_sort is slightly faster. D. They are identical.

B. Stable_sort will preserve ordering of duplicate items.

Unlink a vector, a set does not support the subscript operator (e.g. mySet[0]). If someone still wanted to iterate through each item in a set, they should __________. A. Use a vector instead, it cannot be done B. Use an iterator C. Use the at() function D. Use the toString() function and read the resulting string

B. Use an iterator

A Priority Queue A. is a container. B. is a container adapter that uses a specific underlying container, e.g. vector or deque. C. is implemented with a stack. D. sometimes uses a LIFO to implement a waiting line.

B. is a container adapter that uses a specific underlying container, e.g. vector or deque.

Searching for an item in a linked list is O(___). Searching in a binary search tree is O(___). A. n, n B. n, log(n) C. log(n), log(n) D. n2, n

B. n, log(n)

What is the result of the postfix expression: 4 7 * 20 - ? A. -136 B. -52 C. 8 D. There is none, it is an invalid expression

C. 8

Which of the following can help to reduce collisions in a hash table? A. Expanding the table size. B. Using quadratic probing instead of linear probing. C. A and B. D. None of the above

C. A and B.

Pick the best statement A. A complete binary tree is a full binary tree. B. A complete binary tree is a full binary tree and a full binary tree is a complete binary tree. C. A full binary tree need not be complete and a complete binary tree need not be full. D. A full binary tree is a complete binary tree.

C. A full binary tree need not be complete and a complete binary tree need not be full.

Suppose you want to make a priority queue where smaller numbers have the highest priority. Which of the following would be the best underlying data structure? A. A binary search tree B. A circular array C. A min-heap D. A max-heap

C. A min-heap

When using a map to implement a phone directory, the ______ should be the key and the ______ should be the value. A. Hash code, name B. Hash code, phone number C. Name, phone number D. Phone number, name

C. Name, phone number

The Big O of the number of exchanges of selection sort is ___. The Big O of the comparisons is ___. A. O(n), O(n) B. O(n2), O(n2) C. O(n), O(n2) D. O(n), O(1)

C. O(n), O(n2)

What is the downside of recursion? A. A negative argument is not allowed in any recursive function. B. If the base case is not reached, an invalid_argument exception is thrown and must be caught. C. The function may result in a run-time error when there is no more memory available. D. The is no downside to recursion.

C. The function may result in a run-time error when there is no more memory available.

A map consists of a set of keys, each with one or more values. Which typically is/are unique? A. Both B. Neither C. The keys D. The values

C. The keys

Should a new Huffman tree be built for each file you create? Why or why not? A. No, because one Huffman tree should be enough for any file made in the same language. B. No, because that requires too much code. C. Yes, because different files may contain symbols with different frequencies. D. Yes, because Huffman trees can only be used once, even for the same file.

C. Yes, because different files may contain symbols with different frequencies.

With the recursive binary search algorithm given in the book, how many items in the list need to be checked if the item is not in the list? A. Every item in the list. B. Half of the items in the list. C. log(n), where n is the number of items in the list. D. None, you don't have to search if the item is not in the list.

C. log(n), where n is the number of items in the list.

When collisions are resolved using linear probing, ______. A. infinite loops regularly result B. probing terminates not later than the end of the hash table C. the insertion occurs at the first available slot that was not previously occupied D. the insertion occurs at the first available slot, even it was previously occupied

C. the insertion occurs at the first available slot that was not previously occupied

The reallocate function for class Queue A. has an unacceptable "Big O". B. typically copies elements to identical index positions. C. typically does not copy elements to identical index positions. D. works only if class Queue extends class Vector.

C. typically does not copy elements to identical index positions.

There are two general ways to implement ADT Stack. These are __________________, A. using an array or a vector B. using a single-linked list or a double-linked list C. using a contiguous structure or a linked structure D. none of the above; always use the standard library implementation

C. using a contiguous structure or a linked structure

__________ traversal doesn\'t exist. A. Preorder B. Postorder C. Inorder D. Outorder

D. Outorder

Which of the following most accurately describes the selection sort algorithm? A. Finding the largest chunk of the sorted list, and then sorting afterward. B. Gradually shifting larger items to the back of the array, and smaller items to the front. C. Placing each item into the correct position in the list one at a time, like a hand of cards. D. Picking the smallest item and moving it to the front of the list until the list is sorted.

D. Picking the smallest item and moving it to the front of the list until the list is sorted.

When a recursive function returns after three iterations because it hits a base case, where does it return to? A. The beginning of the previous iteration that called it. B. The first iteration. C. The function that called the first iteration. D. The previous iteration, right after it called the next iteration.

D. The previous iteration, right after it called the next iteration.

When comparing recursion and iteation, all of the following are true EXCEPT A. A recursive algorithm may be simpler than an iterative algorithm and thus easier to write, code, debug, and read. B. In iteration, a loop repetition condition determines whether to repeat the loop body or exit from the loop C. In recursion, the condition usually tests for a base case. D. There is always an recursive solution to a problem that is solvable by iteration.

D. There is always an recursive solution to a problem that is solvable by iteration.

Suppose you want to traverse a hash table of names in alphabetical order. How would you do that? A. Use an iterator. B. Use the remove operator. C. Use the subscript operator or the at() function. D. This cannot be done.

D. This cannot be done.

Compared with a linked list, a binary tree ________. A. is better at representing a sequence of numbers B. is less effective at representing genealogy C. is virtually the same D. has nodes with two child nodes instead of one next node

D. has nodes with two child nodes instead of one next node

What kind of mapping is used in a map from keys to values? A. one-to-many B. one-to-one C. many-to-many D. many-to-one

D. many-to-one

To convert from infix (without parentheses) to postfix, use a stack of A. parentheses B. operators and operands C. operands D. operators

D. operators

When a queue is represented using a single-linked list, the links should A. be double links since you can\'t do it with single links. B. point either from rear to front, or front to rear; it doesn\'t matter. C. point from the rear toward the front. D. point from the front toward the rear.

D. point from the front toward the rear.

A heap A. is a full and complete binary tree. B. is a full binary tree. C. only requires the root value to be greater than or equal to all items in the tree. D. requires every subtree to be a heap.

D. requires every subtree to be a heap.

In tail recursion, ____________. A. progress toward a base case is linear (i.e. each level or recursion entails only a single call) B. progress toward a base case is monotonic C. progress toward a base case is strictly monotonic D. the recursive call is the last executable statement in the function

D. the recursive call is the last executable statement in the function

Which of the following is a true about Binary Trees? 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. E. None of the above.

E. None of the above.

True or false: a heap can only be represented with a linked data structure. True False

False


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

Neuromuscular Physiology Chapter 5 Review

View Set

2-3 Linux+ File and Directory Permissions

View Set

Chapter 1:Overview of Strategic Marketing-Principles of Marketing-BCOR 2201

View Set

medical law and ethics study guide chapters 1-2

View Set