Computer Science: An Overview: Global Edition (12th Edition)

Published by Pearson Higher Education
ISBN 10: 1292061162
ISBN 13: 978-1-29206-116-0

Chapter 8 - Data Abstractions - Chapter Review Problems - Page 408: 3

Answer

See the explanation

Work Step by Step

Given a 2D array representation of a matrix in column major order and its dimensions, what is the correct formula to access the element at position (i, j)? A) element = matrix[j * rows + i] B) element = matrix[i * columns + j] C) element = matrix[i * rows + j] D) element = matrix[j * columns + i] Correct Answer: B) element = matrix[i * columns + j] Explanation: In column major order, elements are stored column-wise, so to access the element at position (i, j), we need to multiply the row index (i) by the number of columns and add the column index (j). Therefore, the correct formula is element = matrix[i * columns + j].
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.