Skip to content

Latest commit

 

History

History

Stack

Stack

Stack is a linear data structure that follows a particular order in which the operations are performed. It works on the principle of LIFO(Last In First Out).

# Question Time Complexity
1 Implementation using Array
2 Valid Parenthesis O(N)
3 Reverse String O(N)
4 Implement 2 Stacks in Array O(N)
5 getMin() in O(1) time and O(1) extra space O(1)
6 Next Greater Element O(N)
7 The Celebrity Problem O(N)

Algorithm for push:

begin
 if stack is full
    return
 endif
else  
 increment top
 stack[top] assign value
end else
end procedure

Algorithm for pop:

begin
 if stack is empty
    return
 endif
else
 store value of stack[top]
 decrement top
 return value
end else
end procedure