NEOCODE

Fundamental Data Structures MCQs

1. Which of the following is a linear data structure?

Correct Answer: c) Array

Explanation: Arrays are linear data structures where elements are stored in contiguous memory locations and accessed using indices.

2. What is the primary characteristic of a linked list?

Correct Answer: c) Dynamic size and non-contiguous memory allocation

Explanation: Linked lists consist of nodes that are not stored contiguously in memory, and their size can grow or shrink dynamically.

3. Which data structure follows the LIFO (Last In, First Out) principle?

Correct Answer: b) Stack

Explanation: Stacks follow the LIFO principle, where the last element added is the first one to be removed.

4. What is the main operation used to add an element to a queue?

Correct Answer: c) Enqueue

Explanation: In a queue, elements are added using the 'enqueue' operation and removed using the 'dequeue' operation.

5. Which data structure is typically used to implement a priority queue?

Correct Answer: c) Heap

Explanation: Priority queues are often implemented using heaps, which allow efficient retrieval and removal of the highest-priority element.

6. What is the maximum number of edges in an undirected graph with n vertices?

Correct Answer: c) n(n-1)/2

Explanation: In an undirected graph, the maximum number of edges is n(n-1)/2, where n is the number of vertices.

7. Which of the following is true about adjacency matrix representation of a graph?

Correct Answer: c) It is a symmetric matrix for undirected graphs.

Explanation: In an adjacency matrix for an undirected graph, the matrix is symmetric because edges are bidirectional.

8. What is a connected component in a graph?

Correct Answer: b) A subgraph where every pair of vertices is connected by a path.

Explanation: A connected component is a maximal subgraph where there is a path between every pair of vertices.

9. Which of the following is a property of a tree?

Correct Answer: b) It has |E| = |V| - 1 edges.

Explanation: A tree is a connected acyclic graph with exactly |V| - 1 edges, where |V| is the number of vertices.

10. What is the height of a binary tree with n nodes?

Correct Answer: c) Between log_2 n and n - 1

Explanation: The height of a binary tree ranges from log_2 n (for a balanced tree) to n - 1 (for a skewed tree).