EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II
Quiz 4 Solutions
Q1: What value does function mystery return when called with a value of 4?
int mystery ( int number )
{
if ( number <= 1 )
return 1;
else
return number * mystery( number – 1 );
}
a. 0.
b. 1.
c. 4.
d. 24.
ANS: d. 24.
Q2: Recursion is memory-intensive because:
a. Recursive functions tend to declare many local variables.
b. Previous function calls are still open when the function calls itself and the activation records of these
previous calls still occupy space on the call stack.
c. Many copies of the function code are created.
d. It requires large data values.
ANS: b. Previous function calls are still open when the function calls itself and the activation records of these
previous calls still occupy space on the call stack.
Q3: Linear search is highly inefficient compared to binary search when dealing with:
a. Small, unsorted arrays.
b. Small, sorted arrays.
c. Large, unsorted arrays.
d. Large, sorted arrays.
ANS: d. Large, sorted arrays.
Q4: A double subscripted array declared as int a[ 3 ][ 5 ]; has how many elements?
a. 15
b. 13
c. 10
d. 8
ANS: a. 15
1|Quiz 4 Solutions
, EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II
Q5: Using square brackets ([]) to retrieve vector elements __________ perform bounds checking;
using member function at to retrieve vector elements __________ perform bounds checking.
a. Does not, does not.
b. Does not, does.
c. Does, does not.
d. Does, does.
ANS: b. Does not, does.
Q6: Which file open mode would be used to write data only to the end of an existing file?
a. ios::app
b. ios::in
c. ios::out
d. ios::trunc
ANS a. ios::app
Q7: A random access file is organized most like a(n):
a. Array.
b. Object.
c. Class.
d. Pointer.
ANS: a. Array.
Q8: To write fixed-length records, use file open mode:
a. ios::app
b. ios::ate
c. ios::trunc
d. ios::binary
ANS: d. ios::binary
Q9: The total number of elements that can be stored in a string without increasing its current amount of allocated
memory is called its:
a. Size.
b. Length.
c. Capacity.
d. Maximum size.
ANS: c. Capacity.
Q10: An algorithm that requires __________ operations to complete its task on n data elements is said to have a
linear runtime.
3
a. n + 9
2
b. 3 n + 3 n + 2
c. 2 n + 1
d. 6
ANS c. 2 n + 1
2|Quiz 4 Solutions
Quiz 4 Solutions
Q1: What value does function mystery return when called with a value of 4?
int mystery ( int number )
{
if ( number <= 1 )
return 1;
else
return number * mystery( number – 1 );
}
a. 0.
b. 1.
c. 4.
d. 24.
ANS: d. 24.
Q2: Recursion is memory-intensive because:
a. Recursive functions tend to declare many local variables.
b. Previous function calls are still open when the function calls itself and the activation records of these
previous calls still occupy space on the call stack.
c. Many copies of the function code are created.
d. It requires large data values.
ANS: b. Previous function calls are still open when the function calls itself and the activation records of these
previous calls still occupy space on the call stack.
Q3: Linear search is highly inefficient compared to binary search when dealing with:
a. Small, unsorted arrays.
b. Small, sorted arrays.
c. Large, unsorted arrays.
d. Large, sorted arrays.
ANS: d. Large, sorted arrays.
Q4: A double subscripted array declared as int a[ 3 ][ 5 ]; has how many elements?
a. 15
b. 13
c. 10
d. 8
ANS: a. 15
1|Quiz 4 Solutions
, EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II
Q5: Using square brackets ([]) to retrieve vector elements __________ perform bounds checking;
using member function at to retrieve vector elements __________ perform bounds checking.
a. Does not, does not.
b. Does not, does.
c. Does, does not.
d. Does, does.
ANS: b. Does not, does.
Q6: Which file open mode would be used to write data only to the end of an existing file?
a. ios::app
b. ios::in
c. ios::out
d. ios::trunc
ANS a. ios::app
Q7: A random access file is organized most like a(n):
a. Array.
b. Object.
c. Class.
d. Pointer.
ANS: a. Array.
Q8: To write fixed-length records, use file open mode:
a. ios::app
b. ios::ate
c. ios::trunc
d. ios::binary
ANS: d. ios::binary
Q9: The total number of elements that can be stored in a string without increasing its current amount of allocated
memory is called its:
a. Size.
b. Length.
c. Capacity.
d. Maximum size.
ANS: c. Capacity.
Q10: An algorithm that requires __________ operations to complete its task on n data elements is said to have a
linear runtime.
3
a. n + 9
2
b. 3 n + 3 n + 2
c. 2 n + 1
d. 6
ANS c. 2 n + 1
2|Quiz 4 Solutions