← All Lessons Lesson 3 / 26
Lesson 3

Key Properties of a Queue: Capacity, Size, Front, and Back

Key Properties of a Queue

Now that you know what a queue is and why it is useful, let's look at the parts that describe it. Think of a queue like a line of people waiting at a ticket counter. To talk about that line clearly, you need words for things like "how many people can fit," "how many are here right now," "who is next," and "who just joined." A queue has the same four key properties: capacity, size, front, and back. These values change every time you add or remove an item.

In all the examples below, picture a row of 7 slots holding the items 1 2 3 4 5 6 7, with a few empty slots still left over.

Capacity

The capacity of a queue is the *maximum* number of items it can hold — the total number of slots, whether they are filled or empty.

  • A bounded queue has a fixed capacity set in advance. Once every slot is full, you cannot add more until something is removed. (Like a parking lot with a fixed number of spaces.)
  • An unbounded queue has no preset limit. It can keep growing, and the only real limit is how much memory the computer has.

So if our queue has 7 items inside but room for a few more slots, the *capacity* is the count of all slots together — both the filled ones and the empty ones.

Size

The size of a queue is the number of items it is holding *right now*. This is different from capacity:

  • Capacity = total slots available (can it ever be full?).
  • Size = how many slots are actually used at this moment.

In our example, the items 1 2 3 4 5 6 7 are present, so the size is 7. Every time you add an item the size goes up by one, and every time you remove an item the size goes down by one. When the size equals the capacity, the queue is full. When the size is 0, the queue is empty.

Front

The front is the *oldest* item in the queue — the one that has been waiting the longest. It sits at the removing end, ahead of everyone else.

This is the item that will be taken out and processed next. In our example, item 1 was the first one to arrive, so 1 is at the front and will leave first. This matches the everyday rule of a real line: the person who has waited longest gets served first.

Back

The back is the *newest* item — the one most recently added. It sits at the opposite end from the front, behind all the other items. The back is also sometimes called the rear.

New items always join at the back. In our example, item 7 was added last, so 7 is the back of the queue. It will have to wait for everything ahead of it to leave before its own turn comes.

Putting it together

This front-and-back arrangement is the heart of a queue:

  • Items enter at the back (the newest item).
  • Items leave from the front (the oldest item).

This is exactly why a queue is called FIFO — *First In, First Out*. The first item to go in (1) is the first one to come out, just like the first person in a line is the first to be served.

Key Properties of a Queue: Capacity, Size, Front, and Back
Diagram — click to zoom (scroll / drag to pan)