Data Structure Introduction Practice Questions with Solutions

Introductions

Data structure practice is about applying concepts, not just memorizing definitions. In this chapter, you will solve beginner-friendly problems based on choosing the right data structure, tracing stack and queue operations, identifying linear and non-linear structures, and matching data structures with real programming situations. These questions gradually build problem-solving skills and prepare you for arrays, linked lists, stacks, queues, trees, graphs, and other advanced topics. Data Structure Introduction practice questions with solutions help to understand the concepts.

Question 1: Identify the Best Data Structure for Student Marks

Question

A teacher needs to store the marks of 30 students. The teacher mainly needs to access a student’s marks using the student’s position in the list. Which data structure is the most suitable?

Solution

The important requirements are:

  • Multiple values need to be stored.
  • The values represent the same type of information.
  • A value needs to be accessed using its position.

An array is suitable for this requirement.

For example:

let marks = [78, 85, 92, 67, 74];

The indexes are:

Index:   0   1   2   3   4
Marks:  78  85  92  67  74

To access the third student’s marks:

console.log(marks[2]);

Output

92

Answer

Array

An array is suitable because the marks can be stored as an ordered collection and accessed using indexes.


Question 2: Trace a Stack Operation

Question

A stack is initially empty. Perform these operations in order:

Push 10
Push 20
Push 30
Pop
Push 40
Pop

What value will be removed by the second Pop operation?

Solution

A stack follows the LIFO (Last In, First Out) principle.

Start with an empty stack.

After:

Push 10

Stack:

10 ← Top

After:

Push 20

Stack:

20 ← Top
10

After:

Push 30

Stack:

30 ← Top
20
10

Now perform the first Pop.

The top value 30 is removed.

Removed: 30

The stack becomes:

20 ← Top
10

Now:

Push 40

Stack:

40 ← Top
20
10

Finally, perform the second Pop.

The top value is 40.

Output

40

Answer

40

The second Pop removes 40 because it was the most recently added element.


Question 3: Trace a Queue Operation

Question

A queue is initially empty. Perform these operations:

Enqueue A
Enqueue B
Enqueue C
Dequeue
Enqueue D
Dequeue

What value will be removed by the second Dequeue operation?

Solution

A queue follows the FIFO (First In, First Out) principle.

Start with an empty queue.

After adding A:

A

After adding B:

A → B

After adding C:

A → B → C

The first Dequeue removes the first element, A.

Removed: A

The queue becomes:

B → C

Now add D:

B → C → D

The second Dequeue removes the first element, which is B.

Output

B

Answer

B

The queue removes elements in the same order in which they were added.


Question 4: Classify Linear and Non-Linear Data Structures

Question

Classify the following data structures as linear or non-linear:

Array
Stack
Tree
Graph
Queue

Solution

A linear data structure arranges elements in a sequential manner.

Therefore:

Array → Linear
Stack → Linear
Queue → Linear

A non-linear data structure represents hierarchical or network-like relationships.

Therefore:

Tree → Non-linear
Graph → Non-linear

The complete classification is:

Data StructureType
ArrayLinear
StackLinear
TreeNon-linear
GraphNon-linear
QueueLinear

Output

Array → Linear
Stack → Linear
Tree → Non-linear
Graph → Non-linear
Queue → Linear

Answer

Array, Stack, and Queue are linear data structures.

Tree and Graph are non-linear data structures.


Question 5: Choose a Data Structure for Undo Operation

Question

A drawing application records these actions:

Draw Circle
Draw Square
Change Color
Delete Square

When the user clicks Undo, the most recent action should be reversed first. Which data structure is most suitable?

Solution

Let’s look at the order in which the actions were performed:

Draw Circle
Draw Square
Change Color
Delete Square

The most recent action is:

Delete Square

If the user clicks Undo, this action should be handled first.

So the behavior is:

Last action → First action to undo

This is the LIFO principle.

LIFO means:

Last In, First Out

A stack follows LIFO.

The actions can be stored like this:

Delete Square ← Top
Change Color
Draw Square
Draw Circle

The top action is removed first.

Output

Undo → Delete Square

Answer

Stack

A stack is suitable because the most recent action needs to be processed first.


Question 6: Choose a Data Structure for Printer Tasks

Question

Four documents are sent to a printer in this order:

Document A
Document B
Document C
Document D

The printer processes the documents in the same order in which they arrive. Which data structure is most suitable?

Solution

The documents arrive in this order:

A → B → C → D

The first document that arrives should be processed first.

Therefore:

A → B → C → D

This follows the FIFO (First In, First Out) principle.

A queue follows FIFO.

The queue can be represented as:

Front                 Rear
  ↓                     ↓
  A  →  B  →  C  →  D

The first document removed from the queue is A.

Output

A

Answer

Queue

A queue is suitable because the documents are processed according to their arrival order.


Question 7: Find the Data Structure from Its Operations

Question

A data structure contains the following elements:

10
20
30

The following operations are performed:

Push 40
Pop
Pop

What values will be removed?

Solution

The word Push indicates that an element is being added to a stack.

Start with:

30 ← Top
20
10

Perform:

Push 40

Now:

40 ← Top
30
20
10

First Pop:

Removed: 40

Stack:

30 ← Top
20
10

Second Pop:

Removed: 30

Output

40
30

Answer

The removed values are:

40, 30

This demonstrates the LIFO behavior of a stack.


Question 8: Choose a Data Structure for a Hierarchical Structure

Question

A computer application needs to represent this folder structure:

Projects
├── Web
│   ├── HTML
│   └── CSS
└── Python
    ├── Basics
    └── Projects

Which data structure is most suitable for representing this structure?

Solution

Look at the relationship between the folders.

Projects is the main folder.

Inside it are:

Web
Python

Inside Web:

HTML
CSS

Inside Python:

Basics
Projects

This creates multiple levels of parent-child relationships.

The structure looks like:

             Projects
             /      \
           Web      Python
          /  \      /    \
       HTML  CSS  Basics Projects

This is a hierarchical structure.

A tree is designed to represent hierarchical data.

Output

Projects
├── Web
│   ├── HTML
│   └── CSS
└── Python
    ├── Basics
    └── Projects

Answer

Tree

A tree is suitable because folders and subfolders form a hierarchical relationship.


Question 9: Choose a Data Structure for Connected Cities

Question

A transportation application needs to represent roads connecting different cities:

Delhi ─── Jaipur
  │         │
  │         │
Agra ─── Lucknow

One city can be connected to multiple other cities. Which data structure is most suitable?

Solution

The important point is that cities can have multiple connections.

For example:

Delhi → Jaipur
Delhi → Agra
Jaipur → Lucknow
Agra → Lucknow

This is a network of relationships.

A graph is designed to represent connections between different objects.

In a graph:

City → Vertex
Road → Edge

So the cities can be represented as vertices, while the roads connecting them can be represented as edges.

Output

Delhi ─── Jaipur
  │         │
  │         │
Agra ─── Lucknow

Answer

Graph

A graph is suitable for representing cities and the connections between them.


Question 10: Select the Right Data Structure

Question

Choose the most suitable data structure for each situation:

A. Store employee IDs and access them using their positions.

B. Undo the most recent action in a photo editor.

C. Process customer requests in the order they arrive.

D. Represent folders and subfolders.

E. Represent connections between users in a social network.

Solution

Let’s solve each situation one by one.

A. Employee IDs

The IDs need to be stored in an ordered collection and accessed using positions.

Suitable data structure: Array

B. Undo the latest action

The latest action should be processed first.

This follows LIFO.

Suitable data structure: Stack

C. Customer requests

The first request received should normally be processed first.

This follows FIFO.

Suitable data structure: Queue

D. Folders and subfolders

Folders have parent-child relationships and multiple levels.

Suitable data structure: Tree

E. Social network connections

Users can have connections with multiple other users.

This creates a network relationship.

Suitable data structure: Graph

Output

SituationData Structure
Employee IDs by positionArray
Undo latest actionStack
Customer requestsQueue
Folders and subfoldersTree
Social network connectionsGraph

Answer

A → Array
B → Stack
C → Queue
D → Tree
E → Graph

Key Takeaways

  • Data structure practice should focus on applying concepts to problems.
  • Use an array when data needs to be stored as an ordered collection and accessed by position.
  • Use a stack when the most recently added item needs to be processed first.
  • Use a queue when the first item added needs to be processed first.
  • Use a tree for hierarchical relationships.
  • Use a graph for networks and connections.
  • LIFO means Last In, First Out.
  • FIFO means First In, First Out.
  • Arrays, stacks, and queues are common linear data structures.
  • Trees and graphs are common non-linear data structures.
  • Choosing the correct data structure depends on how the data needs to be stored and processed.

FAQs

1. What type of questions are included in Data Structure Introduction Practice Questions?

These questions focus on applying basic data structure concepts, identifying suitable structures, tracing operations, and solving simple programming-related situations.

2. Which data structure is used for LIFO?

A stack uses the LIFO principle, meaning the last element added is removed first.

3. Which data structure is used for FIFO?

A queue uses the FIFO principle, meaning the first element added is removed first.

4. When should I use an array?

An array is useful when you need to store a collection of values and access elements using their positions or indexes.

5. When should I use a tree?

A tree is useful when the data has a hierarchical relationship, such as folders and subfolders.

6. When should I use a graph?

A graph is useful when the data represents connections or relationships, such as cities connected by roads or users connected through a social network.

7. How can I improve my data structure problem-solving skills?

Practice problems where you must choose a data structure, trace operations, predict results, and explain why one structure is more suitable than another. Gradually move from simple problems to problems involving multiple operations.

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top