Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

Current Location

1.

COP 4530 (Spring 2014)

2.

Practice Exams

3.

Review Test Submission: Practice Midterm Exam

Menu Management Options

COP 4530 (Spring 2014)

Announcements
Discussion Board
Syllabus
Organizer
Lecture Notes
Practice Exams
Exams
My Grades
Lacher
Virtual Office Live!

Review Test Submission: Practice Midterm


Exam
Content
User
Course
Test
Started
Submitted
Status
Score
Time
Elapsed

Jeremy Crook
COP 4530 (Spring 2014)
Practice Midterm Exam
2/16/14 11:06 AM
2/16/14 12:27 PM
Completed
125 out of 200 points
1 hour, 20 minutes out of 2 hours.

Instruction
s

Not intended to represent complete coverage by the midterm


exam. Practice exam for sample and form only.
Question 1
0 out of 5 points

Select a minimal set of operations that distinguish fsu::List from from other fsu::
sequential containers.
(Here i is an iterator, t is a container element, and n is an integer.)
Answer

Selected Answers:

PushBack(t)
PushFront(t)
Insert(i,t)
Correct Answers:

Insert(i,t)

Question 2
5 out of 5 points

Which of the following are optional (but very desirable) components of


an algorithm?
Answer
Selected
Answers:

Statement of the runtime of the algorithm


body, in asymptotic notation, as a function of input size
RunTime Estimate:

Statement of the algorithm runspace


requirements, in asympotic "+" notation, as a function of
input size
RunSpace Estimate:

RunTime Proof: THEOREM. If the assumptions hold then the


asserted runtime estimates are correct.
RunSpace Proof: THEOREM. If the assumptions hold then the
asserted runspace estimates are correct.
Correct
Answers:

Statement of the runtime of the algorithm


body, in asymptotic notation, as a function of input size
RunTime Estimate:

Statement of the algorithm runspace


requirements, in asympotic "+" notation, as a function of
input size
RunSpace Estimate:

RunTime Proof: THEOREM. If the assumptions hold then the


asserted runtime estimates are correct.
RunSpace Proof: THEOREM. If the assumptions hold then the
asserted runspace estimates are correct.

Question 3
5 out of 5 points

The adaptor template defining fsu::Queue < T , C > defines an


implementation of ADT Queue by re-defining the user interface of the
container C. Which of the operations listed below must C possess for
this adaptation to compile? (Check all that apply.)
Answer
Selected Answers:

PushBack(t)
PopFront()
Correct Answers:

PushBack(t)
PopFront()

Question 4
5 out of 5 points

Suppose that we know Algorithm A has runtime (n2), where n is a


measure of input size. Which of the following statements is also true?
(Check all that apply.)
Answer
Selected Answers:

A has runtime O(n2).


A has runtime O(n3).

A has runtime (n2).


Correct Answers:

A has runtime O(n2).


A has runtime O(n3).
A has runtime (n2).

Question 5
5 out of 5 points

Necessary components in a recursive function implementation are


(select all that apply):
Answer
Selected
Answers:

A recursive call: in which the function itself is called, either


directly or indirectly
A base case: in which no recursive call is made and the
process terminates normally in a return

Correct
Answers:

A recursive call: in which the function itself is called, either


directly or indirectly
A base case: in which no recursive call is made and the
process terminates normally in a return

Question 6

The following represents output from the call d.Dump() from


the fsu::Deque<char> object d:
content_[i]: A B C D E F G H I J
i mod 10: 0 1 2 3 4 5 6 7 8 9
e
b
What is the result of the output statement
std::cout << d;
?
Answer

0 out of 5 points

Selected Answer:

D E F G H
Correct Answer:

H I J A B C

Question 7
0 out of 5 points

The following represents data of type char stored in a vector:


BBDDDFFGGGHPQQQV
With the initial search range for lower_bound underscored. Which if the following
represents the search range after ONE ineration of the loop body
in upper_bound(G) ?
Answer

Selected Answer:

BBDDDFFGGGHPQQQV
Correct Answer:

BBDDDFFGGGHPQQQV

Question 8
0 out of 5 points

Searching a vector of size n using the lower_bound algorithm has


asymptotic runtime (select the best answer)
Answer
Selected Answer:

O(n)
Correct Answer:

(log n)

Question 9
5 out of 5 points

Consider the following implementation of an fsu::List operation:


template < typename T >
ConstListIterator<T> List<T>::Insert (ConstListIterator<T> i, const T&
t)
{
// 1. create new element
Link* newLink = NewLink(t);
if (newLink == 0) return End();
// 2. link new element into the list
newLink->next_ = i.curr_;
newLink->prev_ = i.curr_->prev_;
/* MISSING LINE OF CODE */
/* MISSING LINE OF CODE */
// 3. leave i at new entry and return
i.curr_ = newLink;
return i;

} // end Insert((i,t))

Select the missing TWO LINES of code from the choices below.
Answer
Selected Answer:

newLink->next_->prev_ = newLink;
newLink->prev_->next_ = newLink;
Correct Answer:

newLink->next_->prev_ = newLink;
newLink->prev_->next_ = newLink;

Question 10
5 out of 5 points

Select the answer that best describes the asymptotic runtime of the operation
Deque<T>::PushBack(t)
Here t is an item of type Deque<T>::ValueType and n is the size of the vector.
Answer
Selected Answer:

Amortized O(1)
Correct Answer:

Amortized O(1)

Question 11
0 out of 5 points

Declare a deque object wd with elements of type Widget, and initialize


with 10 elements equal to the Widget ZED.
Answer

Selected Answer:

[None Given]

Correct Answer:

fsu::Deque<Widget> wd;
for ( size_t i = 0 ; i < 10 ; ++i )
wd.PushFront(ZED);

Question 12
0 out of 5 points

The following represents output from the call d.Dump() from


the fsu::Deque<char> object d:
content_[i]: A B C D E F G H I J
i mod 10: 0 1 2 3 4 5 6 7 8 9
e
b
What is the result of the d.Dump() after the call d.PushFront('X') ?
Answer

Selected Answer:

content_[i]:
i mod 10:

A B C D E F G X I J
0 1 2 3 4 5 6 7 8 9
e
b

Correct Answer:

content_[i]:
i mod 10:

A B C D E F X H I J
0 1 2 3 4 5 6 7 8 9
e
b

Question 13
5 out of 5 points

The following represents output from the call d.Dump() from


the fsu::Deque<char> object d:
content_[i]: A B C D E F G H I J K L
i mod 10: 0 1 2 3 4 5 6 7 8 9 0 1
e
b
What is the result of the d.Dump() after the call d.PopFront() ?
Answer

Selected Answer:

content_[i]:
i mod 10:

A B C D E F G H I J K L
0 1 2 3 4 5 6 7 8 9 0 1
e
b

content_[i]:
i mod 10:

A B C D E F G H I J K L
0 1 2 3 4 5 6 7 8 9 0 1
e
b

Correct Answer:

Question 14
0 out of 5 points

To apply the function object f to each element of the array a we can


use the following generic algorithm call (there are size elements in a):
Answer
Selected Answer:

fsu::g_for_each (a.Begin(), a.End(), f);


Correct Answer:

fsu::g_for_each (a, a + size, f);

Question 15
5 out of 5 points

Suppose the fsu::Deque<> d has elements in sorted order and we


wish to insert the element x in correct order in d. The following generic
algorithm call returns an iterator to the first correct location to insert x:
Answer
Selected
Answer:

i = fsu::g_lower_bound(d.Begin(), d.End(), x);

Correct Answer:

i = fsu::g_lower_bound(d.Begin(), d.End(), x);

Question 16
5 out of 5 points

Consider the following code implementing an fsu::List operation:


template < typename T >
bool operator != (const List<T>& x1, const List<T>& x2)
{
/* MISSING LINE OF CODE */
}

Select the missing line(s) of code from the choices below.


Answer
Selected Answer:

return !(x1 == x2);

Correct Answer:

return !(x1 == x2);

Question 17
0 out of 5 points

Consider the following code implementing an fsu::List operation:


void List<T>::Reverse ()
{
typename List<T>::Link * link, * temp;
// reverse links between head and tail
link = head_->next_;
while (link != tail_)
{
temp = link->prev_;
link->prev_ = link->next_;
link->next_ = temp;
/* MISSING LINE OF CODE */
}

// swap head and tail


temp = head_;
head_ = tail_;
tail_ = temp;
tail_->prev_ = tail_->next_;
tail_->next_ = 0;
head_->next_ = head_->prev_;
head_->prev_ = 0;

Select the missing line of code from the choices below.


Answer

Selected Answer:

link = link->next_;

Correct Answer:

link = link->prev_;

Question 18
5 out of 5 points

Declare an fsu::Queue object q with elements of type fsu::String and underlying


container fsu::List.
Answer

Selected
Answer:

fsu::Queue < fsu::String , List < fsu::String > > q;

Correct
Answer:

fsu::Queue < fsu::String , List < fsu::String > > q;

Question 19
0 out of 5 points

This is an illustration of a vector of characters to be used in answering the question:


element: B D F F F H K K W Y
index:
0 1 2 3 4 5 6 7 8 9
What is the return value of the call lower_bound('K') ?
Answer
Selected Answer:

7
Correct Answer:

Question 20
5 out of 5 points

Inserting an element in a vector of size n (not at the end) has


asymptotic runtime (select the best answer)
Answer
Selected Answer:

O(n)
Correct Answer:

O(n)

Question 21
0 out of 5 points

This is an illustration of a vector of characters to be used in answering the question:


element: B D F F F H K K M X
index:
0 1 2 3 4 5 6 7 8 9
What is the return value of the call lower_bound('Y') ?
Answer

Selected Answer:

8
Correct Answer:

10

Question 22
5 out of 5 points

Searching a list whose elements are in sorted order using an algorithm


of your choice has what asymptotic runtime? (n is the size of the list.)
Answer
Selected Answer:

O(n)
Correct Answer:

O(n)

Question 23
5 out of 5 points

This is an illustration of a vector of characters to be used in answering the question:


element: B D F F F H K K W Y
index:
0 1 2 3 4 5 6 7 8 9
What is the return value of the call upper_bound('K') ?
Answer
Selected Answer:

8
Correct Answer:

Question 24
5 out of 5 points

Select the answer that best describes the asymptotic runtime of the operation
fsu::Vector<T>:: bracket operator [i]
Here i is an item of type size_t and n is the size of the vector.
Answer
Selected Answer:

O(1)
Correct Answer:

O(1)

Question 25
5 out of 5 points

Suppose the fsu::Deque<> d has elements in sorted order and we


wish to insert the element x in correct order in d. The following generic

algorithm call returns an iterator to the last correct location to insert x:


Answer

Selected
Answer:

i = fsu::g_upper_bound(d.Begin(), d.End(), x);

Correct Answer:

i = fsu::g_upper_bound(d.Begin(), d.End(), x);

Question 26
5 out of 5 points

Select the answer that best describes the asymptotic runtime of the operation
fsu::Vector<T>:: Destructor
Here n is the size of the vector.
Answer

Selected Answer:

(n)
Correct Answer:

(n)

Question 27
0 out of 5 points

Using a data stack to evaluate the postfix expression


1 2 3 + 4 5 + * 6 + +
what is the best representation of the stack during the evaluation?
Answer
Selected Answer:

stack -->
--------1
1 2
1 2 3
1 2 3 5
1 2 3 5 4
1 2 3 5 4
1 2 3 5 4
1 2 3 5 4
1 2 3 5 4
1 2 3 5 4
1 2 3 5 4
Correct Answer:

stack -->
--------1
1 2
1 2 3
1 5
1 5 4
1 5 4 5

5
5
5
5
5
5

6
6
6
6
6

11
11 44
11 44 49
11 44 49 50

1 5 9
1 45
1 45 6
1 51
52

Question 28
0 out of 5 points

Select the answer that best describes the asymptotic runtime of the operation
fsu::List<T>::Remove(t)
Here t is an item of type fsu::List::ValueType and n is the size of the list.
Answer
Selected Answer:

O(n)
Correct Answer:

(n)

Question 29
5 out of 5 points

Write a traversal loop for an fsu::RingBuffer object b using


the fsu::RingBufferIterator object i
Answer

Selected
Answer:
Correct
Answer:

for (i = b.Begin(); i != b.End(); ++i) { /* whatever */ }


for (i = b.Begin(); i != b.End(); ++i) { /* whatever */ }

Question 30
0 out of 5 points

The following represents output from the call d.Dump() from


the fsu::Deque<char> object d:
content_[i]: A B C D E F G H I J
i mod 10: 0 1 2 3 4 5 6 7 8 9
e
b
What is the result of the output statement
std::cout << d[5];
?
Answer
Selected Answer:

F
Correct Answer:

Question 31
5 out of 5 points

Given the code:


typedef KeyType
String;
typedef DataType
int;
AssociativeArray < KeyType, DataType > aa;
std::cout << aa["xyz"]; // (1)
aa["xyz"] = 20;
// (2)
std::cout << aa["xyz"]; // (3)

The key "xyz" is inserted into the table at line (2).


Answer
Selected Answer:

False

Correct Answer:

False

Question 32
0 out of 5 points

Suppose that table is a container that implements the Table API.


If kval is NOT a key table,
then table.Insert(kval,dval) inserts kval into the table associated with
data dval.
Answer

Selected Answer:

False

Correct Answer:

True

Question 33
5 out of 5 points

Given the code fragment:


typedef KeyType
String;
typedef DataType
int;
AssociativeArray < KeyType, DataType > aa;
aa["xxx"] = 1;
aa["yyy"] = 2;
aa["xxx"] = 3;
Display(aa);

The result to screen should be


xxx : 3
yyy : 2
Answer
Selected Answer:

True

Correct Answer:

True

Question 34
5 out of 5 points

Suppose that table is a container that implements the Table API.


If the key kval is not in the table, the
call table.Retrieve(kval,dval) returns false.
Answer

Selected Answer:

True

Correct Answer:

True

Question 35
5 out of 5 points

A function to display the contents of an associative array could be implemented


efficiently as follows:
Display(const AssociativeArray& aa)

AssociativeArray::KeyType::Iterator i;
for (i = KeyType::Begin(); i != KeyType::End(); ++i)
std::cout << i << " : " << aa[i] << '\n';

Answer
Selected Answer:

False

Correct Answer:

False

Question 36
5 out of 5 points

Given the code fragment:


typedef KeyType
String;
typedef DataType
int;
AssociativeArray < KeyType, DataType > aa;
aa["xxx"] = 1;
aa["yyy"] = 2;
aa["xxx"] = 3;
Display(aa);

The result to screen should be


xxx : 1
yyy : 2
xxx : 3
Answer
Selected Answer:

False

Correct Answer:

False

Question 37
5 out of 5 points

A function to display the contents of an associative array could be implemented


efficiently as follows:
Display(const AssociativeArray& aa)

AssociativeArray::Iterator i;
for (i = aa.Begin(); i != aa.End(); ++i)
std::cout << *i.key_ << " : " << *i.data_ << '\n';

Answer
Selected Answer:

True

Correct Answer:

True

Question 38
5 out of 5 points

Suppose that table is a container that implements the Table API.


If kval is a key in the table, then table.Retrieve(kval,dval) overwrites
the data associated with kval with dval.
Answer
Selected Answer:

False

Correct Answer:

False

Question 39
5 out of 5 points

Suppose that table is a container that implements the Table API.


If kval is a key in the table, the
call table.Retrieve(kval,dval) sets dval to be a reference to the data
stored with kval in the table and returns 1.
Answer

Selected Answer:

True

Correct Answer:

True

Question 40
0 out of 5 points

Suppose that table is a container that implements the Table API.


table.Insert(kval,dval)

increases table.Size() by one.

Answer
Selected Answer:

True

Correct Answer:

False

Sunday, February 16, 2014 12:27:30 PM EST


OK

You might also like