An Array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value, i.e., the memory location of the first element of the array (generally denoted by the name of the array).
The diagrammatic representation of the Array is given below:
A Queue is a linear structure that follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first. The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added.
The diagrammatic representation of the Queue is given below:
A Stack is a linear data structure in which elements can be inserted and deleted only from one side of the list, called the top. A stack follows the LIFO (Last In First Out) principle, i.e., the element inserted at the last is the first element to come out. The insertion of an element into the stack is called push operation, and the deletion of an element from the stack is called pop operation. In stack, we always keep track of the last element present in the list with a pointer called top.
The diagrammatic representation of stack is given below:
Below is the tabular representation of the difference between Array, Stack, and Queue:
|Queues are based on the FIFO principle, i.e., the element inserted at the first, is the first element to come out of the list.||In the array the elements belong to indexes, i.e., if you want to get into the fourth element you have to write the variable name with its index or location within the square bracket eg arr||Stacks are based on the LIFO principle, i.e., the element inserted at the last, is the first element to come out of the list.|
|Insertion and deletion in Queues takes place only from rear and front respectively.||Insertion and deletion in array can be done at any index in the array.||Insertion and deletion in stacks take place only from one end of the list called the top.|
|Queue has a dynamic and fixed size.||Array has a fixed size.||Stack has a dynamic and fixed size.|
|Queue can contain elements of different data type.||Array contains elements of same data type.||The stack can contain elements of the different data types.|
|Different types of Queues are circular queue, priority queue, doubly ended queue||Different types of Arrays are 1D, 2D, etc||Stack has only one type.|
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Stack and Queue in Python using queue Module
- Check if a queue can be sorted into another queue using a stack
- Difference between Multilevel Queue (MLQ) and Multi Level Feedback Queue (MLFQ) CPU scheduling algorithms
- Difference between Circular Queue and Priority Queue
- Difference between Stack and Queue Data Structures
- Implement Stack and Queue using Deque
- Level order traversal in spiral form | Using one stack and one queue
- Stack Permutations (Check if an array is stack permutation of other)
- Reversing a Queue using another Queue
- Infix to Postfix using different Precedence Values for In-Stack and Out-Stack
- Implement a stack using single queue
- How to implement stack using priority queue or heap?
- Check if moves in a stack or queue are possible or not
- Difference between Stack and Array
- Stack | Set 3 (Reverse a string using stack)
- Find maximum in stack in O(1) without using additional stack
- Sort a stack using a temporary stack
- Difference between a Static Queue and a Singly Linked List
- Difference between Multi Level Queue (MLQ) Scheduling and Round Robin (RR) algorithms
- Difference between Multi Level Queue Scheduling (MLQ) and First Come First Served (FCFS)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.