You are on page 1of 1

Tutorial 4

1. Suppose each data structure is stored in a cicular array with N memory cells.
a) Find the number NUMB of elements in a queue in terms of FRONT and
REAR.
b) Find the number NUMB of elements in a deque in terms of LEFT and RIGHT.
c) When will the array be filled?

2. Consider a deque maintained by a circular array with N memory cells.


a) Suppose an element is added to the queue. How is LEFT and RIGHT changed.
b) Suppose an element is deleted. How is LEFT and RIGHT changed?
3. Consider the priority queue which is maintained by a two dimensional array QUEUE.

1 2 3 4 5 6

1 AAA

2 BBB CCC XXX

4 FFF DDD EEE

5 GGG
a) Describe the structure after(RRR,3),(SSS,4),(TTT,1),(UUU,4) and (VVV,2 ) are
added to the queue.
b) Describe the structure if, after the preceding insertions, three elements are
deleted.

4. Given an integer k and a queue of integers, write an algorithm to reverse the order of
the first k elements of the queue, leaving the other elements in the same relative order.
Explain the algorithm by taking an example

5. Given a queue of integers of even length, write an algorithm to rearrange the elements
by interleaving the first half of the queue with the second half of the queue.[Note:
Only a stack can be used as an auxiliary space.]
Examples:
Input : 1 2 3 4
Output : 1 3 2 4

Input : 11 12 13 14 15 16 17 18 19 20
Output : 11 16 12 17 13 18 14 19 15 20

Explain the algorithm by taking an example.

You might also like