Data Structures

Arrays — Practice MCQs for CCAT

20 Questions Section B: Programming Data Structures

Practice 20 Arrays multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.

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

Correct Answer: A — 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(1)
BO(n)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: B — 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
Bn-1
Cn+1
D1
Show Answer & Explanation

Correct Answer: B — 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
BQuick Sort
CHeap Sort
DBubble Sort
Show Answer & Explanation

Correct Answer: B — 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: C — m × n

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

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

Correct Answer: B — 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
CDynamic size
DSimple implementation
Show Answer & Explanation

Correct Answer: C — 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 + S
CB + i × S
DB × i + S
Show Answer & Explanation

Correct Answer: C — 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:
AUnsorted
BSorted
CEmpty
DCircular
Show Answer & Explanation

Correct Answer: B — 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(n)
CO(log n)
DO(n log n)
Show Answer & Explanation

Correct Answer: C — 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: B — 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
BRow by row
CRandomly
DDiagonally
Show Answer & Explanation

Correct Answer: B — Row by row

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

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

Correct Answer: B — 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: B — 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
BRows can have different sizes
COnly 1D
DFixed total size
Show Answer & Explanation

Correct Answer: B — 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
BDoubling capacity
CFixed increment
DNo growth
Show Answer & Explanation

Correct Answer: B — 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: C — O(n)

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