Which statement correctly compares array and linked-list access by position?

Options

  • A. Array access is generally O(1), while linked-list access is generally O(n)
  • B. Both always provide O(1) access
  • C. Array access is O(n), while linked-list access is O(1)
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. Array access is generally O(1), while linked-list access is generally O(n)

Detailed Explanation

Arrays and linked lists differ significantly in how they access elements. An array supports O(1) random access because the address of an indexed element can be calculated directly. A singly linked list generally requires traversal from the first node to reach a particular position, resulting in O(n) access in the worst case. However, linked lists can perform insertion or deletion efficiently when the relevant node or position is already known. These trade-offs are important when selecting a data structure.