COP 4530 Fall 2004: Assignment 3
Assignments should be submitted as described in HWinstructions.html (for written assignments). Due: 12 Oct 2004, by 5 pm.
You must justify all your answers.
- Show the state of a self-organizing (by the count method) linked list after the following sequence of operations (show the links and counts too): push_back(A); push_back(B); push_back(C); push_back(D); search(D); search(D); search(C);.
- Show the state of a deque, with initial capacity 4, after the following sequence of operations: push_back(A); push_back(B); push_front(C); push_front(D).
- Show the state of a stack after the following sequence of operations: push(A); push(B); pop(); push(C); push(D); pop();.
- Show the state of a queue after the following sequence of operations: push(A); push(B); pop(); push(C); push(D); pop();.
- Complete the implementation of the following function so that it reverses the contents of Q. For example, if Q stored
a b c
at the beginning, then it will store c b a
when the function returns. You may use features of STL stacks and queues.
void reverse(queue<char> &Q){
stack<char> S;
... (write code)
}
- Chapter 2, exercise 11. Give the constant that goes with the highest order term too.
- Derive the amortized cost of
n
insertions into a vector, if the capacity of the vector were made three time the current capacity, whenever an insertion would cause the current capacity to be exceeded. Assume that the initial capacity is 1
.
- Assume that you want to store the records of customers at a hotel in a self organizing linked list. What type of self-organization will you choose? You need to mention assumptions you make regarding operations that will be performed, such as inserting a reservation, canceling a reservation, etc, and their relative frequencies. Mention any other assumptions you make, and give justifications for your decision. You must give a final decision; your answer cannot be of the form "if
a
is true, then I will choose x
, and if b
is true, then I will choose y
". You need not restrict yourself to only the types of lists we have discussed in class. However, please mention a precise criterion for the self-organization; it should be sufficiently precise that someone else can code it, given your description.
Last modified: 4 Oct 2004