Array-Based Queues vs List-Based Queues
Queues:
- A queue is a linear data structure in which elements are inserted from one end called the rear end and deleted from another end called the front end.
- It follows FIFO (First In First Out) technique.
- Insertion in the queue is called enqueue and deletion in the queue is called dequeue.
- Queues can be implemented in two ways: Array-based queues and list-based queues.
Array-based queues and List-based queues:
In array-based queues are implemented using the arrays. In list-based queues are implemented using a linked list.
Array-Based vs List-Based Queues:
Sno. |
Array-Based Queues |
List-Based Queues |
---|---|---|
1. | The size of the queue should be known in advance. | It’s not necessary to know the size of the queue in advance. |
2. | Insertion at the end is easier but insertion at the beginning is difficult. | Insertion at both end and beginning is easy. |
3. | Elements can be accessed randomly. | Elements can be accessed sequentially only. |
4. | Resizing array-based queues is complex. | Resizing list-based queues is simple. |
5. | Requires less memory. | Requires more memory. |
6. | It is faster compared to list-based queues. | It is slower compared to array-based queues. |
Advantages of array-based queues:
- It is faster compared to a list-based queue.
- Elements can be accessed randomly.
- It requires less memory.
Disadvantages of array-based queues:
- The size of the queue should be known in advance.
- Resizing array-based queues is complex.
- Insertion at the beginning is difficult.
Advantages of list-based queues:
- Insertion at both end and beginning is easy.
- It’s not necessary to know the size of the queue in advance.
- Resizing is simple.
Disadvantages of list-based queues:
- It requires more memory.
- It is slower as compared to array-based queues.
- Elements can be accessed sequentially only.
Conditions when to use each of these:
Array-based queues are used when we have to access elements randomly and with less memory. List-based queues are used when there are a greater number of enqueue and dequeue operations and the size of the queue is not known in advance.
Please Login to comment...