Top MCQs on Data Structures | DSA Quiz for Beginners

Last Updated : 26 Sep, 2023

A data structure is defined as a particular way of storing and organizing data in our devices to use the data efficiently and effectively. The main idea behind using data structures is to minimize the time and space complexities. An efficient data structure takes minimum memory space and requires minimum time to execute the data.

More On Data Structure…

DSA Quiz for Beginners | Data Structure

DSA Quiz for Beginners | Data Structure

Question 1

Which of the following syntax correctly declares an Array?

Cross

int geeks;

Cross

array geeks[20];

Cross

geeks{20};

Tick

int geeks[20];



Question 1-Explanation: 

Option A: This syntax is a popular way of declaring variables, and not Array.
Option B: Array is not a keyword and hence cannot be used to declare an Array
Option C: No data type is defined here. So array cannot be created using this syntax
Option D: This syntax is optimal for creating an array, as it contains a data type, variable name, and the array size.

Hence D is the correct answer.

Question 2

The size of the array should always be _____

Tick

Positive

Cross

Negative

Cross

whole Number

Cross

Real Number



Question 2-Explanation: 

Option A: The size of the array should always be positive to store some number of elements.
Option B: The size of the array can never be negative, as we can never have negative number of elements to store. hence we can never have the size of array as negative.
Option C: Zero is also a whole number, but we can never have zero number of elements to store. Hence, we can never have size of array as a whole number.
Option D: Real number includes - positive, negative, and zero number. so we can not have this as a size of array, as mentioned above. So we can not consider the real number for size of array.

Hence ( A ) is the correct option.

Question 3

What is the correct way to initialize values in an array?

Cross

my_array [5] = (5,3,4,2,7);

Cross

my_array [5] = {5;3;4;2;7};

Cross

my_array [5] = {5,3,4,2,7,5,6,7,8};

Tick

my_array [5] = {1,2,3,4,5};



Question 3-Explanation: 

Option A:  We can not initialize values within parenthesis, this syntax is incorrect for initializing values.
Option B: We can not initialize values separated by semi-colons, this syntax is incorrect for initializing values.
Option C: Here the number of elements exceeds the size of the array, so we can not consider this.
Option D: This is the correct way to initialize values into an array.

Hence Option (D) is correct.

Question 4

In an array int arr[3]={1,2,3}, what will happen if we try to access arr[4] in C/C++?

Cross

Run TIme error

Cross

3

Cross

0

Tick

Garbage value



Question 4-Explanation: 

Option A:  The reason you might not see a runtime error in this specific case is that C/C++ does not perform bounds checking by default. The compiler does not enforce any runtime checks to ensure that you are accessing array elements within their valid bounds.
Option B: It does not automatically give an output of 3 because you are accessing a memory location beyond the bounds of the array.
Option C: We are trying to access arr[4], which is beyond the valid range of indices, it will result in undefined behavior. as providing garbage value, not zero.
Option D: If you try to access arr[4], which is beyond the valid range of indices, it will result in undefined behavior. as providing garbage values.

Hence option (D) is correct.

Question 5

Which of these operators can be used to concatenate two or more String objects?

Tick

"+"

Cross

"+="

Cross

"&"

Cross

None of these



Question 5-Explanation: 

"+" Operator is used for concatenation of two string.

Hence option (A) is the correct option.

Question 6

Which of these methods of class String is used to obtain the length of the String object?

Cross

get()

Cross

Sizeof()

Cross

lengthof()

Tick

length()



Question 6-Explanation: 

The length method is used for calculating the number of characters present in a string.

Hence option (D) is correct.

Question 7

In a circular linked list, the last node points to the____.

Cross

this pointer

Cross

tail pointer

Tick

first node

Cross

middle node



Question 7-Explanation: 

first node

  • In a circular linked list, the last node points to the first node in the list. This creates a circular structure where the last node connects back to the first node, forming a loop.

Hence Option (C) is incorrect.

Question 8

What advantage does a linked list have over an array?

Tick

A linked list is not of a fixed size

Cross

It's better

Cross

It is easier to use

Cross

A linked list can give you the data faster



Question 8-Explanation: 

The advantage of a linked list over an array is that a linked list is not of a fixed size. In an array, the size is determined when it is created, and it cannot easily be changed. In contrast, a linked list can dynamically grow or shrink as needed by adding or removing elements.

Hence (A) is the correct option.

Question 9

Nodes in a linked list contain two things: 

Cross

A pointer and a node

Cross

A Pointer and a reference

Cross

Direction and a pointer

Tick

Data and a pointer



Question 9-Explanation: 

In a linked list, each node contains two main components:

  1. Data
  2. Pointer / Reference

Hence (D) is the correct option.

Question 10

The last node of the singly-linked list contains ___

Tick

NULL

Cross

Next pointer

Cross

Data

Cross

None of the above



Question 10-Explanation: 

The last node of a singly-linked list typically contains a pointer/reference that points to NULL or nullptr, indicating the end of the list. This pointer/reference is used to terminate the linked list and signifies that there is no next node after the last node.

Hence Option A is correct.

There are 30 questions to complete.


Share your thoughts in the comments

Similar Reads