Question: Suppose X is a two-dimensional array declared in a program. When the program is compiled, the compiler needs to allocate a chunk of memory for
Suppose X is a two-dimensional array declared in a program. When the program is compiled, the compiler needs to allocate a chunk of memory for storing the values of X. This chunk of memory is allocated in a linear one-dimensional fashion. Therefore, there must be ways of mapping a multidimensional array into linear memory: row-major and column-major. In row-major order, the consecutive elements of a row reside next to each other in the memory storage; the same holds true for consecutive elements of a column in column-major order. If the binary search is performed in linear storage after X is compiled and executed, which (row-major or column-major) will work for the binary search? Why?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
