InterviewSolution
| 1. |
What Type Of Operation Can Be Performed Using Stack And Queue In Data Structure ? |
|
Answer» Organization of data in the computer can be done with the help of data structure so that data can be accessed easily and efficiently. There are different types of data structure used in computer, and two of them are Stack and Queue data Structure. Stack: A stack is a type of linear-data structure, which logically represents and arrange the data in the form of a stack. As a real-LIFE example of a stack is "plates arranged in the form of the stack." In a stack structure, any operation can be PERFORMED on data items from one end only. A Stack structure follows a particular order for operation on data items, and that order can be LIFO (Last in First Out) or FILO (First in Last Out). A stack can be represented in the form of an array. Types of Operations performed on Stack: 1. Push: Push is an operation that can be performed, to add an element in the stack. As in the above diagram, the top element was 93 (before addition of a new element), and after performing PUSH operation, a top element is 10. Now pointer will point at the top of the stack. 2. Pop: If we try to remove or delete an element from the Stack, then it is called as Pop operation. As in the above diagram, if we want to delete an element from the top of the Stack, then it can be done by the Pop operation. 3. isEmpty: If we wanted to check whether the stack is empty or not, then we can perform an isEmpty operation. It will return three values: If we will perform a Pop operation on empty Stack, then it is called underflow condition. Empty -1 Single element present 0 Stack is full N-1 Stack overflow N 4. Peek or Top: If we perform Peek operation it CHECKS all the elements of the stack and returns the top element. Queue: A Queue is an ordered collection of data elements same as a stack, but it enables INSERTION operation from one end called as REAR end and deletion operation from other end called as a FRONT end. A Queue structure follows an order of FIFO (First in First Out) for insertion and deletion of the data element. Real life example of a queue is people waiting to buy a movie ticket in a line. Types of Operations performed on Stack: The two main operations which can be performed On Stack are Enqueue and Dequeue. Enqueue: This operation is performed to add an element in the queue at the rear end. After adding an element in a queue, the count of Rear pointer increased by 1. Below is the Array representation of queue with Enqueue operation. Dequeue: This operation is performed to remove an element from the queue at the front end. After removing an element from the queue, the count of Front pointer gets decremented by 1. Below is the diagram which shows the removal of the data element from a queue. Other operations performed on the queue are: Peek: This operation is used to get all the data elements of queue without deletion of an element, at the front end. Isfull: This operation is performed to check whether a queue is full or not. Isempty: This operation is performed to check whether a queue is empty or not. Organization of data in the computer can be done with the help of data structure so that data can be accessed easily and efficiently. There are different types of data structure used in computer, and two of them are Stack and Queue data Structure. Stack: A stack is a type of linear-data structure, which logically represents and arrange the data in the form of a stack. As a real-life example of a stack is "plates arranged in the form of the stack." In a stack structure, any operation can be performed on data items from one end only. A Stack structure follows a particular order for operation on data items, and that order can be LIFO (Last in First Out) or FILO (First in Last Out). A stack can be represented in the form of an array. Types of Operations performed on Stack: 1. Push: Push is an operation that can be performed, to add an element in the stack. As in the above diagram, the top element was 93 (before addition of a new element), and after performing PUSH operation, a top element is 10. Now pointer will point at the top of the stack. 2. Pop: If we try to remove or delete an element from the Stack, then it is called as Pop operation. As in the above diagram, if we want to delete an element from the top of the Stack, then it can be done by the Pop operation. 3. isEmpty: If we wanted to check whether the stack is empty or not, then we can perform an isEmpty operation. It will return three values: If we will perform a Pop operation on empty Stack, then it is called underflow condition. Empty -1 Single element present 0 Stack is full N-1 Stack overflow N 4. Peek or Top: If we perform Peek operation it checks all the elements of the stack and returns the top element. Queue: A Queue is an ordered collection of data elements same as a stack, but it enables insertion operation from one end called as REAR end and deletion operation from other end called as a FRONT end. A Queue structure follows an order of FIFO (First in First Out) for insertion and deletion of the data element. Real life example of a queue is people waiting to buy a movie ticket in a line. Types of Operations performed on Stack: The two main operations which can be performed On Stack are Enqueue and Dequeue. Enqueue: This operation is performed to add an element in the queue at the rear end. After adding an element in a queue, the count of Rear pointer increased by 1. Below is the Array representation of queue with Enqueue operation. Dequeue: This operation is performed to remove an element from the queue at the front end. After removing an element from the queue, the count of Front pointer gets decremented by 1. Below is the diagram which shows the removal of the data element from a queue. Other operations performed on the queue are: Peek: This operation is used to get all the data elements of queue without deletion of an element, at the front end. Isfull: This operation is performed to check whether a queue is full or not. Isempty: This operation is performed to check whether a queue is empty or not. |
|