The number of elements in a one-dimensional array with lowest and highest…
2017
The number of elements in a one-dimensional array with lowest and highest index values as -1024 and 1024 is:
Answer: D. 2049 — Concept: in data-structure theory, a one-dimensional array is described by its index range [LB, UB] — a lower bound (LB) and upper bound (UB) that can be ANY…
- A.
2048
- B.
0
- C.
1024
- D.
2049
Attempted by 1135 students.
Show answer & explanation
Correct answer: D
Concept: in data-structure theory, a one-dimensional array is described by its index range [LB, UB] — a lower bound (LB) and upper bound (UB) that can be ANY integers, negative, zero, or positive, not necessarily starting at 0. This is the general model used in address-calculation problems (this question's own topic), distinct from the 0-based convention that specific programming languages like C or Java happen to adopt. For any such range, the total number of elements equals the count of integers in the closed interval, given by the formula: N = UB − LB + 1.
Applying this to the given bounds:
Read off the two bounds stated in the question: LB = −1024 and UB = 1024.
Apply the general element-count formula: N = UB − LB + 1.
Substitute the values: N = 1024 − (−1024) + 1 = 1024 + 1024 + 1 = 2049.
Cross-check by splitting the index range into three non-overlapping blocks and counting each separately: the negative indices from −1024 to −1 contribute 1024 positions, the single index 0 contributes 1 position, and the positive indices from 1 to 1024 contribute another 1024 positions. Adding these blocks gives 1024 + 1 + 1024 = 2049, the same total obtained from the formula.
Note: this differs from the common 0-based indexing convention of languages such as C or Java, where array indices always start at 0. Here the array is explicitly declared with a negative lower bound — a valid abstract index label in the data-structure model, not a physical memory offset — so the LB/UB formula must be applied exactly as given rather than assuming indices always begin at 0.
Explore the full course: Iocl Engineers Officers Grade A Paper 2