CompTIA Tech+ (FC0-U71)Software Development ConceptsEasy
A developer is designing a program that needs to store a collection of related items, where each item can be accessed by an index number. Which of the following data structures would be most appropriate?
- AQueue
- BLinked List
- CArray
- DStack
Show answer & explanationAnswer & explanation
Correct answer: C. Array
An array is a data structure specifically designed to store a fixed-size sequential collection of elements of the same data type. Elements are accessed using an integer index, making it ideal for the described scenario.
Why the other options are wrong
- A. A queue is a FIFO (First-In, First-Out) data structure, not primarily for indexed access.
- B. A linked list stores elements sequentially but access is typically O(n) for a given index, not direct like an array.
- D. A stack is a LIFO (Last-In, First-Out) data structure, not primarily for indexed access.
Array Data Structure
An array is a fundamental data structure consisting of a collection of elements, each identified by at least one array index or key.
- Stores a fixed-size sequential collection of elements.
- Elements are typically of the same data type.
- Provides direct access to elements using an integer index.
Memory trick: Arrays are like numbered boxes for your items.