2.
A STACK data structure is also called
Explanation
The correct answer is LIFO, which stands for Last In, First Out. This means that the last element added to the stack will be the first one to be removed. In a stack, elements are added and removed from only one end, known as the top of the stack. This behavior is similar to a stack of plates, where you can only add or remove plates from the top. Therefore, LIFO accurately describes the behavior of a stack data structure.
3.
HOW TO CREATE AN EMPTY STACK
Correct Answer
A. STACK = [ ]
Explanation
The correct answer is "STACK = [ ]" because in programming, an empty stack is usually represented by an empty list. By assigning an empty list to the variable STACK, we are creating an empty stack. This allows us to add elements to the stack using the push operation and remove elements from the stack using the pop operation.
4.
In stack, Insertion and deletion take place at________
Correct Answer
top
Explanation
In a stack, insertion and deletion operations always occur at the top. This is because a stack follows the LIFO (Last In, First Out) principle, meaning that the last element added to the stack is the first one to be removed. By inserting or deleting at the top of the stack, we maintain this order and ensure that the most recently added element is always accessible.
5.
Which function is used to delete an element from a queue________
Correct Answer
pop
Explanation
The function "pop" is used to delete an element from a queue. It removes the element at the front of the queue, reducing the size of the queue by one. This function is commonly used in queue data structures to implement the First-In-First-Out (FIFO) behavior, where the element that has been in the queue the longest is the first one to be removed.
6.
Which list function is used to add a new element to the stack?
Correct Answer
append
Explanation
The append function is used to add a new element to the stack. This function takes an element as input and adds it to the end of the list, effectively extending the stack by one element. By using the append function, we can easily add new elements to the stack and maintain the order of the stack.
7.
In a queue, an element is inserted at ________ end
Correct Answer
rear
Explanation
In a queue, elements are inserted at the rear end. This is because a queue follows the FIFO (First-In-First-Out) principle, where the element that is inserted first will be the first one to be removed. By inserting elements at the rear end, we ensure that the oldest element is always at the front and will be the next one to be processed or removed from the queue.
8.
In a queue, an element is deleted from ________ side
Correct Answer
front
Explanation
In a queue, elements are added at one end and removed from the other end. The end from which elements are removed is called the "front" of the queue. Therefore, the correct answer is "front".
9.
Which method in python is used to implement stack and queue
Correct Answer
list
Explanation
The list method in Python is used to implement both stack and queue data structures. Lists are mutable and can be easily modified by adding or removing elements. To implement a stack, the append() method can be used to add elements to the end of the list, while the pop() method can be used to remove elements from the end of the list. To implement a queue, the append() method can be used to add elements to the end of the list, and the pop(0) method can be used to remove elements from the beginning of the list.
10.
Two major operations in a stack are ________ and ________
Correct Answer
push
pop
Explanation
In a stack, two major operations are "push" and "pop". The "push" operation adds an element to the top of the stack, while the "pop" operation removes the topmost element from the stack. These operations are fundamental to the functioning of a stack data structure. When an element is pushed onto the stack, it becomes the new top element, and when an element is popped from the stack, the element below it becomes the new top element. This allows for last-in-first-out (LIFO) behavior, where the most recently added element is the first one to be removed.
11.
A datastructure has well defined________,________and________
Correct Answer
operations
behaviour
properties
Explanation
A data structure is a way of organizing and storing data in a computer's memory. It has well-defined operations, which are the actions that can be performed on the data structure, such as inserting, deleting, or searching for elements. The data structure also has well-defined behavior, which refers to how it behaves when these operations are performed on it. Lastly, the data structure has properties, which are characteristics or attributes that describe its features, such as its size, efficiency, or ordering of elements.
12.
FIRST ELEMENT IN THE STACK WILL BE________
Correct Answer
stack [0]
Explanation
The given answer, "stack [0]", suggests that the first element in the stack will be the element at index 0. In a stack data structure, elements are added and removed from the top, so the first element added will be at the top of the stack. Therefore, in this case, the first element in the stack will be the element at index 0.