Wednesday 26 June 2013

what is Stack and Queue? [ simplest yet every detail]

Stack:
a list of elements where insertion (push) or deletion (pop) is and can only be done at one same end.
the bookish name of it is LIFO. stands for Last In First Out.

special terminology:

  1. push: to insert any element into the stack.
  2. pop  ; to delete any element from the stack.

example:
its like a cookie jar. Top most cookie in the jar is only accessible.

application:
the whole "UNDO" concept or the thing we do by pressing CTRL+ Z is done by stack, or like in Maze puzzles.



Queue;
linear list of elements where insertion (rear)  and deletion (front) can only be done by different ends.
bookish name of it is FIFO, stands for First In First Out. queue has head and tail.

special terminology:

  1. enqueue (rear) : to operate insertion operation.
  2. dequeue (front): to operate deletion operation.

example:
like people waiting in a line for movie tickets, new ( or last) person will stand at the end of the line every time. or like a fancy restaurant where i can enter and get out using 2 different way, and can't mess it up :P .

application:
like in BFS( breadth first search) or DFS( deapth first search).

No comments:

Post a Comment