際際滷

際際滷Share a Scribd company logo
DATA STRUCTURE
D AY 3
BY : M O H A M M E D E L S D O D Y
STACK
Stack is a linear data structure which follows a particular order in which the operations
are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).
Mainly the following three basic operations are performed in the stack:
 Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow
condition.
 Pop: Removes an item from the stack. The items are popped in the reversed order in
which they are pushed. If the stack is empty, then it is said to be an Underflow
condition.
 Peek or Top: Returns top element of stack.
 isEmpty: Returns true if stack is empty, else false.
STACK
STACK
Time Complexities of operations on stack:
push(), pop(), isEmpty() and peek() all take O(1) time. We do not run any loop in any of
these operations.
APPLICATIONS OF STACK:
 Balancing of symbols.
 Infix to Postfix /Prefix conversion .
 Redo-undo features at many places like editors, photoshop.
 Forward and backward feature in web browsers.
 Used in many algorithms like Tower of Hanoi, tree traversals, stock span
problem, histogram problem.
 Other applications can be Backtracking, Knight tour problem, rat in a maze, N queen
problem and sudoku solver.
 In Graph Algorithms like Topological Sorting and Strongly Connected Components.
IMPLEMENTATION
There are two ways to implement a stack:
 Using array
 Using linked list

More Related Content

Data structure day3

  • 1. DATA STRUCTURE D AY 3 BY : M O H A M M E D E L S D O D Y
  • 2. STACK Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). Mainly the following three basic operations are performed in the stack: Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow condition. Pop: Removes an item from the stack. The items are popped in the reversed order in which they are pushed. If the stack is empty, then it is said to be an Underflow condition. Peek or Top: Returns top element of stack. isEmpty: Returns true if stack is empty, else false.
  • 4. STACK Time Complexities of operations on stack: push(), pop(), isEmpty() and peek() all take O(1) time. We do not run any loop in any of these operations.
  • 5. APPLICATIONS OF STACK: Balancing of symbols. Infix to Postfix /Prefix conversion . Redo-undo features at many places like editors, photoshop. Forward and backward feature in web browsers. Used in many algorithms like Tower of Hanoi, tree traversals, stock span problem, histogram problem. Other applications can be Backtracking, Knight tour problem, rat in a maze, N queen problem and sudoku solver. In Graph Algorithms like Topological Sorting and Strongly Connected Components.
  • 6. IMPLEMENTATION There are two ways to implement a stack: Using array Using linked list