Skip to main content

Stacks & its Applications

Hi,
👋 everyone,
Here is a new important section for the programmers. Data structures. As the first step I would like to discuss about the STACKS.
Hope you have heard about stack.
When we talk about the stacks the first thing that comes to our mind is,
Isn’t it???

Yes! Stack is a kind of data structure which has only one opened end. So, you have to use this opened end when you insert or delete element. That means only the top element can accessible when you are using a stack.
  Some examples for stack,


Also we can say stack uses LIFO strategy.
That means Last In First Out…
Here is the list of operations we can done in stack.

  • push(x)      – push/insert an element x to the stack
  • pop()         – pop/delete/remove the top element from the stack
  • top()           – Returns the top most element in the stack. But it does not allow to remove it.
  • isEmpty ()  – Check whether the stack is empty or not
  • isFull()        – Check whether the stack is full or not


All above operations take constant time. So we can say O(1) is the time complexity for the all operations of the stack.
Let’s see how these operations work.



Lets check how these push and pop operations take O(1) time.

isEMpty()
Let's assume the top of the empty stack is -1


push(x)


pop()



 When you check above pseudo codes you can see there are no any loops .So all the operations gets O(1) time complexity.
OK.

Finally I would like to discuss some of the applications of stacks.
  • ·        For undo operations
  • ·        For recursive function calls
  • ·        For balance the parenthesis of a code

I hope to discuss about each applications with more details in future tutorials.
Thakyou
Bye bye….✋ 

Comments

Post a Comment