What is space complexity?
a) The amount of memory an algorithm uses.
b) The amount of time an algorithm takes to complete.
c) The number of steps an algorithm performs.
d) The amount of data an algorithm processes.
Answer: a) The amount of memory an algorithm uses.
What is the space complexity of storing an array of n integers?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
What is the space complexity of a function that uses a constant amount of extra space?
a) O(n)
b) O(log n)
c) O(1)
d) O(n^2)
Answer: c) O(1)
What is the space complexity of the recursive implementation of Fibonacci sequence without memoization?
a) O(1)
b) O(n)
c) O(n^2)
d) O(2^n)
Answer: b) O(n)
What is the space complexity of the iterative implementation of Fibonacci sequence?
a) O(1)
b) O(n)
c) O(n^2)
d) O(2^n)
Answer: a) O(1)
What is the space complexity of depth-first search (DFS) in a graph with n nodes and e edges using recursion?
a) O(n)
b) O(e)
c) O(n + e)
d) O(n^2)
Answer: a) O(n)
What is the space complexity of breadth-first search (BFS) in a graph with n nodes and e edges?
a) O(n)
b) O(e)
c) O(n + e)
d) O(n^2)
Answer: c) O(n + e)
What is the space complexity of merge sort?
a) O(n log n)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
What is the space complexity of quicksort in the worst case?
a) O(n log n)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
What is the space complexity of quicksort in the best case?
a) O(n log n)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: c) O(log n)
What is the space complexity of an algorithm that uses an auxiliary array of size n/2?
a) O(n/2)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
What is the space complexity of an algorithm that uses a stack for recursion and the depth of the recursion is n?
a) O(1)
b) O(n)
c) O(n log n)
d) O(n^2)
Answer: b) O(n)
What is the space complexity of storing a binary tree with n nodes?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
Answer: c) O(n)
What is the space complexity of dynamic programming solution for the knapsack problem with n items and capacity W?
a) O(n)
b) O(W)
c) O(nW)
d) O(n + W)
Answer: c) O(nW)
What is the space complexity of an algorithm that uses an adjacency matrix to represent a graph with n nodes?
a) O(n)
b) O(n^2)
c) O(n log n)
d) O(n + e)
Answer: b) O(n^2)
What is the space complexity of an algorithm that uses an adjacency list to represent a graph with n nodes and e edges?
a) O(n)
b) O(n + e)
c) O(e)
d) O(n^2)
Answer: b) O(n + e)
What is the space complexity of a hash table with n elements?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
What is the space complexity of a depth-first search (DFS) in a graph with n nodes and e edges using an iterative approach?
a) O(1)
b) O(n)
c) O(n + e)
d) O(n^2)
Answer: b) O(n)
What is the space complexity of the selection sort algorithm?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: a) O(1)
What is the space complexity of the insertion sort algorithm?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: a) O(1)
Basic Concepts
Non-Linear Data Structures MCQs
Sorting and Searching Algorithms MCQs
- Data Structures MCQs 1
- Data Structures MCQs 2
- Data Structures MCQs 3
- Data Structures MCQs 4
- Data Structures MCQs 5
- Stacks Solved MCQs
- Queues MCQs
- pointer mcqs
- Array MCQs