Arrays MCQ
Arrays MCQ
1. What is the time complexity of accessing an element in an array using the index?
A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Answer: A. O(1)
A. 4
B. 5
C. 6
D. 3
Answer: A. 4
A. int arr[5];
5. Which data structure is most suitable to implement an array with variable size?
A. Stack
B. Queue
C. Linked List
D. Tree
A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Answer: B. O(n)
7. What is the time complexity to append an element to the end of an array, assuming enough
space is available?
A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Answer: A. O(1)
A. Loops
B. Recursion
C. Iterators
D. All of the above
A. Fixed size
B. Sequential storage
D. Random access
10. What happens if you try to access an array index out of bounds in C?
B. Runtime error
C. Segmentation fault
D. Logical error
A. Value at arr[i]
B. Address of arr[i]
C. Garbage value
D. Compiler error
13. Which of the following sorting algorithms works best for nearly sorted arrays?
A. Quick Sort
B. Merge Sort
C. Insertion Sort
D. Selection Sort
A. Stack
B. Queue
C. Two-pointer method
D. Recursion only
15. What is the auxiliary space complexity of the merge sort algorithm on arrays?
A. O(1)
B. O(n)
C. O(log n)
D. O(n^2)
Answer: B. O(n)
17. Which method can be used to search an element in a sorted array efficiently?
A. Linear Search
B. Binary Search
C. Jump Search
A. 1
B. 0
C. -1
D. Garbage
Answer: B. 0
A. O(n)
B. O(log n)
C. O(1)
D. O(n^2)
Answer: C. O(1)
B. Array of arrays
C. Graph
D. Matrix