C S 235: Data Structures; Final Exam

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

"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

Set A has 10 members and set B has 14 members. The intersection of the two sets has 5 members. How many members are in the union of the two sets? a. 10 b. 19 c. 14 d. 24

b. 19

In this sequence, 11 4 20 45 32 60 98 70, which element seems to be the pivot? a. 4 b. 20 c. 70 d. 98

b. 20 (because all to the right are greater and all to the left are lesser)

Suppose set A contains the strings "apples", "oranges", and "pineapples". Then 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

Which of the following functions is the least 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 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.

What is TRUE of the friend functions? a. A friend function is a non-member function with access to the class private and protected members. b. Friend function in a class definition are member functions of that class. c. Friendship is inherited. d. If A is friend of B, then B automatically becomes a friend of A.

a. A friend function is a non-member function with access to the class private and protected members.

Which of the following is an example of an 'is-a' relationship? a. A jet plane is a plane b. A plane is a jet plane. c. A train engine is a train. d. A train is a train engine.

a. A jet plane is a plane

What is true of shell and/or merge sorts? a. A merge sort is a stable sort. b. A merge sort is faster than a shell sort (on average). c. A shell sort is a stable sort. d. Merge and shell sorts sort in place.

a. A merge sort is a stable sort.

How can you verify that a list is sorted? a. Check each element in the list and make sure that it is not less than its predecessor. b. Check several random indicies and ensure that they are in order. c. Verify that each position in the list has its index as its value (e.g. spot 0 in the array is 0). d. Any of the above.

a. Check each element in the list and make sure that it is not less than its predecessor.

Pick the best statement: a. Both the preconditions and postconditions must be met. b. If the preconditions are met, the postconditions must be achieved. c. If the preconditions are not met, the postconditions will not be achieved. d. The preconditions and postconditions are independent of each other.

b. If the preconditions are met, the postconditions must be achieved.

Which of the following describes testing the interactions among smaller units? a. Acceptance testing. b. Integration testing. c. System testing. d. Unit testing.

b. Integration testing.

In what order should catch clauses appear? a. It makes no difference. b. Most specific to most general. c. Most general to most specific. d. All of the above.

b. Most specific to most general.

What is the worst case performance of the bubble sort? a. O(n) b. O(n^2) c. O(n^3) d. O(n) exchanges, O(n^2) comparisons

b. O(n^2)

What happens if an exception is thrown in a program and not caught? a. The compiler crashes. b. The program aborts. c. The program begins executing again from the point the exception was thrown. d. The program will not compile.

b. The program aborts.

In a binary search tree, all of the following are synonyms except _____________. a. a node's inorder predecessor b. a node's parent c. the largest value in the node's left subtree. d. the value found by going left from the node, and then going right as far as possible

b. a node's parent

The performance of a self-balancing binary search tree a. is expected to be O(log n), even if not full. b. is of order of log(number of elements in the tree). c. is possibly up to O(n). d. requires the heights of the right and left subtrees to be equal.

b. is of order of log(number of elements in the tree).

The contiguous implementation of ADT deque is ______________. a. impractical b. more like the contiguous implementation of ADT queue c. more like the contiguous implementation of ADT stack d. unlike the contiguous implementation of either ADT stack or ADT queue

b. more like the contiguous implementation of ADT queue

The scope of a variable refers to: a. logical groups that prevent name collision from multiple file includes. b. the region or section of code where a variable can be accessed. c. the time duration when a variable is in a valid state. d. which translation unit is being referenced.

b. the region or section of code where a variable can be accessed.

What are the correct intermediate steps of the following data set when it is being sorted with Quicksort? 15,20,10,18 a. 10,20,15,18 -- 10,15,20,18 -- 10,15,18,20 b. 10,20,15,18 -- 10,18,15,20 -- 10,15,18,20 c. 15,10,20,18 -- 10,15,20,18 -- 10,15,18,20 d. 15,20,10,18 -- 15,10,20,18 -- 10,15,20,18

c. 15,10,20,18 -- 10,15,20,18 -- 10,15,18,20

A left-right AVL imbalance calls for _________ rotation(s); a right-right imbalance calls for _____________ rotation(s) to correct the immediate imbalance. a. 1 or 2, 1 or 2 b. 2 or more, 1 or more c. 2, 1 d. 1, 2

c. 2, 1

How many base cases are in the maze solving algorithm? a. 1 b. 2 c. 3 d. 4

c. 3

What is the maximum height of an AVL-tree with 7 nodes? (Assume the height of a tree with a single node is 1.) a. 2 b. 3 c. 4 d. 5

c. 4

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 the collisions in 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.

Which of the following most accurately describes the behavior of a stack? a. First in, first out. b. Last in, last out. c. Last in, first out. d. None of the above.

c. Last in, first out.

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(n^2), O(n^2) c. O(n), O(n^2) d. O(n), O(1)

c. O(n), O(n^2)

Quicksort uses a. Insertion b. Merging c. Partitioning d. Selection

c. Partitioning

"Divide-and-conquer" refers to: a. The list being divided into sublists with equal numbers of elements in each, then those sorted sublists are merged back together. b. The list being divided into only two sublists, never more or less, which are sorted and merged back together. c. The list being divided into smaller sublists, then those sorted sublists are merged back together.

c. The list being divided into smaller sublists, then those sorted sublists are merged back together.

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.

The pre-processor conditional compilation directives a. act the same as the /*...*/. b. are evaluated at run-time. c. are used to eliminate lines at compilation time. d. cannot be nested.

c. are used to eliminate lines at compilation time.

In a class that contains a pointer to a dynamically allocated int, the destructor ________ delete the pointer because _________. a. should not, primitive data types are handled automatically. b. should not, ints do not cause memory leaks, only classes. c. should, the memory pointed to by the pointer must be freed to prevent memory leaks. d. should, every data member of a class should be deleted in the destructor.

c. should, the memory pointed to by the pointer must be freed to prevent memory leaks.

Which of the following most accurately describes the shell sort algorithm? a. Shell sort is divide-and-conquer approach to bubble sort. b. Shell sort sorts one smaller subarray using insertions sort before sorting the entire array. c. After each subarray sort, a new subarray with approximately the same number of elements is sorted. d. The last step is to perform an insertion sort on the entire array, which has been presorted by the earlier sorts.

d. The last step is to perform an insertion sort on the entire array, which has been presorted by the earlier sorts.

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

What is a C++ concept? a. A C++ concept serves as a constraint by limiting the set of arguments that are accepted as template parameters. b. Concepts are an instantiation of a C++ template. c. Concepts can be used to introduce types to template programming. d. Violations of constraints are detected at run time.

a. A C++ concept serves as a constraint by limiting the set of arguments that are accepted as template parameters.

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 kind of pointer should be included in a singly linked node? a. A pointer to the next node. b. A pointer to the previous node. c. A pointer to the beginning of the list. d. A pointer to the end of the list.

a. A pointer to the next node.

How are iterators implemented? a. All STL iterators support pre- and post- increment operators. b. Dereferenced iterators return const items. c. Iterators are always implemented as nested structs. d. Post-increment operators return a new reference to the iterator.

a. All STL iterators support pre- and post- increment operators.

What is true of translation units? a. All source files, together with their included header files, are called the translation unit. b. Translation units are compiled into object files that are joined together by the the linker. c. Local objects in a source file are accessible across translation units. d. A single translation unit can't be compiled into a library.

a. All source files, together with their included header files, are called the translation unit.

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

What is C++ object delegation? a. Delegation allow exposure to some functionality of a pre-existing class, but still control access through your own interface. b. Delegation and inheritance are the same concept. c. Delegation is when an object of one is a data member in another class. d. Delegation refers to one object being independent of another object but providing same functionalities.

a. Delegation allow exposure to some functionality of a pre-existing class, but still control access through your own interface.

What is NOT TRUE about switch statements? a. Every case needs to contain a break. b. It is not required that each case be enclosed in braces. c. The expression used in a switch statement must have an integral enumerated type. d. When a break statement is reached, control jumps to the next line following the switch statement.

a. Every case needs to contain a break.

Suppose you want to access the next element of a stack. Which function would you call? a. top() b. pop() c. push() d. next()

a. top()

A Huffman tree for an alphabet of 15 distinct characters has ________ leaf nodes. a. 15 b. less than 15 c. 16 d. more than 16

a. 15

What is the maximum black-height of a Red-Black Tree with 7 nodes? a. 2 b. 3 c. 4 d. 7

a. 2

Pick the correct statement. a. A binary tree is a tree. b. A tree is not a binary tree and a binary tree is not a tree. c. A tree is a binary tree. d. "Tree" and "binary tree" are synonymous.

a. A binary tree is a tree.

Which of the following would not 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 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.

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.

What is the expected run time for inserting into a hash table? a. O(1) b. O(n) c. O(log n) d. O(n*log n)

a. O(1)

What is the best case performance of the quicksort algorithm? a. O(n) b. O(n^2) c. O(n log n) d. O(log n)

a. O(n)

What is true of C++ streams? a. The class istream defines the extraction operator (>>) for primitive data types. b. A stream is an entity where a program can only extract characters. c. The stream class istream inherits from the class ifstream. d. File streams associate streams with C++ data types.

a. The class istream defines the extraction operator (>>) for primitive data types.

What is NOT true of a const_iterator and the iterator? a. The compiler ensures that any attempt to do so results in an error. b. The const in the operator heading means that the reference item can be changed. c. The dereferencing operator returns a const reference. d. The member access operator returns a const pointer.

a. The compiler ensures that any attempt to do so results in an error.

What typically happens as a consequence of the ++iter component of: for (list<Item_Type>::iterator iter = a_list.begin(); iter != a_list.end(); ++iter) { // Sequence of statements } a. The iterator pointer advances to the next element of the list. b. The value of the data element referenced by the iter is incremented by 1. c. The value of the data element referenced by iter is incremented by one and the iter advances to the next element of the list. d. The iterator pointer advances to the next element of the list and the value of the data element now referenced by the iter is increases by one.

a. The iterator pointer advances to the next element of the list.

(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. a. True b. False

a. True

To restore the AVL property after inserting an element, we start at the insertion point and move towards root of that tree. a. True b. False

a. True

Is it possible to have all black nodes in a Red-Black tree? a. Yes, with a complete tree of all black nodes. b. No, the root is always red. c. Yes, a red node always has a black children. d. No, the number of black nodes is even.

a. Yes, with a complete tree of all black nodes.

Both the client and programmer can do _________ testing. Typically only the ________ does ______ testing. a. black box; programmer; white box. b. closed-box; client; glass box. c. functional; client; open box. d. white box; programmer; functional.

a. black box; programmer; white box.

When the array representation of ADT queue becomes full, ___________. a. call a reallocate specialized for the array-based queue b. call the reallocate function for vector c. terminate enqueuing d. wrap around to the beginning of the array

a. call a reallocate specialized for the array-based queue

A binary tree's conceptual counterpart of a double-linked list ____________. a. consists of links to children and parents: three links per node b. consists of links to left and right subtrees: two links per node c. consists of links to parents: one link per node d. does not exist

a. consists of links to children and parents: three links per node

Recursion typically is justified when it reduces ____________. a. design and coding time. b. execution time. c. memory usage. d. program error.

a. design and coding time.

Infix-to-postfix uses a stack of ________, postfix evaluation a stack of ________, and postfix-to-infix a stack of ________. a. operators, operands, operators b. operators, operands, operands. c. strings, strings, strings d. operators, operands, string

a. operators, operands, operators

What makes backtracking different from random trial and error? a. Backtracking is always faster than random trial and error. b. Backtracking is a systematic approach that will not try the same path more than once. c. Random trial and error cannot be made in a program. d. There is no real difference.

b. Backtracking is a systematic approach that will not try the same path more than once.

Quicksort is a stable sort. a. True b. False

b. False

True or false: The maze solving algorithm will not function properly if there is more than one possible path through the maze. a. True b. False

b. False

For which type of error are try and catch most appropriate? a. Logic errors. b. Run-time errors. c. Syntax error. d. All of the above.

b. Run-time errors.

Which of the following most accurately describes the merge sort algorithm? a. Placing every item into a heap and moving the top item into the sorted list. b. Splitting the array evenly in half, and sorting the halves recursively. c. Splitting the array in halves based on size, and sorting the halves recursively. d. Sorting the first element, and then adding items from the rest of the list recursively.

b. Splitting the array evenly in half, and sorting the halves recursively.

What is the difference between variable scope and lifetime? a. The lifetime of a variable is the region of the code where variable can be accessed. b. The lifetime of an object is the time duration where an object is in a valid state. c. A static local variable has limited scope but an unlimited lifetime. d. Two variables with the same name always exhibit undefined behavior.

b. The lifetime of an object is the time duration where an object is in a valid state.

Unlike 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

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. n^2, n

b. n, log(n)

While insertion sort is generally O(n^2), it is ______. a. always O(n^2) b. sometimes O(n) c. sometimes O(n*log n) d. sometimes O(n^2*log n)

b. sometimes O(n)

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.

What features are considered fundamental by the C++ standard on containers? a. Containers grow as needed. b. Containers hold objects. c. Both of the above. d. None of the above.

c. Both of the above.

What are the characteristics of a good pivot in a quicksort algorithm? a. It does not matter, all pivots are equally effective. b. It is close to the mean value of the list. c. It is close to the median value of the list. d. It is either very large or very small compared to the rest of the list.

c. It is close to the median value of the list.

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

What would be the Big O of a reserve function which creates a new array that is twice the size of the current array for an object of class Vector, and copies the contents from the old array into the new array? a. order 1 b. order n c. amortized order 1 d. amortized order n

c. amortized order 1

With an iterator named iter, how would the data in the iterator be accessed? a. iter* b. iter& c. &iter d. *iter.

d. *iter.

Pick the best relationship for queues and deques. a. A queue is-a deque. b. a deque is-a queue. c. A deque has-a queue. d. A queue has-a deque.

d. A queue has-a deque.

Which of the following is an example of an 'has-a' relationship? a. A jet plane is a plane b. A plane is a jet plane. c. A train engine is a train. d. A train has a train engine.

d. A train has a train engine.

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

d. D

What is the primary advantage of heap sort over merge sort? a. Heap sort is easier to visualize b. Heap sort is significantly faster than heap sort. c. Heap sort is stable, while merge sort is unstable. d. Heap sort requires less space than merge sort.

d. Heap sort requires less space than merge sort.

The inorder traversal sequence of a binary tree is A B C. the root is _______. a. A b. B c. C d. Not a unique binary tree.

d. Not a unique binary tree.

Which of the following most accurately describes the selection sort algorithm? a. Finding the largest chunk of 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 card. 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.

Which of the following most accurately describes the insertion 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.

d. Placing each item into the correct position in the list one at a time, like a hand of cards.

Which of the following most accurately describes the quicksort algorithm? a. Placing every item into a heap and moving the top item into the sorted list. b. Sorting the first element, and then adding items from the rest of the list recursively. c. Splitting the array in thirds, and sorting the sub-arrays recursively. d. Splitting the array in halves based on size, and sorting the halves recursively.

d. Splitting the array in halves based on size, and sorting the halves recursively.

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 iteration, all of the following are true EXCEPT a. A recursive algorithm may be simpler than in 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 a recursive solution to a problem that is solvable by iteration.

d. There is always a 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.

Which of the following is true about the selection sort? a. Each element is examined only once. b. It is one of the most complex sorting algorithms. c. The code executes in O(n) time if the elements are sorted already. d. With each pass, an element jumps to its final location.

d. With each pass, an element jumps to its final location.

An abstract data type (ADT) has all of the following EXCEPT: a. a name. b. a set of data elements. c. a set of operations. d. an implementation.

d. an implementation

What is the proper relationship between a class List and class Ordered_List? a. class List has-a Ordered_List. b. class List is-a Ordered_List. c. class Ordered_List is-a List. d. class Ordered_List has-a List.

d. class Ordered_List has-a List.

A Huffman tree, like the one depicted on page 450 of the course text, is a _____________. a. binary search tree. b. complete and full binary tree. c. complete binary tree. d. full binary tree.

d. full binary tree.

If you wanted to use a data structure to store a club roster, which of the following should you use? a. either a map or a set, either is equally fine. b. map. c. neither a map nor a set will perform well here. d. set.

d. set.

Which of the following CANNOT be overloaded? a. the << operator. b. the <= operator. c. the == operator. d. the dot operator.

d. the dot operator.

For the contiguous representation of ADT deque, when an end of the deque is reached, ______________________. a. allocate a larger array b. shift elements to the left c. shift elements to the right d. wrap around to the other end

d. wrap around to the other end

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.

Which of the following is in correct descending precedence order? a. () ~ == || b. [] << + % c. * (unary) * & + d. & && ^ |

a. () ~ == ||

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. + %

In 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 is true of C++ strings? a. A C++ string is an alias for a basic_string<char> b. Character arrays and strings are identical. c. Memory for a C++ string must be pre-allocated. d. C++ strings lose type and dimension when passed to a function.

a. A C++ string is an alias for a basic_string<char>

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 / +

If one class has two functions with the same name, but that take different arguments, this is an example of: a. Overriding. b. Overloading. c. An error. d. Polymorphism.

b. Overloading

What is true about the main function? a. Command line parameters are passed thru three arguments to the main() function. b. The 1st parameter of main() is the number of arguments and the 2nd is an array of char* pointers to those arguments. c. The main() function parameters are always called argc and argv. d. The main() function parameters are required even when they are not used.

b. The 1st parameter of main() is the number of arguments and the 2nd is an array of char* pointers to those arguments.

/* /* This is an invalid command. Why? */ */ a. Comments should start with the # character. b. You cannot nest comments. c. Single line comments can only be done with // d. The outer comment would be empty, and empty comments are not allowed.

b. You cannot nest comments.

The most obvious from of an iterator is: a. & operator. b. a pointer. c. destructor d. an at operator.

b. a pointer.

Why are iterators useful? a. All containers have the same iterator capabilities and hence the choice of the container doesn't matter. b. Iterators are faster than pointers. c. Iterators isolate the user from the internal structure of a container. d. You cannot sort a container without an iterator.

c. Iterators isolate the user from the internal structure of a container.

_____________ traversal doesn't exist. a. Preorder b. Postorder c. Inorder d. Outorder

d. Outorder

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 is not likely 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 content in increasing order? a. Inorder. b. Preorder. c. Postorder. d. It doesn't matter, all would work.

a. Inorder.

What is the fundamental flaw with the Waterfall software development model? a. It assumes that each stage can be completed correctly and fully before advancing to the next stage. b. It ignores the "salmon" among us. c. It is not compatible with object-oriented programming. d. It requires some stages which skilled programmers can safely omit.

a. It assumes that each stage can be completed correctly and fully before advancing to the next stage.

_______ errors probably exist in a significant portion of commercial software. a. Logic b. Run-time c. Syntax d. Waterfall

a. Logic

Which of the following is NOT a disadvantage of a singly linked list compared to a doubly linked list? a. Nodes in a singly linked list contain more data than nodes in a doubly linked list. b. A singly linked list can only insert a node after a node we have a pointer to. c. A singly linked list can only be traversed in the forward direction. d. A singly linked list can remove a node only if it was a previous node.

a. Nodes in a singly linked list contain more data than nodes in a doubly linked list.

Which of the following most accurately describes the heap sort algorithm? a. Placing every item into a heap and moving the top item into the sorted list. b. Sorting the first element, and then adding items from the rest of the list recursively. c. Splitting the array evenly in half, and sorting the halves recursively. d. Splitting the array in halves based on size, and sorting the halves recursively.

a. Placing every item into a heap and moving the top item into the sorted list.

A Red-Black tree may not be as balanced as an AVL tree for the same series inputs. a. True. b. False.

a. True.

If you need to provide a stack, a queue, a deque, an input-restricted deque, and an output restricted queue, ____________________. a. each of the others should "have" a deque as a data member b. each of the others should "be" a deque c. each of the others should extend class stack d. each of the others should extend class queue

a. each of the others should "have" a deque as a data member

A private data member is visible: a. in the class in which it is declared. b. nowhere. c. (a) and in all derived classes d. (a) and in any class that 'has-a' object of the class in which it is declared.

a. in the class in which it is declared.

With a heap, a. insertion traces a path from a leaf to the root. b. removal traces a path from the leaf to the root. c. the largest complete tree of height h has 2^h nodes. d. the smallest full tree of height h has 2^(h-1) nodes.

a. insertion traces a path from a leaf to the root.

The sequential representation of ADT deque _______________. a. is not practical (too many O(n) operations) b. requires (single) links between adjacent nodes c. requires (double) links between adjacent nodes d. uses the technique like those discussed for representing ADT queue

a. is not practical (too many O(n) operations)

Software practitioners sometimes object to the term "bugs" because: a. it tends to trivialize potentially serious consequences of program defects. b. there are three general categories of defects or errors, not just one. c. they consider it inappropriate to assign life-like characteristics to any aspect of computing. d. we no longer use vacuum-tube computers where insects could intrude.

a. it tends to trivialize potentially serious consequences of program defects.

To check for balanced parentheses, use a stack of: a. parentheses. b. operators and operands. c. operands. d. operators.

a. parentheses.

Balance, in the context of AVL trees, refers to _______________________. a. the difference between the heights of the right and left nodes. b. the difference between the heights of the right node and the root node. c. the difference between the number of nodes from the root to the right and left nodes. d. the difference between the number of nodes to the right and the left of the node

a. the difference between the heights of the right and left nodes.

All of the following are true of iterators EXCEPT: a. the iterator end() function returns a pointer to the last element on the container. b. iterators allow you to traverse container members using pointer-like semantics. c. iterators provide abstraction away from the "how" to traverse a container. d. iterators are in essence improved versions of pointers from C. e. iterators in STL allow algorithms to be written independent of the manner in which the data is stored.

a. the iterator end() function returns a pointer to the last element on the container.

Writing "towers of Hanoi" code for 64 disks is a. virtually the same as for 3 disks. b. exponentially more difficult than for 3 disks. c. completely unrelated to code for 3 disks. d. impossible, even on the world's fastest computer.

a. virtually the same as for 3 disks.

The default copy constructor may be used EXCEPT: a. when a deep copy is required. b. when an object is constructed based on another object of the same class. c. when an object of the class is passed (to a function) by the value as an argument. d. when an object of the class is returned by the value. e. when the compiler generates a temporary object.

a. when a deep copy is required.

If the number 5 is deleted from the following binary tree, what would be the level order traversal order? 5 / \ 1 10 / \ / 0 4 7 \ 9 a. 1 0 4 10 7 9 b. 4 1 10 0 7 9 c. 7 1 9 0 4 10 d. 9 1 10 0 4 9

b. 4 1 10 0 7 9

A Priority Queue is an extension of queue with the 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.

What is true of an iterator? a. All iterators have the same functionality as pointers. b. An iterator is an object pointer to an item that is part of a larger container of items. c. Iterators are only used for accessing container items. d. Most iterators only support pre-decrement operators.

b. An iterator is an object pointer to an item that is part of a larger container of items.

What is true of C++ pointer variables? a. A pointer variable contains the variable value. b. Array pointers enable us to conveniently process groups of data such as vectors, lists, and strings. c. Pointers prevent functions from modifying the arguments passed by the called function. d. The ampersand (&) indicates that the following identifier is a pointer variable.

b. Array pointers enable us to conveniently process groups of data such as vectors, lists, and strings.

The reallocate function for the 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.

What is the difference between const and the pre-processor directive #define? a. A symbolic debugger is able to resolve #define directives. b. As a general rule you should give the compiler preference to the preprocessor. c. The C++ compiler always sees the #define directive. d. The used of const always yields smaller code size.

b. As a general rule you should give the compiler preference to the preprocessor.

What is the best way to visit every node of a circular list exactly once? a. Add a boolean data member and set it after a node is visited. b. Begin at the head and ask if the next node in the list is the head. c. Count the nodes and use a for loop. d. Set the data member to a value (such as NULL or 0 or """) to mark it as visited.

b. Begin at the head and ask if the next node in the list is the head.

Shell sort can be interpreted as an improved version of which sorting algorithm? a. Bubble sort b. Insertion sort c. Selection sort d. Merge sort

b. Insertion sort

Which of the following is true about multiple inheritance? a. C++ does not support multiple inheritance. b. Multiple inheritance can often be avoided by refactoring. c. The constructors of inherited classes are called in reverse order in which they are inherited. d. With multiple inheritance, all the variables of the base class have different names.

b. Multiple inheritance can often be avoided by refactoring.

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.

What is "chaining?" a. Keeping track of the locations visited by particular item in a hash table when finding collisions. b. Storing a linked list in each table entry that contains each value that hashes to the same location. c. The process of checking for open spots in a hash table if there is a collision. d. The process of cleaning up a hash table that has had too many collisions.

b. Storing a linked list in each table entry that contains each value that hashes to the same location.

What is regression testing? a. Testing code against old versions to make sure that progress is being made. b. Testing to make sure a change did not have an unintended consequence. c. Testing your code to make sure that it did not degrade over time. d. Writing new tests for old versions of code.

b. Testing to make sure a change did not have an unintended consequence.

Which of the following is NOT an invariant of a Red-Black tree? a. A node is either red or black. b. The root is always red. c. A red node always has black children. d. The number of black nodes in any path from the root to the leaf is the same.

b. The root is always red.

The merge step of merge sort depends on which of the following characteristics? a. The original array was of an even length. b. The subarrays are sorted. c. The two subarrays are relatively small. d. The two subarrays are the same size.

b. The subarrays are sorted.

Which of the following is NOT a reason to override a function? a. You are writing a function to implement an ADT. b. You made a child class so you need to override every function. c. You want to change the functionality of a derived class. d. You want to add to functionality of the base class.

b. You made a child class so you need to override every function.

A template class typically: a. accommodates a variety of containers that have the same set of core operations. b. facilitates the same set of operations on a variety of data types. c. is a class (such as vector) that has a data member of another class (such as array). d. is an abstract class without a specific implementation.

b. facilitates the same set of operations on a variety of data types.

A private data member is visible: a. nowhere. b. in the class in which it is declared. c. (b) and in all derived classes. d. (c) and in any class that instantiates an object of the class in which it is declared.

b. in the class in which it is declared.

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.

Inserting at the head of a single-linked list is ________ inserting at the tail. a. equivalently efficient to b. more efficient than c. less efficient than d. impossible, bu if there is sufficient available space, it is reasonable to think in terms of doing so.

b. more efficient than

A vector is _________ efficient than an array __________. a. more, in terms of execution time and memory usage. b. more in terms of coding time, but not execution time or memory usage. c. less, in terms of coding time. d. less, for any reasonable definition of efficiency.

b. more in terms of coding time, but not execution time or memory usage.

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.

What types of maps would NOT be useful in a Huffman Code algorithm? a. A map of characters to ints, representing the frequencies of each character. b. A map of characters to strings, representing the encoding of each character. c. A map of strings to characters, representing the decodings of each string. d. All of the above are useful.

c. A map of strings to characters, representing the decodings of each string.

To convert from infix (without parentheses) to postfix, use a stack of: a. parentheses. b. operators and operands. c. operands. d. operators

d. operators

What is FALSE concerning pointers and references? a. A pointer variable can be assigned a value at any time, while a reference variable cannot be re-assigned. b. A pointer variable is a variable that holds a memory address. c. A reference variable has a different memory address than the item it references. d. A reference variable is an alias for an already existing variable.

c. A reference variable has a different memory address than the item it references.

Which of the following is TRUE concerning abstract classes and concrete classes? a. Concrete classes can define variables, but abstract classes cannot. b. Concrete classes can extend another class, but abstract classes cannot. c. Abstract classes can declare abstract member functions, but concrete classes cannot. d. Abstract classes can extend another class, but concrete classes cannot.

c. Abstract classes can declare abstract member functions, but concrete classes cannot.

Which of the following is NOT a reason to use a linked list over a vector? a. Removal from a linked list is more efficient. b. Inserting at the beginning of a linked list is more efficient. c. Accessing any given element in a linked list is more efficient. d. All of the above are reasons why the linked list is superior.

c. Accessing any given element in a linked list is more efficient.

Pick the best statement: a. An ADT is represented by a .cpp file. b. An ADT is represented by a .h file. c. An ADT is represented by a class consisting of abstract functions. d. An ADT is represented by the combination of a .h file and an associated .cpp file.

c. An ADT is represented by a class consisting of abstract functions.

Why is a Node typically defined as a struct in the private part of a host class? a. Because structs cannot be #included. b. Because C++ allows inner structs, but not inner classes. c. Because a struct's data members are public by default. d. To permit multiple containers to have Nodes as data members.

c. Because a struct's data members are public by default.

What best describes a C++ template? a. A template saves memory by reusing code. b. All possible class templates are defined at run-time. c. C++ uses a class template as a pattern to create a new class of a specified type. d. Templates can only be used to build classes.

c. C++ uses a class template as a pattern to create a new class of a specified type.

What is the principal advantage of having a template class? a. It serves as a skeleton from which other classes can be built. b. It serves as the root of a(n anticipated) hierarchy. c. Its ability to contain different types of data (determined at run time). d. Its ability to contain different types of data (determined at compile time)

c. Its ability to contain different types of data (determined at run time).

If N = size / 2 and M = size * size, what is the Big-O of the following: for(i = 0; i < N; i++) { // Sequence of statements } for (j = 0; j < M; j++) { // Sequence of statements } a. O(max(N, M)) b. O(N x M) c. O(n^2) d. O(n)

c. O(n^2)

What order is used in the C++ tool chain? a. Compiler, preprocessor, assembler, linker. b. Compiler, preprocessor, linker, assembler. c. Preprocessor, compiler, assembler, linker. d. Preprocessor, compiler, linker, assembler.

c. Preprocessor, compiler, assembler, linker.

What is NOT true of an array? a. An array name is the address of its first element. b. Statically declared arrays are allocated memory at compiler time. c. The C++ compiler is able to deduce an array size from the array pointer. d. You can use array notation (e.g., int[]) or a pointer notation (e.g., int*) in a function declaration.

c. The C++ Compiler is able to deduce an array size from the array pointer.

Why is the list class required to have a push_front function, but the vector is not? a. It is impossible to add something to the front of a vector. b. The list class was designed later, and the push_front function had not been thought of yet. c. The push_front function would be O(n), and the function must be at least amortized constant time to be required. d. The list class has a vector, and it adds more functionality.

c. The push_front function would be O(n), and the function must be at least amortized constant time to be required.

What do Red-Black trees, 2-3-4 trees, and AVL trees all have in common? a. They are all binary-search trees. b. They all have binary search trees. c. They are all self balancing trees. d. They are all largely unused -- binary search trees are superior

c. They are all self balancing trees.

Suppose we are writing a program with polymorphism, but only our base class functions are being called. What is likely the source of our bug? a. We are not using pointers. b. We forgot to make the derived classes inherit from the base class. c. We have forgotten to make our base class functions virtual. d. We forgot to #include the base class in the derived .h class.

c. We have forgotten to make our base class functions virtual.

The contiguous implementation of an ADT queue _______________. a. calls for a vector b. calls for a conventional array c. calls for a circular array d. is not practical

c. calls for a circular array

Inclusion of the keyword const in a function header does all of the following EXCEPT: a. alert the user that the function will not change values. b. disallow changes in values. c. force the return type to be a constant. d. incorporate optimizations.

c. force the return type to be a constant.

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.

The separation of what is to be done from how it is to be done is called: a. data abstraction. b. information hiding. c. procedural abstraction. d. top-down design.

c. procedural abstraction.

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 if it was previously occupied.

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

There are two general ways to implement ADT stacks. These are: a. using an array or 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.

What is the advantage of placing the word const in the function declaration and in the function definition? a. Any operation that could modify the object is flagged. b. it facilitates optimizations in the machine code. c. This tells the user that the function will not modify the associated object. d. All of the above are true.

d. All of the above are true.

Polymorphism expects: a. functions with common signatures at different levels in hierarchy. b. functions with common signatures at different levels, with at least the highest-level function declared virtual. c. pointers to objects (probably to objects higher in the hierarchy). d. All of the above.

d. All of the above.

Suppose we are trying to use multiple inheritance, but the compiler reports that there is an ambiguity about our variable named 'var'. What can we do to resolve this error? a. Refactor the parent classes by combining them. b. Rename the variable of one of the parent classes. c. Specify which parent you are taking the variable from with 'Parent::var". d. All of the above.

d. All of the above.

Which of the following is a FALSE statement? a. An abstract class can extend another abstract class. b. An abstract class cannot be instantiated. c. Pointers to an abstract class may be declared. d. An abstract class contains only abstract functions.

d. An abstract class contains only abstract functions.

Which of the following most closely describes the functionality of a debugger? a. It sweeps your code and fixes bugs it encounters. b. It allows you to run your code directly from the IDE. c. It underlines in red all the parts of the program that are syntactically incorrect. d. It allows you to monitor the variables at individual steps during the execution of the program.

d. It allows you to monitor the variables at individual steps during the execution of the program.

What is the matching infix expression to the following postfix expression: 8 9 + 4 * - ? a. - ((8 + 9) * 4) b. ((8 + 9) * 4) c. - (8 + 9 * 4) d. There is none, it is an invalid expression.

d. There is none, it is an invalid expression.

Traversal algorithms are fairly simple. What attribute of trees makes that so? a. Trees are linear data structures. b. Trees are normally smaller than other data structures. c. Trees are normally larger than other data structures. d. Trees are recursive data structures.

d. Trees are recursive data structures.

Which of the following is TRUE of UML diagrams? a. A UML "Has-a" relationship is indicated with a white triangle arrowhead facing the parent class. b. A UML "Is-a" relationship is indicated with a filled diamond arrow. c. The circle with a cross through it indicates an inheritance relationship. d. UML virtual functions are italicized.

d. UML virtual functions are italicized.

Which of the following describes testing the smallest testable piece of the software? a. Acceptable testing. b. Integration testing. c. System testing. d. Unit testing.

d. Unit testing.

Which of the following IS NOT included in the C++ memory model? a. Heap. b. Initialized data. c. Stack. d. Virtual memory.

d. Virtual memory

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(n^2) for restructuring.

d. is O(n^2) for restructuring.

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.

What is the output of the following code fragment? double d = 53.12345; cout << setprecision(3) << "|"; cout << left << fixed << setfill('-'); cout << setw(10) << d << "|" << endl; a. | 53.12345| b. |----53.123| c. |-53.12345 | d. |53.123----|

d. |53.123----|

Streams are used for input and output. What else? a. The console is represented by input stream cin and output stream cout. b. You can declare your own input (or output) streams as type ifstream (or ofstream) objects. c. Class istringstream extends istreams to extract from a string. d. Output files can be formatted using I/O manipulators. e. All of the above

e. All of the above

Which of the following are part of the C++ federation? a. C. b. Object-Oriented C++ c. Standard Library Templates (STL) d. Template Metaprogramming (TMP) e. All of the above.

e. All of the above

Which of the following may be included in C S 235 C++ header files? a. Executable code and object instantiations where needed. b. Inline functions of any length. c. Pre-processor macros. d. Use of #pragma once to guard header inclusion. e. None of the above.

e. None of the above


Kaugnay na mga set ng pag-aaral

Algebra II Lesson 2.2 Standard Form of Linear Equations

View Set

German geography cards, Geography Questions, Germany Geography Questions (Zach Butterfield)

View Set

Chap. 23 - Caring for clients with infectious and inflammatory disorders of the heart and blood vessels.

View Set

Social and Behavioral Responsible Conduct of Research

View Set

Nursing Care of the Newborn (Level 1)

View Set