What is a Stack ?

1 : A stack is a linear data structure which can be represented by a real physical stack or pile.

2 : Insertion and deletion of element takes place at one end called top of the stack.

3 : Stack works on the principle of LIFO(last in first out) which means the element which is inserted last can be   deleted first.

Figure :



Basic Operations in Stack :

Operation Description Complexity
push(Object obj)  adds one element to the stack O(1)
pop()  deletes one(last inserted) element from the stack O(1)
top()  returns the last pushed element in the stack O(1)
size()  returns total  elements present in the stack O(1)
isEmpty()  checks if stack is empty O(1)
isFull()  checks if stack is full O(1)

Program class For  basic operation in Stack:

Problems :

1 : Check for balanced parentheses in an expression
2 : Next Greater Element in an array
3 : Special Stack Data Structure which returns minimum and maximum element in O(1) time complexity.
4 : Design a queue using stacks

Leave a comment

Your email address will not be published. Required fields are marked *

4 × 4 =