EECS 280 FINAL T/F PRACTICE QUESTIONS &
ANSWERS
Assuming a valid BST node *, the expression *node never results in error - Answer -
false (an empty tree is a valid BST, so node could be a nullptr)
If you have a container of pointers to dynamically allocated objects, the container's
destructor should ensure they are cleaned up - Answer -false (the destructor only
cleans up memory allocated by the container itself)
Deleting a dynamically allocated array will be done with both delete[] as well as a for
loop of delete arr[i] - Answer -false (the loop-version results in undefined behavior)
Destructors are only called when using the delete or delete[] keyword - Answer -false
(memory that is local goes out of scope)
Dangling pointer means you have set a pointer to nullptr after deleting what it was
pointing to - Answer -false (it's exactly the opposite: Dangling pointer still points to the
deleted object)
An overloaded == operator is REQUIRED for classes that manage dynamic memory
(eg. to avoid shallow copies) - Answer -false (the only requirements are from the Big 3 -
ctr, dtr, overloaded= operator. operator== is not one of them)
Tree recursive functions can be tail recursive - Answer -false (goes against definition of
tree recursive - multiple recursive calls from at least one function call - in tail recursion,
no work done after recursive call)
A class that has a pointer as a member variable should implement the Big Three -
Answer -false (only classes with pointers to dynamically allocated memory need the Big
Three)
Any recursive solution written for a binary search tree will always be tree recursive -
Answer -false
When the new keyword is used to create a dynamic object, the new operation evaluates
to the value of that object - Answer -false
In C++, static member functions have access to the this pointer - Answer -false
The private members of a class can never be accessed by any other class - Answer -
false (friend classes)
, A container of pointers is responsible for deleting memory associated with those
pointers - Answer -false (only if dynamically allocated??)
Imposter syndrome is a condition in which someone believes that they know less than
other people in a similar situation - Answer -true
A function that is linear recursive can also be tail recursive - Answer -true (linear
recursion - at most one recursive call each time the function is called, tail recursion -
linear recursion and all recursive calls are tail calls)
An uncaught exception will cause the program to terminate - Answer -true
Printing all the elements in an array has linear O(n) time complexity - Answer -true
Finding the element at index i in an array has constant O(1) time complexity - Answer -
true
Assuming a data structure uses an array to store an ordered sequence of elements and
keeps track of the number of elements, removing the last element from the sequence
has constant O(1) time complexity - Answer -true
Assuming a data structure uses an array to store an ordered sequence of elements and
keeps track of the number of elements, removing an element from the middle of the
sequence has constant O(1) time complexity - Answer -false
Given a pointer to an element in the middle of an array, removing that element from the
array has constant O(1) time complexity - Answer -false
A set based on a sorted array has better time complexity for a contains() operation, but
worse time complexity for insert() and remove() when compared to a set based on an
unsorted array - Answer -false (not worse, but same)
A set based on a sorted array has better time complexity for a contains() operation, but
the same time complexity for insert() and remove() when compared to a set based on
an unsorted array - Answer -true
An instance of a container class with a template parameter for its element type may
contain several different kinds of objects at runtime - Answer -false
An instance of a container class with a template parameter for its element type must
choose the type of element it contains at compile_time, and this cannot be changed at
runtime - Answer -true
Representation invariants are used to specify the C++ type of an ADT's member
variables - Answer -false
ANSWERS
Assuming a valid BST node *, the expression *node never results in error - Answer -
false (an empty tree is a valid BST, so node could be a nullptr)
If you have a container of pointers to dynamically allocated objects, the container's
destructor should ensure they are cleaned up - Answer -false (the destructor only
cleans up memory allocated by the container itself)
Deleting a dynamically allocated array will be done with both delete[] as well as a for
loop of delete arr[i] - Answer -false (the loop-version results in undefined behavior)
Destructors are only called when using the delete or delete[] keyword - Answer -false
(memory that is local goes out of scope)
Dangling pointer means you have set a pointer to nullptr after deleting what it was
pointing to - Answer -false (it's exactly the opposite: Dangling pointer still points to the
deleted object)
An overloaded == operator is REQUIRED for classes that manage dynamic memory
(eg. to avoid shallow copies) - Answer -false (the only requirements are from the Big 3 -
ctr, dtr, overloaded= operator. operator== is not one of them)
Tree recursive functions can be tail recursive - Answer -false (goes against definition of
tree recursive - multiple recursive calls from at least one function call - in tail recursion,
no work done after recursive call)
A class that has a pointer as a member variable should implement the Big Three -
Answer -false (only classes with pointers to dynamically allocated memory need the Big
Three)
Any recursive solution written for a binary search tree will always be tree recursive -
Answer -false
When the new keyword is used to create a dynamic object, the new operation evaluates
to the value of that object - Answer -false
In C++, static member functions have access to the this pointer - Answer -false
The private members of a class can never be accessed by any other class - Answer -
false (friend classes)
, A container of pointers is responsible for deleting memory associated with those
pointers - Answer -false (only if dynamically allocated??)
Imposter syndrome is a condition in which someone believes that they know less than
other people in a similar situation - Answer -true
A function that is linear recursive can also be tail recursive - Answer -true (linear
recursion - at most one recursive call each time the function is called, tail recursion -
linear recursion and all recursive calls are tail calls)
An uncaught exception will cause the program to terminate - Answer -true
Printing all the elements in an array has linear O(n) time complexity - Answer -true
Finding the element at index i in an array has constant O(1) time complexity - Answer -
true
Assuming a data structure uses an array to store an ordered sequence of elements and
keeps track of the number of elements, removing the last element from the sequence
has constant O(1) time complexity - Answer -true
Assuming a data structure uses an array to store an ordered sequence of elements and
keeps track of the number of elements, removing an element from the middle of the
sequence has constant O(1) time complexity - Answer -false
Given a pointer to an element in the middle of an array, removing that element from the
array has constant O(1) time complexity - Answer -false
A set based on a sorted array has better time complexity for a contains() operation, but
worse time complexity for insert() and remove() when compared to a set based on an
unsorted array - Answer -false (not worse, but same)
A set based on a sorted array has better time complexity for a contains() operation, but
the same time complexity for insert() and remove() when compared to a set based on
an unsorted array - Answer -true
An instance of a container class with a template parameter for its element type may
contain several different kinds of objects at runtime - Answer -false
An instance of a container class with a template parameter for its element type must
choose the type of element it contains at compile_time, and this cannot be changed at
runtime - Answer -true
Representation invariants are used to specify the C++ type of an ADT's member
variables - Answer -false