Array Basics: 16 MCQs with answers
All 16 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 10 questions
Q1. What is an array?
BeginnerShow answer & explanation
A collection of elements of the same data type stored in contiguous memory locations
An array is a fixed-size collection of elements of the same data type stored in contiguous memory locations.
Q2. How is an element accessed in an array?
BeginnerShow answer & explanation
By its index
Array elements are accessed using their index, which represents their position in the array.
Q3. Which of the following is a disadvantage of arrays?
BeginnerShow answer & explanation
They have a fixed size
Arrays have a fixed size determined at creation, which cannot be changed later.
Q4. What is a multidimensional array?
BeginnerShow answer & explanation
An array of arrays
A multidimensional array is an array of arrays, such as a 2D array representing a matrix.
Q5. What is the space complexity of an array of size $n$?
BeginnerShow answer & explanation
$O(n)$
An array of size $n$ requires space proportional to $n$, so space complexity is $O(n)$.
Q6. What is the index of the first element in most programming languages?
BeginnerShow answer & explanation
0
In many languages like C, C++, Java, and Python, array indices start at 0.
Q7. What happens if you try to access an array element with an index out of bounds?
BeginnerShow answer & explanation
The program may crash or produce undefined behavior
Accessing out of bounds can lead to runtime errors or undefined behavior, as it accesses memory not allocated for the array.
Q8. Which of the following is true about arrays?
BeginnerShow answer & explanation
Arrays provide constant-time access to elements by index
Arrays allow direct access to any element using its index in constant time.
Q9. Arrays can store elements of different data types.
BeginnerShow answer & explanation
False
Arrays are homogeneous; they store elements of the same data type.
Q10. The size of an array can be changed after it is created.
BeginnerShow answer & explanation
False
Static arrays have a fixed size determined at creation and cannot be resized.
Building up · 6 questions
Q11. What is the time complexity to access an element in an array by index?
IntermediateShow answer & explanation
$O(1)$
Accessing an array element by index is a constant time operation because the memory address can be calculated directly.
Q12. What is the time complexity to insert an element at the beginning of an array of size $n$?
IntermediateShow answer & explanation
$O(n)$
Inserting at the beginning requires shifting all existing elements one position to the right, which takes linear time.
Q13. What is the time complexity to delete an element from the end of an array of size $n$?
IntermediateShow answer & explanation
$O(1)$
Deleting the last element does not require shifting any other elements, so it takes constant time.
Q14. What is the time complexity to search for an element in an unsorted array of size $n$?
IntermediateShow answer & explanation
$O(n)$
In the worst case, you may need to check every element, resulting in linear time complexity.
Q15. What is the time complexity to search for an element in a sorted array using binary search?
IntermediateShow answer & explanation
$O(\log n)$
Binary search repeatedly divides the search interval in half, resulting in logarithmic time complexity.
Q16. Which operation is NOT typically supported efficiently by a static array?
IntermediateShow answer & explanation
Inserting an element at an arbitrary position
Inserting at an arbitrary position requires shifting elements, which is inefficient ($O(n)$) for large arrays.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages