# Stacks

Approved & Edited by ProProfs Editorial Team
At ProProfs Quizzes, our dedicated in-house team of experts takes pride in their work. With a sharp eye for detail, they meticulously review each quiz. This ensures that every quiz, taken by over 100 million users, meets our standards of accuracy, clarity, and engagement.
| Written by Seventyfive
S
Seventyfive
Community Contributor
Quizzes Created: 3 | Total Attempts: 20,448
Questions: 15 | Attempts: 2,394  Settings  • 1.

### A stack is a data structure that implements movement of data in which format?

• A.

First in first out

• B.

Last in first out

• C.

Random access

B. Last in first out
Explanation
A stack is a data structure that implements the "Last in first out" (LIFO) movement of data. This means that the last element that is added to the stack will be the first one to be removed. It follows a principle similar to a stack of plates, where you can only access the topmost plate and remove it before accessing the ones below. In a stack, elements are added and removed from the same end, known as the top of the stack. This makes it useful for applications like function calls, undo operations, and expression evaluation.

Rate this question:

• 2.

### What are the basic operations performed on a stack?

• A.

Push, pop, and peek

• B.

InsertAt, removeAt, peekAt

• C.

None of the above

A. Push, pop, and peek
Explanation
The basic operations performed on a stack are push, pop, and peek. "Push" is used to add an element to the top of the stack, "pop" is used to remove the top element from the stack, and "peek" is used to view the top element without removing it. These operations are fundamental in manipulating and accessing data in a stack structure.

Rate this question:

• 3.

### The initializeStack() operation can only be performed when?

• A.

Before the stack is used, and never after

• B.

Before the stack is used, and any time the stack is empty

• C.

Any time

C. Any time
Explanation
The initializeStack() operation can be performed at any time. It is not limited to a specific condition or state of the stack. This means that the operation can be executed before the stack is used, after the stack is used, or even when the stack is empty. There are no restrictions on when the initializeStack() operation can be performed.

Rate this question:

• 4.

### The initializeStack() operation will always preserve any data stored in the stack before initializing it?

• A.

True

• B.

False

B. False
Explanation
The initializeStack() operation does not preserve any data stored in the stack before initializing it. When this operation is called, it resets the stack to its initial state, removing any previously stored data. Therefore, the correct answer is False.

Rate this question:

• 5.

### Stacks can only be implemented using a linked list?

• A.

True

• B.

False

B. False
Explanation
Stacks can be implemented using various data structures, including arrays and linked lists. While linked lists are a common choice for implementing stacks due to their dynamic nature and efficient insertion and deletion operations, it is not the only option. Arrays can also be used to implement stacks by dynamically resizing the array when needed. Therefore, the statement that "Stacks can only be implemented using a linked list" is false.

Rate this question:

• 6.

### What approaches are generally used for implementing a stack data structure?

• A.

Stacks can only be implemented with a generic class

• B.

Stacks are implemented using either an array or a linked list

• C.

Stacks can only be implemented using the operating system resources for a stack

B. Stacks are implemented using either an array or a linked list
Explanation
Stacks can be implemented using either an array or a linked list. In the array implementation, a fixed-size array is used to store the elements of the stack, and a pointer keeps track of the top element. In the linked list implementation, each element of the stack is represented by a node, and each node contains a reference to the next node. Both approaches allow for efficient push and pop operations, but the choice between them depends on the specific requirements and constraints of the problem at hand.

Rate this question:

• 7.

### What generally happens when the pop operation is performed on an empty stack?

• A.

The null reference is returned

• B.

The StackUnderflowException is thrown

• C.

None of the above

B. The StackUnderflowException is thrown
Explanation
When the pop operation is performed on an empty stack, it means that there are no elements in the stack to remove. In such a scenario, throwing a StackUnderflowException is a common practice. This exception indicates that the stack is empty and there is no element to be popped. Therefore, the correct answer is "The StackUnderflowException is thrown."

Rate this question:

• 8.

### What is the basic tasks performed by the constructor of an array based stack?

• A.

Initialize the stack size; set the stack to empty; create the array

• B.

Nothing since the push operation will initialize the array if needed

• C.

Create a default node for the head of the stack

A. Initialize the stack size; set the stack to empty; create the array
Explanation
The constructor of an array-based stack performs the basic tasks of initializing the stack size, setting the stack to empty, and creating the array. These tasks are necessary to ensure that the stack is properly initialized and ready for use. By initializing the stack size, the constructor determines the maximum number of elements that the stack can hold. Setting the stack to empty means that there are no elements currently in the stack. Creating the array involves allocating memory for the array that will be used to store the elements of the stack.

Rate this question:

• 9.

### What generally happens when the push operation is performed on an array based stack that is full?

• A.

Deletes the first item in the stack to make room for the new item

• B.

Throws the StackOverflowException

• C.

None of the above

B. Throws the StackOverflowException
Explanation
When the push operation is performed on an array-based stack that is full, it throws the StackOverflowException. This exception is thrown because the stack is already full and there is no more space to add a new item. The StackOverflowException is a type of exception that occurs when the stack's capacity has been exceeded, preventing any further push operations.

Rate this question:

• 10.

### The benefit of a linked list based stack over an array based one is what?

• A.

There are no benefits, just coded differently

• B.

The linked list stack must use generic classes to work

• C.

The linked list stack does not have a fixed size

C. The linked list stack does not have a fixed size
Explanation
The benefit of a linked list based stack over an array based one is that the linked list stack does not have a fixed size. Unlike an array, a linked list can dynamically grow or shrink as elements are added or removed from the stack. This flexibility allows for efficient memory management and eliminates the need to pre-allocate a fixed amount of memory for the stack.

Rate this question:

• 11.

### The stackTop instance variable is used in both array and linked list stacks. What is the difference in each?

• A.

Both uses point to the head node

• B.

The array uses it as an index and the linked list uses it as a node pointer

• C.

None of the above

B. The array uses it as an index and the linked list uses it as a node pointer
Explanation
In an array stack, the stackTop instance variable is used as an index to keep track of the top element in the stack. It represents the position of the top element in the array.

In a linked list stack, the stackTop instance variable is used as a node pointer. It points to the head node of the linked list, which contains the top element of the stack.

Therefore, the correct answer is that the array uses the stackTop as an index, while the linked list uses it as a node pointer.

Rate this question:

• 12.

### Stacks are used to store what type of data?

• A.

Homogeneous data

• B.

Heterogeneous data

• C.

A very limited set of data types such as integers, strings

A. Homogeneous data
Explanation
Stacks are used to store homogeneous data. This means that all the elements in a stack must be of the same data type. Stacks follow the Last-In-First-Out (LIFO) principle, where the last element added to the stack is the first one to be removed. Storing homogeneous data in a stack ensures that the data can be easily managed and accessed in a consistent manner, as all the elements have the same structure and properties.

Rate this question:

• 13.

### The followng code is most likely found in which method of the linked list stack? return (stackTop == null);

• A.

In the pop() method

• B.

In the isEmptyStack() method

• C.

In the isFullStack() method

B. In the isEmptyStack() method
Explanation
The given code snippet checks if the stack is empty by evaluating if the stackTop pointer is null. If the stackTop is null, it means that the stack is empty, and the method returns true. Therefore, the code is most likely found in the isEmptyStack() method, which is responsible for checking if the stack is empty or not.

Rate this question:

• 14.

### The peek() method of the linked list stack must first check for what condition?

• A.

A full stack

• B.

An empty stack

• C.

None of the above

B. An empty stack
Explanation
The peek() method of the linked list stack must first check for an empty stack. This is because the peek() method is used to retrieve the top element of the stack without removing it. If the stack is empty, there are no elements to retrieve, so the method should return an appropriate indication, such as null or throwing an exception. Therefore, the peek() method needs to check if the stack is empty before attempting to retrieve the top element.

Rate this question:

• 15.

### The following code is most likely found in which method of a linked list stack? first = first.link;

• A.

The peek() method

• B.

The push() method

• C.

The pop() method Back to top