Back to Practice Data Structures

Arrays - Practice MCQs for CCAT

50 Questions Section B: Programming Data Structures

Arrays Question Bank for C-CAT

Topic-wise Arrays MCQs for CDAC C-CAT preparation with answers and explanations.

Q1.
What is the time complexity to access an element in an array by index?
AO(n)
BO(1)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: B - O(1)

Arrays provide constant time O(1) access because elements are stored in contiguous memory locations.

Q2.
What is the time complexity of inserting an element at the beginning of an array?
AO(n)
BO(1)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: A - O(n)

Inserting at beginning requires shifting all elements, making it O(n).

Q3.
If an array has n elements, what is the index of the last element?
An-1
Bn
Cn+1
D1
Show Answer & Explanation

Correct Answer: A - n-1

Arrays are 0-indexed, so last element is at index n-1.

Q4.
Which sorting algorithm has worst case O(n²) but average case O(n log n)?
AMerge Sort
BHeap Sort
CQuick Sort
DBubble Sort
Show Answer & Explanation

Correct Answer: C - Quick Sort

Quick Sort has O(n²) worst case (already sorted) but O(n log n) average case.

Q5.
In a 2D array arr[m][n], total elements are:
Am + n
Bm - n
Cm / n
Dm × n
Show Answer & Explanation

Correct Answer: D - m × n

A 2D array of m rows and n columns has m × n total elements.

Q6.
Binary search works on:
AAny array
BLinked list
CSorted array only
DUnsorted array
Show Answer & Explanation

Correct Answer: C - Sorted array only

Binary search requires the array to be sorted to work correctly.

Q7.
Time complexity of binary search is:
AO(1)
BO(n)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: C - O(log n)

Binary search halves the search space each time, giving O(log n).

Q8.
Space complexity of a 1D array of n integers:
AO(1)
BO(n)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: B - O(n)

An array of n elements uses O(n) space.

Q9.
Which is NOT an advantage of arrays?
ARandom access
BCache friendly
CSimple implementation
DDynamic size
Show Answer & Explanation

Correct Answer: D - Dynamic size

Arrays have fixed size. Dynamic size is not an advantage of static arrays.

Q10.
Address of arr[i] if base address is B and element size is S:
AB + i
BB + i × S
CB + S
DB × i + S
Show Answer & Explanation

Correct Answer: B - B + i × S

Address of arr[i] = Base + i × Size of each element.

Q11.
What is the time complexity of linear search in an unsorted array?
AO(1)
BO(log n)
CO(n)
DO(n²)
Show Answer & Explanation

Correct Answer: C - O(n)

Linear search checks each element one by one, taking O(n) in worst case.

Q12.
Binary search requires the array to be:
ASorted
BUnsorted
CEmpty
DCircular
Show Answer & Explanation

Correct Answer: A - Sorted

Binary search only works on sorted arrays as it relies on the ordering to eliminate half the elements.

Q13.
Time complexity of binary search:
AO(1)
BO(log n)
CO(n)
DO(n log n)
Show Answer & Explanation

Correct Answer: B - O(log n)

Binary search halves the search space each time, giving O(log n) complexity.

Q14.
A 2D array of m×n has how many elements?
Am + n
Bm / n
Cm - n
Dm × n
Show Answer & Explanation

Correct Answer: D - m × n

A 2D array with m rows and n columns has m × n total elements.

Q15.
Row-major order stores 2D array:
AColumn by column
BRandomly
CRow by row
DDiagonally
Show Answer & Explanation

Correct Answer: C - Row by row

In row-major order, elements of each row are stored contiguously in memory.

Q16.
What is a sparse array?
AArray with mostly zero/default values
BDense array
CSmall array
DCircular array
Show Answer & Explanation

Correct Answer: A - Array with mostly zero/default values

A sparse array has most of its elements as zero or default values.

Q17.
For array of n elements, deleting first element takes:
AO(1)
BO(n²)
CO(log n)
DO(n)
Show Answer & Explanation

Correct Answer: D - O(n)

All remaining n-1 elements must be shifted left, taking O(n) time.

Q18.
Which is true for jagged arrays?
AAll rows same size
BFixed total size
COnly 1D
DRows can have different sizes
Show Answer & Explanation

Correct Answer: D - Rows can have different sizes

Jagged arrays (arrays of arrays) can have rows of different lengths.

Q19.
Dynamic arrays like ArrayList grow by:
AAdding 1 element space
BFixed increment
CDoubling capacity
DNo growth
Show Answer & Explanation

Correct Answer: C - Doubling capacity

Most dynamic array implementations double capacity when full for amortized O(1) insertion.

Q20.
Time complexity of finding minimum in unsorted array:
AO(1)
BO(log n)
CO(n²)
DO(n)
Show Answer & Explanation

Correct Answer: D - O(n)

Must check every element to find minimum, taking O(n) time.

Q21.
What is the time complexity of accessing an element by index in an array?
AO(n)
BO(1)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: B - O(1)

Array elements are stored in contiguous memory locations, so accessing any element by index requires a single base address + offset calculation, giving O(1) time complexity.

Q22.
What is the time complexity of inserting an element at the beginning of an unsorted array of size n?
AO(1)
BO(n)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: B - O(n)

Inserting at the beginning requires shifting all n existing elements one position to the right, resulting in O(n) time complexity.

Q23.
In a sorted array of n elements, what is the time complexity of binary search?
AO(n)
BO(log n)
CO(n²)
DO(1)
Show Answer & Explanation

Correct Answer: B - O(log n)

Binary search repeatedly halves the search space by comparing with the middle element. This halving leads to O(log n) comparisons in the worst case.

Q24.
What is the time complexity of deleting an element from a specific index in an array of size n?
AO(1)
BO(n)
CO(log n)
DO(n log n)
Show Answer & Explanation

Correct Answer: B - O(n)

After deleting the element, all subsequent elements must be shifted one position to the left to fill the gap, resulting in O(n) time in the worst case.

Q25.
Which of the following is NOT a valid advantage of arrays?
AConstant-time access by index
BCache-friendly due to contiguous memory
CEfficient memory usage for fixed-size data
DEasy insertion and deletion at any position
Show Answer & Explanation

Correct Answer: D - Easy insertion and deletion at any position

Insertion and deletion at arbitrary positions in arrays require shifting elements, making them O(n) operations. This is a disadvantage, not an advantage of arrays.

Q26.
If an array of size 10 stores integers (4 bytes each) starting at address 2000, what is the address of element at index 7?
A2032
B2070
C2028
D2024
Show Answer & Explanation

Correct Answer: C - 2028

Address = Base + (index × size) = 2000 + (7 × 4) = 2000 + 28 = 2028.

Q27.
What is the worst-case time complexity of linear search in an array of n elements?
AO(n)
BO(log n)
CO(1)
DO(n²)
Show Answer & Explanation

Correct Answer: A - O(n)

In the worst case, the element is at the last position or not present, requiring comparison with all n elements, giving O(n) time complexity.

Q28.
In a 2D array stored in row-major order with dimensions [M][N], the address of element A[i][j] is:
ABase + (i × M + j) × size
BBase + (j × M + i) × size
CBase + (i × N + j) × size
DBase + (i + j × N) × size
Show Answer & Explanation

Correct Answer: C - Base + (i × N + j) × size

In row-major order, elements of each row are stored contiguously. To reach A[i][j], we skip i complete rows (each of N elements) and then j elements within the current row.

Q29.
What is the time complexity of finding the maximum element in an unsorted array?
AO(1)
BO(n)
CO(log n)
DO(n log n)
Show Answer & Explanation

Correct Answer: B - O(n)

Every element must be checked to determine the maximum in an unsorted array, requiring a single pass through all n elements, giving O(n).

Q30.
Which operation on a sorted array has O(log n) time complexity?
ASearch using binary search
BDeletion
CInsertion
DTraversal
Show Answer & Explanation

Correct Answer: A - Search using binary search

Binary search on a sorted array achieves O(log n) by halving the search space at each step. Insertion and deletion still require shifting elements (O(n)), and traversal is always O(n).

Q31.
What happens when you try to access an array index that is out of bounds in C?
ACompiler error
BRuntime exception
CReturns 0
DUndefined behavior
Show Answer & Explanation

Correct Answer: D - Undefined behavior

C does not perform bounds checking on arrays. Accessing an out-of-bounds index leads to undefined behavior — it may read garbage values, crash, or produce unpredictable results.

Q32.
In a column-major order, elements of a 2D array are stored:
ARow by row
BRandomly
CDiagonally
DColumn by column
Show Answer & Explanation

Correct Answer: D - Column by column

In column-major order (used by languages like Fortran), all elements of the first column are stored first, then all elements of the second column, and so on.

Q33.
What is the space complexity of an array of n elements?
AO(n)
BO(1)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: A - O(n)

An array of n elements requires memory proportional to n to store all elements, giving O(n) space complexity.

Q34.
Which sorting algorithm is most efficient for nearly sorted arrays?
AInsertion sort
BSelection sort
CMerge sort
DHeap sort
Show Answer & Explanation

Correct Answer: A - Insertion sort

Insertion sort performs very well on nearly sorted arrays with O(n) best-case time complexity, as very few shifts are needed when elements are almost in order.

Q35.
What is the time complexity of merging two sorted arrays of size m and n into a single sorted array?
AO(m × n)
BO(m log n)
CO(m + n)
DO((m+n) log(m+n))
Show Answer & Explanation

Correct Answer: C - O(m + n)

Using the two-pointer technique, we compare elements from both arrays and place the smaller one in the result. Each element is processed exactly once, giving O(m + n).

Q36.
In a sparse matrix, which storage method is more memory efficient?
A2D array
BNeither can store sparse matrices
CBoth use equal memory
DTriplet representation (row, col, value)
Show Answer & Explanation

Correct Answer: D - Triplet representation (row, col, value)

A sparse matrix has mostly zero elements. Storing only non-zero elements as (row, col, value) triplets uses far less memory than a full 2D array that stores all zeros.

Q37.
What is the output of applying binary search for element 7 in the array [2, 4, 6, 8, 10, 12]?
AIndex 3
BElement not found
CIndex 2
DIndex 4
Show Answer & Explanation

Correct Answer: B - Element not found

Binary search requires the target element to be present in the array. Since 7 is not in [2, 4, 6, 8, 10, 12], the search returns 'element not found'.

Q38.
Which of the following operations is most efficient in an array compared to a linked list?
ARandom access by index
BDeletion from middle
CInsertion at beginning
DInsertion at middle
Show Answer & Explanation

Correct Answer: A - Random access by index

Arrays provide O(1) random access by index due to contiguous memory allocation. Linked lists require O(n) traversal for the same operation.

Q39.
What is the maximum number of comparisons needed in binary search for an array of 1024 elements?
A10
B512
C11
D1024
Show Answer & Explanation

Correct Answer: C - 11

Binary search needs at most ⌊log₂(n)⌋ + 1 comparisons. For n = 1024: log₂(1024) = 10, so maximum comparisons = 10 + 1 = 11.

Q40.
What is the time complexity of reversing an array of n elements in-place?
AO(1)
BO(n)
CO(n/2)
DO(n²)
Show Answer & Explanation

Correct Answer: B - O(n)

Reversing in-place requires swapping elements from both ends toward the center, performing n/2 swaps. Since O(n/2) simplifies to O(n), the time complexity is O(n).

Q41.
A jagged array (array of arrays) differs from a 2D array in that:
AEach row can have a different number of columns
BIt uses less memory always
CIt is faster to access
DIt cannot store integers
Show Answer & Explanation

Correct Answer: A - Each row can have a different number of columns

A jagged array allows each row to have a different length, unlike a standard 2D array where all rows must have the same number of columns.

Q42.
What is the time complexity of checking if an unsorted array contains duplicate elements using brute force?
AO(n²)
BO(n log n)
CO(n)
DO(2ⁿ)
Show Answer & Explanation

Correct Answer: A - O(n²)

The brute force approach compares every pair of elements using two nested loops, resulting in n(n-1)/2 comparisons, which is O(n²).

Q43.
In an array-based implementation of a dynamic array (like ArrayList), what happens when the array is full and a new element is added?
AOverflow error occurs
BA new larger array is allocated and elements are copied
CThe last element is overwritten
DMemory is extended in-place
Show Answer & Explanation

Correct Answer: B - A new larger array is allocated and elements are copied

Dynamic arrays allocate a new array (typically double the size), copy all existing elements to the new array, and then add the new element. This is called resizing or growing.

Q44.
What is the amortized time complexity of insertion at the end of a dynamic array?
AO(1)
BO(log n)
CO(n)
DO(n²)
Show Answer & Explanation

Correct Answer: A - O(1)

Although occasional resizing takes O(n), it happens infrequently. When averaged over a sequence of n insertions, each insertion costs O(1) amortized time due to the doubling strategy.

Q45.
To find the second largest element in an unsorted array, the minimum number of passes required is:
An-1
B2
Cn
D1
Show Answer & Explanation

Correct Answer: D - 1

The second largest element can be found in a single pass by maintaining two variables: one for the largest and one for the second largest, updating them as we traverse.

Q46.
What is the best-case time complexity of bubble sort on an already sorted array (with optimization)?
AO(n²)
BO(n log n)
CO(n)
DO(1)
Show Answer & Explanation

Correct Answer: C - O(n)

With the optimization of a flag to detect if no swaps occurred in a pass, bubble sort completes in one pass (O(n)) on an already sorted array.

Q47.
Which of the following correctly represents the lower triangular matrix storage in a 1D array for element A[i][j] where i ≥ j?
AIndex = j(j+1)/2 + i
BIndex = i(i+1)/2 + j
CIndex = i×n + j
DIndex = i + j
Show Answer & Explanation

Correct Answer: B - Index = i(i+1)/2 + j

In a lower triangular matrix, elements are stored row-wise. Before row i, there are 1+2+...+i = i(i+1)/2 elements. Adding j gives the position of A[i][j].

Q48.
What is the time complexity of the Dutch National Flag algorithm for sorting an array of 0s, 1s, and 2s?
AO(n)
BO(n log n)
CO(n²)
DO(1)
Show Answer & Explanation

Correct Answer: A - O(n)

The Dutch National Flag algorithm uses three pointers (low, mid, high) and sorts the array in a single pass through all elements, giving O(n) time complexity.

Q49.
In interpolation search on a uniformly distributed sorted array, what is the average time complexity?
AO(n)
BO(log n)
CO(log log n)
DO(√n)
Show Answer & Explanation

Correct Answer: C - O(log log n)

For uniformly distributed data, interpolation search estimates the position of the target using linear interpolation, achieving O(log log n) average time complexity.

Q50.
What is the time complexity of rotating an array of n elements by k positions using the reversal algorithm?
AO(k)
BO(n log n)
CO(n × k)
DO(n)
Show Answer & Explanation

Correct Answer: D - O(n)

The reversal algorithm rotates an array by reversing three subarrays: first k elements, remaining n-k elements, and then the entire array. Each reversal is O(n), giving O(n) overall.

Showing 1-10 of 50 questions