# Data Structures: Question Set – 06

#### How do you check if a stack is empty?

You can check if a stack is empty by checking if the top element of the stack is null or by keeping track of the number of elements in the stack.

#### What is the top element of a stack?

The top element of a stack is the element that was most recently added to the stack.

#### What is a stack overflow?

A stack overflow occurs when a stack is full and a new element is pushed onto the stack. This can happen when the stack’s size is fixed, and all the elements in the stack are already occupied.

#### What is a stack underflow?

A stack underflow occurs when a pop operation is performed on an empty stack. This can happen when there are no elements in the stack, and an attempt is made to remove an element from the stack.

#### What is a stack trace?

A stack trace is a report that shows the sequence of function calls that led to an error or exception in a program. It is usually shown in reverse order, starting with the most recent function call and working backward to the original function call.

#### What is the difference between a stack and a queue?

A stack follows the Last-In-First-Out (LIFO) principle, while a queue follows the First-In-First-Out (FIFO) principle. In a stack, elements are added and removed from the top, while in a queue, elements are added to the rear and removed from the front.

#### What is a queue?

A queue is an abstract data type that follows the First-In-First-Out (FIFO) principle. It is a collection of elements with two primary operations: enqueue (to add an element to the back of the queue) and dequeue (to remove the front element from the queue).

#### What are the two primary operations performed on a queue?

The two primary operations performed on a queue are enqueue (to add an element to the back of the queue) and dequeue (to remove the front element from the queue).

#### How is a queue implemented?

A queue can be implemented using an array or a linked list. In an array implementation, the elements are stored in a contiguous block of memory, while in a linked list implementation, each element contains a reference to the next element in the list.