Basic CS-Data Structures [3i Infotech Placement]: Sample Questions 6 - 6 of 52

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 6

Data Structures

Describe in Detail


Describe a stack and the operations used to interact with it.


Understanding of Stack
  • Stack is a linear data structure for following a particular order in which the operations are performed.
  • The order is LIFO (Last in First Out) or FILO (First in Last Out) .

    Basic Features of Stack

  • Stack is an ordered list of similar data type.
  • Stack is a LIFO structure.
  • Push () function is used to insert new elements into the stack and pop () function is used to delete an element from the stack.
  • Both are and deletion allowed only at one end of stack called Top.

    Stack Operations

  • Push
  • Pop

Push operation:

  • Putting a new data element onto stack is known as a push operation. Steps of push operation.
    1. Check if the stack is full.
    2. If stack is full, generate an error and exit.
    3. Stack is not full, increment top to point next empty space.
    4. Add data element to the stack location, where top is pointing.
    5. Returns success.
Steps of Push Operation
  • Algorithm for PUSH Operation

    begin procedure push: stack, data

    if stack is full

    return null


    top top + 1

    stack [top] data

    end procedure

Pop Operation:

  • Accessing the content while removing it from the stack is known as a pop operation.
  • In array implementation of pop () operation, the data element is not actually removed
  • Top is decremented to a lower position in the stack to next value.
  • Pop Steps

    1. Check if the stack is empty
    2. Stack is empty, produces an error and exit.
    3. The stack is not empty, access the data element at which top is pointing.
    4. Decreases the value of pop by 1.
    5. Returns accessed element.
Graph of the Pop Operation
  • Algorithm for Pop Operation

    begin procedure pop: stack

    if stack is empty

    return null


    data stack [top]

    top top -1

    return data

    end procedure.

Application of stack:

  • Balancing of symbol
  • Infix to postfix
  • Redo-undo features at many places like editors, Photoshop.
  • Forward and backward feature in web browsers.

Developed by: