Which of the following is an advantage of using arrays?

Asked In: BPSC TRE 3.0

Options

  • A. Constant time insertion and deletion
  • B. Ability to store elements of different data types
  • C. Random access to elements using an index
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. Random access to elements using an index

Detailed Explanation

Random access is one of the major advantages of an array. Since array elements are stored in contiguous memory locations, the address of any element can be calculated directly using its index. Therefore, accessing A[i] normally takes O(1) time. Arrays generally store elements of the same data type. Insertion or deletion at an arbitrary position can require shifting elements, making those operations O(n) in the worst case.