Checking an AI proposal against a memory budget

An AI assistant proposes a numerical program that retains a full N×NN\times N distance matrix for N=10 000N=10\,000 three-dimensional points. Every matrix entry occupies 8 bytes. The program has a strict total budget of 512 MiB, and all memory outside the distance matrix occupies exactly 128 MiB under the supplied planning model. Use 1 MiB=1 048 576 bytes1\ \text{MiB}=1\,048\,576\ \text{bytes}.


You request a revised implementation that processes rr rows at a time without retaining the full matrix. In this revised plan, the fixed allocation is still 128 MiB. In addition, each block requires these three arrays:

  • Coordinate differences: r×N×3r\times N\times3 entries, each occupying 8 bytes.
  • Squared distances: r×Nr\times N entries, each occupying 8 bytes.
  • Row totals: rr entries, each occupying 8 bytes.

All three block arrays are allocated simultaneously. Each block is processed and its arrays released before the next block is allocated. The fixed allocation includes accumulated output and every allocation not listed above. Ignore allocator overhead beyond this explicit model.


Find the original program's total memory requirement in MiB to one decimal place, the maximum integer block size rr that fits the revised plan, and the number of blocks needed to process all 10,000 rows using that maximum size. Give the last two answers as exact integers; the final block may contain fewer rows.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Use of AI in Programming Questions: