MCQ On Data Structure Array
Q1. What is an array?.
- Collection of different data types
- Collection of similar data types stored in random locations
- Collection of similar data types stored in contiguous memory locations
- Collection of elements stored in linked memory
Answer: c, Collection of similar data types stored in contiguous memory locations
Solution: An array stores similar data types in continuous memory locations.
Q2. Which operation is fastest in an array?.
- Insertion
- Deletion
- Searching
- Accessing an element
Answer: d, Accessing an element
Solution: Array elements can be accessed directly using index, which is O(1).
Q3. What is the time complexity of accessing an array element by index?.
- O(n)
- O(log n)
- O(1)
- O(n²)
Answer: c, O(1)
Solution: Direct indexing allows constant time access.
Q4. What is the time complexity of traversing an array of size n?.
- O(1)
- O(log n)
- O(n)
- O(n²)
Answer: c, O(n)
Solution: Traversal visits each element once.
Q5. What is the time complexity of inserting an element at the end of an array?.
- O(1)
- O(log n)
- O(n)
- O(nlog n)
Answer: a, O(1)
Solution:
When an element is inserted at the end of an array (and there is available space):
- No shifting of existing elements is required
- The element is placed directly at the last index
So, the operation takes constant time, independent of the array size.
Therefore, time complexity = O(1)
Q6. What is the time complexity of deleting an element from an array?.
- O(1)
- O(log n)
- O(n)
- O(nlog n)
Answer: c, O(n)
Solution: Deleting an element from an array has a time complexity of O(n) due to element shifting. But when deleting from end then time complexity is O(1)
Q7. Which of the following is a limitation of arrays?.
- Dynamic size
- Fast access
- Fixed size
- Easy traversal
Answer: c, Fixed size
Solution: Arrays have fixed size which cannot be changed at runtime.
Q8. Which of the following is a valid array declaration in C?.
- int arr;
- int arr[ ];
- int arr[5];
- arr int[5];
Answer: c, int arr[5];
Solution: Array must have size specified or initialized.
Q9. What happens if array size is not specified during initialization?.
- Error occurs
- Garbage value assigned
- Compiler decides the size
- Array cannot be created
Answer: c, Compiler decides the size
Solution: Compiler automatically sets size based on number of elements.
Q10. What is the default value of uninitialized array elements in C?.
- 0
- NULL
- Garbage value
- Compiler error
Answer: c, Garbage value
Solution: Uninitialized arrays contain garbage values.
Q11. Which of the following concepts make extensive use of arrays?.
- Binary trees
- Scheduling of processes
- Caching
- Spatial locality
Answer: d, Spatial locality
Solution: Spatial locality is a concept from memory management that states: If a memory location is accessed, nearby memory locations are likely to be accessed soon. Arrays store elements in contiguous memory locations, which makes them a perfect fit for spatial locality. When one array element is accessed, the neighboring elements are already close in memory and often loaded into cache together.
Q12. Elements in an array are accessed _____________.
- randomly
- sequentially
- exponentially
- logarithmically
Answer: a, randomly
Solution: Elements in an array are accessed randomly. In Linked lists, elements are accessed sequentially.
Q13. Assuming int is of 4bytes, what is the size of int arr[15];?.
- 15
- 19
- 11
- 60
Answer: d, 60
Solution: Since there are 15 int elements and each int is of 4bytes, we get 15*4 = 60bytes.