Overview of Stack

A stack is a data structure which stores elements one above others. Consider a pile of coins. Each coin is a data element. Addition and removal of coins take place at one end. This place is called the top of the stack. 

Image Credits:Pixelbay

A unique feature of this data structure is that we can use an array or linked list for its implementation. We are concerned about its functionality instead of it is implemented in code. Thus, the stack is an abstract data type. 

We use push operation for insertion and pop operation for deletion. 


Stack uses LIFO approach which is an acronym for, "Last in first out". The newer elements are the ones which get popped first.

There are two states which can be determined by the value of the top:

  1. Overflow- It means that the stack is full.
  2. Underflow- It means that the stack is empty.


Advantages of the stack are:

  1. Easy insertion and deletion of elements. 
  2. Provides LIFO functionality which is not given by array and linked list.


Disadvantages of the stack are:

  1. Elements cannot be randomly accessed.

Note: Advantages and disadvantages of data structure used for the implementation of the stack are reflected on the stack during program execution.


Application of stack are:

1. For checking parenthesis.

2. Evaluate arithmetic expressions.

3. For converting infix expression to postfix expression and vice versa.

4. For converting infix expression to prefix expression and vice versa.

5. Reversing a string.

6. Maintain function call order in memory.

7. Compilers use the stack to check if the syntax is correct.

8. Operating systems use the stack for memory management purposes.

8. Backtracking algorithm.

Comments

Popular posts from this blog

Overview of Tree Data Structure

Overview of Three Dimensional Array

Overview of Priority Queue