C++ ch 20, 21, 12
When working with a binary tree, a node that has more than two children:
is theoretically impossible in a correctly-developed binary tree structure
A node that has no children is known as a ________.
leaf node
Values are typically stored in a binary search tree so that a node's ________ child holds data is less than the ________ data.
left, node's
The QuickSort algorithm is used to sort ________.
lists stored in arrays or linear linked lists
In a non-linear linked list, a node can point to:
more than one other node, plus the previous node in sequence
Outside of a C++ program, a file is identified by its ________. Inside a C++ program, a file is identified by a(n) ________.
name, file stream object
In a binary tree, each node may point to ________ other nodes.
no, one, two
This data type can be used to create files and write information to them but cannot be used to read information from them.
ofstream
To set up a file to perform file I/O, you must declare:
one or more file stream objects
7. A class may have this many default constructor(s).
only one
If you do not furnish one of these, an automatic memberwise copy will be performed when one object is assigned to another object.
overloaded assignment operator
This member function writes a single character to a file.
put
The ________ algorithm uses recursion to efficiently sort a list.
quicksort
This term means non-sequentially accessing information in a file.
random access
To access files from a C++ program, you must use this directive:
#include <fstream>
How many times will the following function call itself, if the value 5 is passed as the argument? void showMessage(int n) { if (n > 0) { cout << "Good day!" << endl; showMessage(n - 1); } }
5
Binary trees may be implemented as templates, but any data types used with them must support the ________ operator.
<, >, ==
The advantage a linked list has over a vector is:
A node can be inserted into or removed from a linked list faster than from a vector
How many times will the following function call itself, if the value 5 is passed as the argument? void showMessage(int n) { if (n > 0) { cout << "Good day!" << endl; showMessage(n + 1); } }
An infinite number of times
The QuickSort algorithm was developed in 1960 by ________.
C.A.R. Hoare
The ________ marker is the character that marks the end of a file, and is automatically written when the file is closed.
End of File (EOF)
________ queues are more intuitive and easier to understand than ________ queues.
Dynamic, static
What is true about the following statement? out.open("values.dat", ios::app);
If the file already exists, its contents are preserved and all output is written to the end of the file.
Class declarations are usually stored here.
In their own header files
In order, the three-step process of using a file in a C++ program involves:
Open the file, read/write/save data, close the file
True/False: All nodes to the right of a node hold values greater than the node's value.
true
Deleting a node that has two children offers an opportunity to use:
a function that returns a pointer to a pointer, a function parameter that is a pointer to a pointer, double indirection
The following statement: stack< int, vector<int> > iStack; indicates:
a new stack of integers, implemented as a vector
All node pointers that do not point to other nodes are set to:
a null pointer
The programmer must ensure that a recursive function does not become:
an endless loop
When you dereference a pointer to a pointer, the result is:
another pointer
When a file is opened, the file stream object's "read position" is ________.
at the beginning of the file
A recursive function is designed to terminate when it reaches its ________.
base case
When a binary tree is used to facilitate a search, it is referred to as a ________.
binary search tree
When the root node points to two other nodes, the nodes are referred to as ________.
child nodes, or children
Recursion can be used to:
compute factorials, find GCD's, traverse linked lists
When objects contain pointers, it is a good idea to create an explicit ________ function.
copy constructor
A class is a(n) ________ that is defined by the programmer.
data type
ofstream, ifstream, and fstream are:
data types
Which statement opens a file in such a way that information will only be written to its end?
dataFile.open("info.dat", ios::out | ios::app);
Which of the following statements opens the file info.txt for both input and output?
dataFile.open("info.txt", ios::in | ios::out);
When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n) ________.
default constructor
6. Assuming that Rectangle is a class name, the statement: Rectangle *BoxPtr;
defines a Rectangle pointer variable called BoxPtr
The ________ of recursion is the number of times a recursive function calls itself.
depth
The shape of a binary tree is ________.
determined by the order in which values are inserted
The list container provided by the Standard Template Library is a template version of a ________.
doubly-linked list
Variations of the linked list are:
doubly-linked list, circular linked list
All stream objects have ________, which indicate the condition of the stream.
error state bits
True/False: A recursive function cannot call another function.
false
True/False: By default, files are opened in binary mode.
false
True/False: In a binary tree, each node must have a minimum of two children.
false
True/False: Indirect recursion means that a function calls itself n number of times, then processing of the function starts from the first call.
false
True/False: Only one file stream object can be declared per C++ program.
false
True/False: Output will be the same if you use inorder, postorder, or preorder traversals of the same binary tree.
false
True/False: The setprecision manipulator cannot be used to format data written to a file.
false
True/False: To remove a node that has children, you must first remove the children.
false
True/False: To write to a file, you use the file_write() function.
false
True/False: When data is read from a file, it is automatically stored in a variable.
false
True/False: When recursion is used on a linked list, it will always display the contents of the list in reverse order.
false
True/False: When used by itself, the ios::app flag causes the file's existing contents to be deleted if the file already exists.
false
True/False: When you store data in a variable, it is automatically saved in a file.
false
Which statement opens a file and links it to a file stream object?
file.open("c:\\filename.txt");
This data type can be used to create files, read data from them, and write data to them.
fstream
This member function reads a single character from a file.
get
This data type can be used to create files and read information from them into memory.
ifstream
Data stored here disappears once the program stops running or the computer is powered down.
in RAM
When function A calls function B, which in turn calls function A, this is known as:
indirect recursion
When the body of a member function is defined inside a class declaration, it is said to be ________.
inline
Methods of traversing a binary tree are:
inorder traversal, preorder traversal, postorder traversal
An operation that can be performed on a binary search tree is:
insertion, finding, deleting
This state bit can be tested to see if the end of an input stream is encountered.
ios::eofbit
This state bit is set when an attempted operation has failed.
ios::failbit
When used by itself, this access flag causes a file's contents to be deleted if the file already exists.
ios::out
The inorder, preorder, and postorder traversals can be accomplished using ________.
recursion
A ________ function is one that calls itself
recursive
C++ requires that a copy constructor's parameter be a(n) ________.
reference object
The first node in a binary tree list is called the ________.
root node
The ________ in a binary tree is similar to the head pointer in a linked list.
root pointer
Closing a file causes any unsaved information still held in the file buffer to be ________.
saved to the file
If a member variable is declared ________, all objects of that class have access to that variable.
static
A C++ class is similar to one of these.
structure
Binary trees can be divided into:
subtrees
The beginning of a function template is marked by a ________.
template prefix
linked list class must take care of removing the dynamically allocated nodes. This is done by ________.
the destructor function
When an application begins searching a binary tree, it starts at ________.
the root node
In a binary tree class, you usually have a pointer as a member that is set to ________.
the root of the tree
A binary tree with a height of three has:
three levels
A good reason to use the binary tree structure is:
to expedite the process of searching large sets of information
The process of stepping through the nodes of a binary tree is known as ________.
traversing
The head pointer, anchored at the top of a binary tree, is called the ________.
tree pointer
True/False: A subtree is an entire branch of a tree, from one particular node down.
true
True/False: An alternative to using the open member function is to use the file stream object declaration itself to open the file. Example: fstream DataFile("names.dat", ios::in | ios::out);
true
True/False: Any algorithm that can be coded with recursion can also be coded with an iterative structure.
true
True/False: Binary trees are commonly used to organize key values that index database records.
true
True/False: Deleting a leaf node from a binary tree is not difficult. Deleting a non-leaf node requires several steps.
true
True/False: Dereferencing a pointer to a pointer gives you another pointer.
true
True/False: File output may be formatted the same way as console screen output.
true
True/False: If a file already exists, you can open it with the flags ios::in | ios::out to preserve its contents.
true
True/False: Like a loop, a recursive function must have some method to control the number of times it repeats.
true
True/False: Recursive algorithms are less efficient than iterative algorithms.
true
True/False: The binary tree structure is called a "tree" because it resembles an upside-down tree.
true
True/False: The height of a tree describes how many levels there are in the tree.
true
True/False: The inorder method of traversing a binary tree involves traversing the node's left subtree, processing the node's data, and then traversing the node's right subtree.
true
True/False: The ios::hardfail bit is set when an unrecoverable error occurs.
true
True/False: The ios::out flag causes the file's existing contents to be deleted if the file already exists.
true
True/False: The preorder method of traversing a binary tree involves processing the node's data, traversing the node's left subtree, then traversing the node's right subtree.
true
True/False: The speed and amount of memory available to modern computers diminishes the performance impact of recursion so much that inefficiency is no longer a strong argument against it.
true
True/False: The width of a tree is the largest number of nodes in the same level.
true
True/False: When a recursive function directly calls itself, this is known as direct recursion.
true
True/False: When passing a file stream object to a function, you should always pass it by reference.
true
A binary tree can be created using a struct or class containing a data value and ________.
two pointers, one for the left child and one for the right child
The QuickSort algorithm works on the basis of
two sublists and a pivot
If a recursive function does not contain a base case, it ________.
uses up all available stack memory, causing the program to crash
A dynamic stack has a ________ size, and is implemented as a(n) ________.
variable, linked list
The end-of-file marker is automatically written ________.
when a file is closed
This member function can be used to store binary data to a file.
write
The recursive factorial function calculates the factorial of its parameter. Its base case is when the parameter is ________.
zero