Print Clearly !!: Quiz #5 CS 153
Print Clearly !!: Quiz #5 CS 153
CS 153
name _______________________
print clearly !!
Show All Work
Be Neat (I have little tolerance for slppiness slupiness sloppiness )
Be Literate
25 pts.
1. The circular array implementation of a queue (not a priority queue) that was discussed in class requires what worstcase running time for the pop (or dequeue) operation? (Assume n is the number of items in the queue.)
[5]
a. O(n2)
b. O(n)
c. O(log n)
d. O(1)
*
2. If a queue (not a priority queue) is implemented with a pointer-based linked or (doubly linked) list, with the push
operation done with insertTailNode, then the pop (or dequeue) operation should be done by calling:
[5]
e. removeHeadNode
*
f. removeTailNode
g. the queue destructor
h. getTailPtr
i. setTailPtr
j. another student who has already passed cs 153 with an A
3. Suppose that a QUEUE is implemented with a circular array of size 3. Show the contents of the queues data array
and the value of the integer front member variable after the code below is executed.
[5]
QUEUE q;
q.enqueue(20);
q.enqueue(30);
q.enqueue(40);
q.dequeue( );
q.enqueue(60);
q[0] is 60
q[1] is 30
q[2] is 40
4. Write C++ code for a recursive function (NO LOOPS!) which does the following: Given an integer parameter n (n 0),
return 2 n. You may not use the C++ pow function.
[10]