Problems on Queues - Computer Science I | COP 3502, Assignments of Computer Science

Material Type: Assignment; Class: Computer Science I; Subject: Computer Programming; University: University of Central Florida; Term: Spring 2005;

Typology: Assignments

Pre 2010

Uploaded on 11/08/2009

koofers-user-gz6
koofers-user-gz6 🇺🇸

8 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Problems on Queues
1) Given a queue of size 10 find out how many elements are there in the queue when
the indices front and rear have the following values?
For your understanding you can draw a queue of size and mark the front and rear
indices to verify that the following solutions are correct.
front = 0 and rear =2
This shows that first 3 slots are occupied.
front = 0 and rear =9
This shows all the 10 slots are occupied.
front =4 and rear =4
Since front=rear and not equal to -1, it means that there is only one slot is occupied.
front = 6 and rear = 5
Since front =rear + 1, it means that the queue is full, with all slots occupied.
front = 6 and rear = 4
Now front =rear + 1 means that the queue is full, but here front = rear+ 2, it
means that still 1 slot is free. (There are 9 elements in the queue).
2) Consider a queue of size 5 . Using the concept of circular array implementation
show the contents of the queue after the following operations are carried out
Enqueue 6
Enqueue 7
Enqueue 2
X = dequeue
Enqueue 9
Y = dequeue
Enqueue 5
Enqueue 4
Enqueue 6
Z = dequeue
Enqueue Y
X = dequeue
Enqueue Z
Y = dequeue
pf2

Partial preview of the text

Download Problems on Queues - Computer Science I | COP 3502 and more Assignments Computer Science in PDF only on Docsity!

Problems on Queues

  1. Given a queue of size 10 find out how many elements are there in the queue when the indices front and rear have the following values? For your understanding you can draw a queue of size and mark the front and rear indices to verify that the following solutions are correct. front = 0 and rear = This shows that first 3 slots are occupied. front = 0 and rear = This shows all the 10 slots are occupied. front =4 and rear = Since front=rear and not equal to -1, it means that there is only one slot is occupied. front = 6 and rear = 5 Since front =rear + 1, it means that the queue is full, with all slots occupied. front = 6 and rear = 4 Now front =rear + 1 means that the queue is full, but here front = rear+ 2, it means that still 1 slot is free. (There are 9 elements in the queue).
  2. Consider a queue of size 5. Using the concept of circular array implementation show the contents of the queue after the following operations are carried out Enqueue 6 Enqueue 7 Enqueue 2 X = dequeue Enqueue 9 Y = dequeue Enqueue 5 Enqueue 4 Enqueue 6 Z = dequeue Enqueue Y X = dequeue Enqueue Z Y = dequeue

3) Consider a queue of size 12. Indicate the number of EMPTY slots when

  • a) front = -1 and rear = -
  • b) front = 0 and rear =
  • c) front = 9 and rear =
  • d) front = 3 and rear =