1. Which of the following is the primary goal of an algorithm?
a) To minimize time complexity
b) To maximize space complexity
c) To solve a problem step-by-step
d) To ensure the algorithm is complex
Answer: c) To solve a problem step-by-step
Rationale: An algorithm is designed to solve a problem efficiently, step-
by-step, and it should be able to give the correct output for given
inputs.
2. What does Big O notation primarily measure?
a) Space consumption
b) Time complexity
c) Algorithm correctness
d) Memory consumption
Answer: b) Time complexity
Rationale: Big O notation is used to describe the upper bound of an
algorithm’s time complexity, measuring the performance in terms of
input size.
3. Which of the following is a divide-and-conquer algorithm?
,a) Binary Search
b) Bubble Sort
c) Insertion Sort
d) Linear Search
Answer: a) Binary Search
Rationale: Binary Search splits the search space in half and recursively
searches through one half, making it a divide-and-conquer algorithm.
4. In the context of data structures, which one of these is a type of tree
traversal?
a) Insertion
b) Sorting
c) Pre-order
d) Merging
Answer: c) Pre-order
Rationale: Pre-order traversal refers to visiting the root node first,
followed by the left and right subtrees in a binary tree.
5. What is the time complexity of Merge Sort?
a) O(n log n)
, b) O(n^2)
c) O(log n)
d) O(n)
Answer: a) O(n log n)
Rationale: Merge Sort has a time complexity of O(n log n) because it
divides the input array into two halves and recursively sorts them.
6. Which of the following is the worst-case time complexity of Quick
Sort?
a) O(n log n)
b) O(n^2)
c) O(log n)
d) O(n)
Answer: b) O(n^2)
Rationale: In the worst case, Quick Sort has a time complexity of
O(n^2), especially when the pivot elements are poorly chosen (e.g.,
always picking the smallest or largest element).
7. Which of the following is not a stable sorting algorithm?
a) Bubble Sort
b) Merge Sort
a) To minimize time complexity
b) To maximize space complexity
c) To solve a problem step-by-step
d) To ensure the algorithm is complex
Answer: c) To solve a problem step-by-step
Rationale: An algorithm is designed to solve a problem efficiently, step-
by-step, and it should be able to give the correct output for given
inputs.
2. What does Big O notation primarily measure?
a) Space consumption
b) Time complexity
c) Algorithm correctness
d) Memory consumption
Answer: b) Time complexity
Rationale: Big O notation is used to describe the upper bound of an
algorithm’s time complexity, measuring the performance in terms of
input size.
3. Which of the following is a divide-and-conquer algorithm?
,a) Binary Search
b) Bubble Sort
c) Insertion Sort
d) Linear Search
Answer: a) Binary Search
Rationale: Binary Search splits the search space in half and recursively
searches through one half, making it a divide-and-conquer algorithm.
4. In the context of data structures, which one of these is a type of tree
traversal?
a) Insertion
b) Sorting
c) Pre-order
d) Merging
Answer: c) Pre-order
Rationale: Pre-order traversal refers to visiting the root node first,
followed by the left and right subtrees in a binary tree.
5. What is the time complexity of Merge Sort?
a) O(n log n)
, b) O(n^2)
c) O(log n)
d) O(n)
Answer: a) O(n log n)
Rationale: Merge Sort has a time complexity of O(n log n) because it
divides the input array into two halves and recursively sorts them.
6. Which of the following is the worst-case time complexity of Quick
Sort?
a) O(n log n)
b) O(n^2)
c) O(log n)
d) O(n)
Answer: b) O(n^2)
Rationale: In the worst case, Quick Sort has a time complexity of
O(n^2), especially when the pivot elements are poorly chosen (e.g.,
always picking the smallest or largest element).
7. Which of the following is not a stable sorting algorithm?
a) Bubble Sort
b) Merge Sort