What is the main difference between ARRAY and STACK?

Data Structure >   Stack Data Structure >   Stack Data Structure Introduction  

Short Question

872


Answer:

Stack follows LIFO. Thus the item that is first entered would be the last removed. In array the items can be entered or removed in any order. Basically each member access is done using index and no strict order is to be followed here to remove a particular element .Array may be multi-dimensional or one dimensional but stack should be one-dimensional. Size of array is fixed, while stack can be grow or shrink. We can say stack is dynamic data structure.

Here are the main differences between arrays and stacks:

Array Stack
A collection of elements of the same data type A collection of elements of the same data type
Has a fixed size, determined at declaration Has a dynamic size that grows and shrinks as elements are pushed and popped
Elements are stored sequentially in contiguous memory locations Elements are stored in a LIFO (last-in, first-out) order
Elements can be accessed directly by their index Elements can only be accessed at the top of the stack
Can be used to implement other data structures such as queues and hash tables Typically used as a data structure itself for applications such as undo/redo functionality or recursion

In summary, arrays have a fixed size and allow for direct element access, while stacks have a dynamic size and prioritize the most recently added element for access.


This Particular section is dedicated to Question & Answer only. If you want learn more about Data Structure. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.