ExT1 StacksQueues
ExT1 StacksQueues
[1]
Data Structures
Queues:
(1) Define an ADT to support the operations enqueue, dequeue and onqueue. onqueue(x) is a
function returning true or false depending on whether x is on the queue. Write also onqueue
and compute its running time.
(2) Rewrite the makenull operation of the queue ADT so that any element existing on the queue is
conveniently disposed. Dequeue operation can be reused. What is the running time of the
new makenull operation.
(3) Extend the ADT queue to include the following operations:
o last that will return the rear element of the queue (which shall not be deleted from the
queue)
o length that will return the number of elements on the queue.
o enqueueN that will enqueue an array of N elements on the queue
o dequeueN that will dequeue and return an array of N elements from the queue
Write an implementation for each operation and compute their running time.
(4) Extend the ADT queue to include an operation called searchqueue that searches for an item on
the queue and returns its position. Write a program for the new function and compute its
running time.
(5) Extend the specification of queue to include a function called extractfromqueue that searches
and returns an element e from a queue. Implement that function. Any other element must
remain on the queue respecting their order. Consider the case in which the element is not
found. Provide also an implementation based on the standard queue operations. Estimate the
running time of each version to determine the best option.
(6) Provide a pointer implementation of a queue that does not kept a reference to the rear
element (i.e. that does not have any pointer to the rear element). Compare the running time
of each operation with the standard implementation.
(7) Implement the ADT that provides a circular implementation of a queue. Extend the queue ADT
to include a function that returns the number of elements on the queue. Implement such a
function.
(8) Another linked-list implementation of queues is to use a dummy cell. A dummy cell is an
empty cell that always is in the first position of the queue. If the queue is empty then front and
rear point to the dummy cell. Implement the queue operations for this representation. How
does this implementation compare with the list implementation given in class in terms of
speed (running time) and space utilization?
(9) A dqueue (doubled-ended queue) is a list from which elements can be inserted or deleted at
either end. Present a specification for the dqueue ADT and develop array as well as pointer
implementations of it.
[2]