CS 235 Final Exam
Which of the following is 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.
None of the above.
To convert from infix (without parentheses) to postfix, use a stack of
Operators and operands
Infix-to-postfix uses a stack of ____, postfix evaluation a stack of _____, and postfix-to-infix a stack of _____.
Operators, operands, operators
__________ traversal doesn't exist.
Outorder
Writing "towers of Hanoi" code for 64 disks is
Virtually the same as for 3 disks.
For the contiguous representation fo ADT deque, when an end of the deque is reached, __.
Wrap around to the other end
What is recursion?
problem-solving approach that causes functions to call themselves with different arguments
The separation of what is to be done from how it is to done is called _________.
procedural abstraction
What makes backtracking different from random trial and error?
Backtracking is a systematic approach that will not try the same path more than once
Which of the following should be used to allow you to use cout in your c++ program? a. using <iostream> b. import iostream c. #include <iostream> d. using namespace std;', (This would be helpful, but not required nor enough)
#include <iostream>
Suppose we want to get the address of a variable named x. Which of the following would provide that? a. ->x b. *x c. &x d. address(x)
&x
Which of the following is in correct descending precedence order? a. () & ~ == || b. [] << + % c. * * & + d. & && ^ |
() & ~ == ||
Which of the following would be an appropriate implementations of a queue? a. The standard list implementation. b. A single-linked list. c. A circular array. d. All of the above.
A circular array
What is the relationship between a class and an object? a. A class is specific; an object is general b. A class is general; an object is specific c. The two terms are totally unrelated d. The two terms are interchangeable
A class is general; an object is specific
What is an iterator? a. A pointer. b. A class that allows for a data structure to be traversed. c. Any object that defines the ++, *, and != operators. d. A struct that contains data and a pointer to the next chunk of data.
A class that allows for a data structure to be traversed
Which representation of a queue has the most favorable Big Ohs for the (as discussed in class)?
Circular array
What are characteristics of a good pivot in the quicksort algorithm?
It is close to the median value of the list.
T/F : If ADT preconditions are met, the postconditions must be achieved.
True
To restore the AVL property after inserting a element, we start at the insertion point and move towards root of that tree.
True
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 __________.
Use an iterator
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.
+ %
Which of the following can help to reduce collisions in a hash table?
- Expanding the table size. - Using quadratic probing instead of linear probing.
"Big O" for find, insert, and erase when hashing should be ___, ___, and ___, respectively.
1, 1, 1
What is the maximum black-height of a Red-Black Tree with 7 nodes?
2
A left-right AVL imbalance calls for ___________ rotation(s); a right-right imbalance calls for ____________ rotation(s) to correct the immediate imbalance.
2, 1
In this sequence, 11 4 20 45 32 60 98 70, which element seems to be the pivot?
20
Consider a binary max-heap implemented using an array. Which one of the following array represents a binary max-heap? a. 25,12,16,13,10,8,14 b. 25,12,16,13,10,8,14 c. 25,14,16,13,10,8,12 d. 25,14,12,13,10,8,16
25,14,16,13,10,8,12
How many different kinds of unbalanced trees are there? a. 2 b. 3 c. 4 d. 5
4
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?
4
What is the maximum height of an AVL-tree with 7 nodes? (Assume the height of a tree with a single node is 1.)
4
If the number 5 is deleted from the above tree, what would be the level-order traversal order? 5 / \ 1 10 / \ / 0 4 7 \ 9
4 1 10 0 7 9
The maximum number of binary trees that can be formed with three unlabeled nodes is: a. 1 b. 3 c. 4 d. 5
5
What is the matching postfix expression to the following infix expression: 7 + (2 * 3) / 9?
7 2 3 * 9 / +
Which of the following would not be a good application for a binary tree?
A family tree.
What types of maps would NOT be useful in a Huffman Code algorithm?
A map of strings to characters, representing the decodings of each string
What is true of shell and/or merge sorts?
A merge sort is a stable sort.
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 min-heap
What happens when a recursive function calls itself?
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 pointer to the next node
All of the following are true of Big-O analysis EXCEPT what? a. A simple way to determine the Big-O of an algorithm or program is to look at the loops invariants. b. Algorithms with exponential and factorial growth rates have practical limits due to computer resources. c. In general, we ignore all constants and drop the lower-order terms when determining the order of magnitude. d. The growth rate of f(n) will be determined by the fastest growing term, which is the one with the largest exponent.
A simple way to determine the Big-O of an algorithm or program is to look at the loops invariants.
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.
Accessing any given element in a linked list is more efficient
How does a 2-3 tree maintain balance? a. The root is always a 3-node. b. Through rotations if a new node ever causes an imbalance. c. All of its leaf nodes are at the lowest level. d. By always adding both children nodes at the same time.
All of its leaf nodes are at the lowest level
Polymorphism expects _______. a. functions with common signatures at different levels in a 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 the above
All of the above
What file extension can you use on a file that contains the definitions of functions and classes? a. .cpp b. .cc c. .C d. All of the above
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.
All of the above
What best describes Namespaces? a. The entire C++ standard library is contained in the namespace std. b. Namespaces are used to organize code into logical groups and to prevent name collisions. c. All names introduced by declarations within a namespace-body become members of the current namespace identifier. d. All of the above are true.
All of the above are true
A Priority Queue is an extension of a queue with the following properties:
An element with high priority is dequeued before an element with low priority.
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 caller function. d. The ampersand (&) indicates that the following identifier is a pointer variable.
Array pointers enable us to conveniently process groups of data such as vectors, lists, and strings.
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 use of const always yields smaller code size.
As a general rule you should give the compiler preference to the preprocessor.
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 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. e. Non-statically-scoped objects are shared across multiple translation units. f. Along with any class or function, static limits scope to the translation unit. g. The linker joins translation units into an object.
B & E
Why is Node typically defined as a struct in the private part of the 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
Because a struct's data members are public by default
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.
Begin at the head and ask if the next node in the list is the head
What features are considered fundamental by the C++ standard to containers? a. Containers grow as needed. b. Containers hold objects. c. Both of the above d. None of the above
Both of the above
Which of the following functions is the least efficient when implemented recursively?
Calculating the nth Fibonacci number.
When the array representation of ADT queue becomes full, ____.
Call a reallocate function specialized for the array-based queue
Generally speaking, an ADT can be represented using a(n)_______.
Contiguous structure or a linked structure
Which of following is NOT a method in which an object is created? a. Creating a local variable when you change the value of a pre-existing variable b. Creating global objects at the beginning of the execution of the program c. Creating member variables when a class is created d. Creating local variable at the beginning of a function
Creating a local variable when you change the value of a pre-existing variable
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 or enumerated type. d. When a break statement is reached, control jumps to the next line following the switch statement.
Every case needs to contain a break.
Quicksort is a stable sort.
False
True or false: Iterators must contain a dynamically allocated array.
False
Which of the following most accurately describes the behavior of a queue?
First in, first out (FIFO).
Which of the following most accurately describes the bubble sort algorithm?
Gradually shifting larger items to the back of the array, or smaller items to the front.
Let H(value) be a function that returns the hash code of "value." If A == B, then _______.
H(A) == H(B)
What is the primary advantage of heap sort over merge sort?
Heap sort requires less space than merge sort.
The sequential representation of ADT deque ______.
Is not practical (too many O(n) operations)
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
Last in, first out
What are use cases? a. A log of applications that have actually used a class together with the absolute or relative frequency of use. b. Applications designed to test the functionality of classes. c. Diagrams of messages issued by the user and the options subsequently available to the user. d. Lists of user actions and system responses
Lists of user actions and system responses
The contiguous implementation of ADT deque is ____.
More like the contiguous implementation of ADT queue
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 that 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
Nodes in a singly linked list contain more data that nodes in a doubly linked list.
The inorder traversal sequence of a binary tree is A B C. The root is _______.
Not a unique binary tree.
What is the expected run time for inserting into a hash table?
O(1)
What is the best case performance of the quicksort algorithm?
O(n)
The Big O of the number of exchanges of selection sort is ___. The Big O of the comparisons is ___.
O(n), O(n2)
What is the worst case performance of bubble sort?
O(n^2)
Quicksort uses
Partitioning
Which of the following most accurately describes the selection sort algorithm?
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 merge sort algorithm?
Splitting the array evenly in half, and sorting the halves recursively.
Which of the following most accurately describes the quicksort algorithm?
Splitting the array in halves based on size, and sorting the halves recursively.
What is the difference between sort and stable_sort?
Stable_sort will preserve ordering of duplicate items.
Which part of the compiler program merges the include files into the source file? a. The Preprocessor b. The C++ Compiler c. The Linker d. All of the above
The Preprocessor
If you represent the string "Hello!" as a C String called str, what is the value of str[6]? a. The character '!' b. Nothing, that would result in an error c. The character '\0' d. The character '0\'
The character '\0'
What is the downside of recursion?
The function may result in a run-time error when there is no more memory available.
All of the following are true of iterators EXCEPT what? a. The iterator end() function returns a pointer to the last element in 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
The iterator end() function returns a pointer to the last element in the container.
A map consists of a set of keys, each with one or more values. Which typically is/are unique?
The keys
In tail recursion, ____________.
The recursive call is the last executable statement in the function
What is the matching infix expression to the following postfix expression: 8 9 + 4 * -
There is none, it is an invalid expression
What do Red-Black trees, 2-3-4 trees, and AVL trees all have in common?
They are all self balancing trees.
Suppose you want to traverse a hash table of names in alphabetical order. How would you do that?
This cannot be done.
(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
The reallocate function for class Queue
Typically does not copy elements to identical index positions
Should a new Huffman tree be built for each file you create? Why or why not?
Yes, because different files may contain symbols with different frequencies.
In a binary search tree, all of the following are synonyms except _______.
a node's parent
The most obvious form of an iterator is a. & operator b. a pointer c. destructor d. an at operator
a pointer
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.
_______ 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 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 the functionality of the base class.
b. You made a child class so you need to override every function.
When 2 rotations are needed in an AVL tree, the first rotation should be around the ________; the second rotation should be around the __________. a. parent, child in the same direction b. child, parent in the same direction c. child, parent in the opposite direction d. parent, child in the opposite direction
child, parent in the opposite direction
When using a dynamically allocated array of size n, you should use _______ to delete it. a. delete[] array b. delete[n] array c. delete array[n] d. delete array
delete[] array
If the local root has an AVL imbalance of -2 and both its children have balances of 0, ___________. a. do a double rotation b. do a single rotation c. do nothing d. you messed up; this cannot happen
do a single rotation
The most appropriate linked representation for a deque is _____. a. double- non-circular b. double- circular c. single- circular d. single- non-circular
double-circular
The loop invariant must be true at all of the following times EXCEPT __________. a. at the beginning of each repetition of the loop b. after each iteration c. before loop execution begins d. during loop execution
during loop execution
In C++, the standard definition of "NULL" is _________. a. always a pointer to an int b. totally blank memory c. a pointer to the recycle bin on your computer d. exactly the same as the number 0
exactly the same as the number 0
For which function in the algorithm library would a function object most likely be used? a. find b. swap c. random_shuffle d. All of the above.
find
A Huffman tree, like the one depicted on page 450 of the course text, is a _________.
full binary tree
Cells in a 3D maze should be probed in a consistent order to _____________. a. avoid redundant consideration of cells b. facilitate discovery of the shortest path through the maze (if it exists) c. simplify the coding d. guarantee discovery of a solution if it exists
guarantee discovery of a solution if it exists
What maximum difference in heights between the leafs of a AVL tree is possible? a. 0 or 1. b. atmost 1. c. log(n) where n is the number of nodes. d. n where n is the number of nodes.
log(n) where n is the number of nodes
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?
log(n), where n is the number of items in the list
Which data type should you use if you need to handle very large integers (i.e. you can safely ignore remainders) a. short b. long c. int d. double
long
What kind of mapping is used in a map from keys to values?
many-to-one
When using a dynamically allocated array of size n, you should use _______ to create it. a. new array b. new[n] array c. new array[n] d. new array[]
new array[n]
To check for balanced parentheses, use a stack of a. parentheses b. operators and operands c. operands d. operators
parentheses
In the linked representation of a queue, the pointers should _________. a. point from the front toward the rear b. point from the rear toward the front c. a or b, but not both d. point to each node's successor and predecessor
point from the front toward the rear
An iterator functions most like a(n) a. [] operator b. pointer c. destructor d. at operator
pointer
All of the following separate the "what" from the "how" except ___________. a. procedural abstraction b. data abstraction c. information hiding d. (no exceptions here)
procedural abstraction
While insertion sort is generally O(n^2), it is ______.
sometimes O(n)
Balance, in the context of AVL trees, refers to ___________.
the difference between the heights of the right and left nodes
Which operator CANNOT be overloaded?
the dot operator
When collisions are resolved using linear probing, ______.
the insertion occurs at the first available slot that was not previously occupied
The "order of complexity" of an algorithm expresses a. precisely how fast it can be expected to execute b. the limiting behavior of a function when the argument tends towards infinity c. the (functional decomposition / piecewise refinement / top-down) level of the algorithm d. the number of function calls (both direct and indirect) anticipated by the algorithm
the limiting behavior of a function when the argument tends towards infinity
Suppose you want to access the next element of a stack. Which function would you call? a. top() b. pop() c. push() d. next()
top()
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)
using a contiguous structure or a linked structure
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 value as an argument d. when an object of the class is returned by value e. when the compiler generates a temporary object
when a deep copy is require
What things are necessary in a recursive function?
A base case and a recursive call
What is the worst case possible height of AVL tree? a. 2 * log n b. 1.44 * log n c. O(n) d. Depends upon implementation.
1.44 * log n
A Huffman tree for an alphabet of 15 distinct characters has _____ leaf nodes.
15
What are the correct intermediate steps of the following data set when it is being sorted with the Quick sort? 15,20,10,18
15,10,20,18 -- 10,15,20,18 -- 10,15,18,20
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?
19
How many base cases are in the maze solving algorithm?
3
Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8, 4. Now consider that a value 35 is inserted into this heap. After insertion, the new heap is a. 40, 30, 20, 10, 15, 16, 17, 8, 4, 35 b. 40, 35, 20, 10, 30, 16, 17, 8, 4, 15 c. 40, 30, 20, 10, 35, 16, 17, 8, 4, 15 d. 40, 35, 20, 10, 15, 16, 17, 8, 4, 30
40, 35, 20, 10, 30, 16, 17, 8, 4, 15
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
5 1 0 4 3 10 7 9
What is the result of the postfix expression: 4 7 * 20 - ?
8
Considering the following AVL tree, which of the following is the updated AVL tree after insertion of 70? 60 / \ 20 100 / \ 80 120
80 / \ 60 100 / \ \ 20 70 120
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 C++ concept serves as a constraint by limiting the set of arguments that are accepted as template parameters.
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. e. A pointer and a reference variable both occupy the same amount of memory. f. Const references can be bound to temporaries. g. Pointers can point nowhere (NULL), whereas reference always refer to an object. h. You can\'t take the address of a reference like you can with pointers. i. Pointers can point nowhere (NULL), whereas reference always refer to an object.
C, G, H, I
Quicksort is run on two inputs shown below to sort in ascending order taking first element as pivot. Let C1 and C2 be the number of comparisons made for the inputs (i) and (ii) respectively. Then, 1, 2, 3,......., n, n-1, n-2,......, 2, 1 a. C1 < C2 b. C1 > C2 c. C1 = C2 d. We cannot say anything for arbitrary n
C1 = C2
How can you verify that a list is sorted?
Check each element in the list and make sure that it is not less than its predecessor.
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?
D
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
What is C++ object delegation? a. Delegation allows 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
Delegation allows exposure to some functionality of a pre-existing class, but still control access through your own interface
Recursion typically is justified when it reduces ________.
Design and coding time
What is NOT true concerning dynamic-casts? a. Dynamic_cast does not offer runtime type checking. b. Dynamic_cast ensures that the result of the type conversion points to a valid complete object of the destination pointer type. c. Dynamic_cast has runtime type checking and only works with references and pointers. d. Dynamic_cast only supports pointer and reference types
Dynamic_cast does not offer runtime type checking.
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?
Every item in the list
What does the break statement do in a switch? a. Exit your program because you encountered an error b. Execute the next case block c. Ignore the default section of the switch', 'While true, there is a better answer d. Exit from the switch statement
Exit from the switch statement
True or false: The maze solving algorithm will not function properly if there is more than one possible path through the maze.
False
True or false: When making a recursive call in a function, the function actually just starts over instead of calling a new function.
False
True or false: a heap can only be represented with a linked data structure.
False
Pick the best statement: a. Both the preconditions and the 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.
If the preconditions are met, the postconditions must be achieved.
Which strategy is most likely to be successful? a. Implementing a linked list by using an underlying stack. b. Implementing a stack by using an underlying linked list c. Implementing a linked list by inheriting from a stack. d. Implementing a stack by inheriting from a linked list.
Implementing a stack by using an underlying linked list.
When inserting into a 2-3-4 tree, the new value is always inserted ___________. a. In the root. b. As the middle value of a 4-node. c. In a leaf node. d. (You cannot know for certain)
In a leaf node
Suppose you have a binary search tree. Which kind of traversal would print the contents in increasing order?
Inorder.
Shell sort can be interpreted as an improved version of which sorting algorithm?
Insertion sort
When used before the main function, int refers to ______. a. Intent, as in the purpose of the function b. Integral, because the main function is very important c. Integer, the data type returned by the main function d. Internal, because the program will be placed inside the computer
Integer, the data type returned by the main function
Which of the following describes testing the interactions among smaller units? a. Acceptance testing. b. Integration testing. c. System testing. d. Unit testing.
Integration Testing
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.
It assumes that each stage can be completed correctly and fully before advancing to the next stage.
What is the principal advantage of 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.)
Its ability to contain different types of data (determined at compile time.)
When writing a program, Visual Studio reports an error that says "cannot instantiate abstract class MyClass". What is likely the problem? a. MyClass has a pure-virtual function that is not defined (perhaps from a parent class). b. MyClass does not have a default constructor. c. MyClass doesn't have enough functions. d. It is impossible to know. Ask a TA.
MyClass has a pure-virtual function that is not defined (perhaps from a parent class)
Suppose I have a class named MyClass, and another class named MyParent. When defining MyClass, I use the line \"class MyClass: public MyParent\". What kind of relationship is there between MyClass and MyParent? a. MyClass has-a MyParent. b. MyClass is-a MyParent. c. MyParent has-a MyClass. d. MyParent is-a MyClass.
MyClass is-a MyParent
When using a map to implement a phone directory, the ____ should be the key and the ____ should be the value.
Name, phone number
Which of the following most accurately describes the insertion sort algorithm?
Placing each item into the correct position in the list one at a time, like a hand of FIX.
Which of the following most accurately describes the heap sort algorithm?
Placing every item into a heap and moving the top item into the sorted list.
When a queue is represented using a single-linked list, the links should
Point from the front towards the rear.
Which of the following may be included in CS 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.
Pre-processor macros
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.
Preprocessor, compiler, assembler, linker.
If you wanted to use a data structure to store a club roster, which of the following should you use? a. Map or Set b. Map c. Neither map nor set d. set
Set
What is "chaining?"
Storing a linked list in each table entry that contains each value that hashes to the same location.
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.
The 1st parameter of main() is the number of arguments and the 2nd is an array of char* pointers to those arguments.
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 referenced item can be changed. c. The dereferencing operator returns a const reference. d. The member access operator returns a const pointer
The const in the operator heading means that the referenced item can be changed
What is the difference between a while loop and a do ... while loop? a. You can use break and case statements in a do ... while loop b. The while loop always executes at least once, but the do ... while loop might not c. The do ... while loop always executes at least once, but the while loop might not d. There is no difference, just style
The do ... while loop always executes at least once, but the while loop might not
Which of the following most accurately describes the shell sort algorithm?
The last step is to perform an insertion sort on the entire array, which has been presorted by the earlier sorts.
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.
The lifetime of an object is the time duration where an object is in a valid state.
"Divide-and-conquer" refers to:
The list being divided into smaller sublists, then those sorted sublists are merged back together.
When using an ofstream, what happens when the output file name already exists? a. An error occurs, no file can be written b. The old file is erased, and the new file is written over it c. The new file is written over the old file, but only as many characters as are needed to write the new file d. The new file is appended to the old file
The old file is erased, and the new file is written over it
Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first partitioning with the array looking like this: 2 5 1 7 9 12 11 10 Which statement is correct? a. The pivot could be either the 7 or the 9. b. The pivot could be the 7, but it is not the 9. c. The pivot is not the 7, but it could be the 9. d. Neither the 7 nor the 9 is the pivot.
The pivot could be the 7, but it is not the 9.
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 functions must be at least amortized constant time to be required. d. The list class has a vector, and it adds more functionality
The push_front function would be O(n), and functions must be at least amortized constant time to be required
Which of the following is NOT an invariant of a Red-Black tree?
The root is always red.
The merge step of merge sort depends on which of the following characteristics?
The subarrays are sorted.
When working with strings, what is the difference between using the at() function and using the [] subscript like on an array? a. The subscript operators are slightly faster b. The subscript operators will crash the program if the given value is out of range of the string c. The at() function is overloaded to optionally take additional arguments d. There is no difference
The subscript operators will crash the program if the given value is out of range of the string
When comparing recursion and iteration, 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.
There is always a recursive solution to a problem that is solvable by iteration.
Traversal algorithms are fairly simple. What attribute of trees makes that so?
Trees are recursive data structures.
A Red-Black tree may not be as balanced as an AVL tree for the same series of inputs.
True
The Using-declaration does all of the following EXCEPT a. A using-declaration with more than one using-declarator is equivalent to a corresponding sequence of using-declarations with one using-declarator. b. The using declaration introduces a name that is defined elsewhere into the declarative region where this using-declaration appears. c. Using-declarations can be used to introduce namespace members into other namespaces and block scopes, or to introduce base class members into derived class definitions. d. Using-declaration introduces a member of a derived class into the base class definition, such as to expose a protected member of base as public member of derived.
Using-declaration introduces a member of a derived class into the base class definition, such as to expose a protected member of base as public member of derived
Which of the following IS NOT included in the C++ memory model? a. Heap. b. Initialized data. c. Stack. d. Virtual memory.
Virtual Memory
Which of the following is true about the selection sort?
With each pass, an element jumps to its final location.
Is it possible to have all black nodes in a Red-Black tree?
Yes, with a complete tree of all black nodes.
/* /* This is an invalid comment. 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
You cannot nest comments
Which of the following is NOT a consequence of calling by reference? a. The code may run more efficiently b. You get a pointer to the argument so you must dereference it c. Changes made to the variable within the function persist once it returns d. It may change the value of the variable, even if you didn't intend it to
You get a pointer to the argument so you must dereference it
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
acilitates the same set of operations on a variety of data types
What would be the Big Oh 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
amortized order 1
The pre-processor conditional compilation directives a. act the same as /*...*/ b. are evaluated at run-time. c. are used to eliminate lines at compilation time. d. cannot be nested.
are used to eliminate lines at compilation time.
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.
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)
c. O(n^2)
What is the proper relationship between 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
class Ordered_List has-a List
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 'Parent1::var'. d. All of the above.
d. All of the above.
Consider any array representation of an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at index i of the array (i <= n), the index of the parent is a. i - 1 b. floor(i / 2) c. ceiling(i / 2) d. (i + 1) / 2
floor(i / 2)
A private data member is visible only __________________.
in the class in which it is declared
With a heap,
insertion traces a path from a leaf to the root.
If the size of a heap is n, the performance
is O(log n) for insertion.
A Priority Queue
is a container adapter that uses a specific underlying container, e.g. vector or deque.
The performance of a self-balancing binary search tree
is of order of log(number of elements in the tree).
Assuming A is a bool, when would the condition (A && !A) be true? a. When A is true b. When A is false c. It is always true d. It is never true
it is never true
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, but if there is sufficient available space, it is reasonable to think in terms of doing so
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
more, in terms of coding time, but not execution time or memory usage
Searching for an item in a linked list is O(___). Searching in a binary search tree is O(___).
n, log(n)
As a first guess, the order of complexity of three nested loops is probably__________. a. 3 b. n^3 c. log 3n d. 3n
n^3
What is the Big O of a program which has (i) a nested loop inside a nested loop and the innermost loop has 2 simple statements, (ii) a nested loop with 2,000 simple statements inside the inner loop, and (iii) a loop with 20,000 simple statements? a. n^2 b. n^3 c. n d. 2n^3 + 2000n^2 + 20000n
n^3
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
should, the memory pointed to by the pointer must be freed to prevent memory leaks
If the preconditions for a function are not met, ___________. a. the function may or may not perform satisfactorily b. the function will not perform satisfactorily c. the function will need to be coded more robustly d. the compiler will have an error
the function may or may not perform satisfactorily
The scope of a variable refers to a.logical groups that prevent name collisions 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.
the region or section of code where a variable can be accessed.
If a particular binary tree is full and has 100 leaf nodes, how many internal nodes does it have?
99
A heap
requires every subtree to be a heap.
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 binary tree is a tree.
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.
A full binary tree need not be complete and a complete binary tree need not be full.
Pick the best statement: a. A queue differs from a stack in only one operation. b. A queue differs from a stack in several operations. c. A stack is simply a queue with a different name. d. Stacks and queues are largely unrelated.
A queue differs from a stack in only one operation.
Pick the best relationship for queues and deques
A queue has-a deque
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?
B
The contiguous Implementation on an ADT queue______.
Calls for a circular array
If you need to provide a stack, a queue, a deque, an input-restricted deque, and an output restricted deque, _____.
Each of the others should "have" a deque as a data member
When a recursive function returns after three iterations because it hits a base case, where does it return to?
The previous iteration, right after it called the next iteration
What is true of C++ strings? a. A C++ string is an alias for 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 basic_string<char>
What is TRUE of friend functions? a. A friend function is a non-member function with access to the class private and protected members. b. Friend functions 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.
Pick the best statement: a. A queue differs from a stack in only one operation. b. A queue differs from a stack in several operations. c. A stack is simply a queue with a different name. d. Stacks and queues are largely unrelated
a. A queue differs from a stack in only one operation.
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.
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).
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 typically happens as a consequence of the "++iter" component of for (list<Item_Type>::iterator iter = a_list.begin(); iter != a_list.end()l ++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 iter is inceremented by 1. c. The value of the data element referenced by iter is incremented by one and the iterator pointer 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 iter is incremented by one.
a. The iterator pointer advances to the next element of the list.
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
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
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.
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. Not relevant as each try block can have only one associated catch clause.
b. Most specific to most general.
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 classes have different names.
b. Multiple inheritance can often be avoided by refactoring.
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
For which type of error are try and catch most appropriate? a. Logic errors. b. Run-time errors. c. Syntax errors. d. All of the above.
b. Run-time errors.
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.
What happens if an exception is thrown in a program and not caught? a. The computer 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.
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.
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.
Why are Iterators useful? a. All containers have the same iterator capabilities and hence the choice of 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.
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 compile time. c. The C++ compiler is able to deduce an array size from the array pointer. d. You can use array notation or pointer
c. The C++ compiler is able to deduce an array size from the array pointer.
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.
A binary tree's conceptual counterpart of a double-linked list ______.
consists of links to children and parents: three links per node
Generally speaking, an ADT can be represented using a(n) ________. a. array or a vector b. circular linked list or non-circular linked list c. contiguous structure or a linked structure d. single-linked list or a double-linked listcontiguous structure or a linked structure
contiguous structure or a linked structure
With an iterator named iter, how would the data in the iterator be accessed? a. iter* b. iter& c. &iter d. *iter
d. *iter
Which of the following is an example of an 'has-a' relationship? a. A jet plane has a plane. b. A plane has a jet plane. c. A train engine has a train. d. A train has a train engine.
d. A train has a train engine.
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.
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.
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
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.
4. What is the output of the followig code fragment? double e = 53.12345; cout << setprecision(3) << "|"; cout << left << fixed << setfill('-'); cout << setw(10) << e << "|" << 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 istream 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.
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
force the return type to be a constant
Compared with a linked list, a binary tree ________.
has nodes with two child nodes instead of one next node