public class RowvColumn
{
public static void main(String[] args)
{
/**This program compares the run-time between row-major and column major
* ordering.
*/
//creating a 2d Array
int[][] twoD = new int[5000][5000];
long start = System.currentTimeMillis();
for (int row = 0 ; row < twoD.length; row++)
{
for (int col = 0; col < twoD[row].length; col++)
{
twoD[row][col] = row + col;
}
}
long mid = System.currentTimeMillis();
for (int row = 0; row < twoD.length; row++)
{
for (int col = 0; col < twoD[row].length; col++)
{
twoD[col][row] = row + col;
}
}
long end = System.currentTimeMillis();
System.out.println("Speed to traverse Row-Major (Milliseconds): " + (mid - start));
System.out.println("Speed to traverse Column-Major (Milliseconds): " + (end-mid));
}
}
Using the example code from Row vs. Column Major, answer the following questions in complete sentences:
Is Row-Major or Column-Major order faster? Why do you think that is. Please explain using execution counts.
In what scenario would you use Row-Major ordering when traversing a 2D array? In what scenario would you use Column-Major ordering?

Answers

Answer 1

The provided example code indicates that Row-Major order is quicker than Column-Major order.

The order that elements of a two-dimensional array are kept in memory is referred to as row-major. The items of one row are kept together in a row-major order, then the elements of the next row, and so on. This makes it efficient to iterate across each row of the array, accessing its elements one at a time. The array can be traversed more quickly column by column when the components of a column are stored together in column-major order. Programming languages like C and Java frequently employ row-major ordering. It is helpful for operations like matrix multiplication or linear algebra that require iterating through a matrix's rows.

Learn more about Row-Major here:

https://brainly.com/question/29758232

#SPJ4


Related Questions

Other Questions
Read the following passage:No one was looking forward to Tommy's fifth birthday. Onthat day, he would be removed from the family to entercommunal living. There, he and the other five-year-oldswould be evaluated and set on a "track." We were allhoping that his intelligence and creativity would benoticed. Maybe he could become a scientist orprogrammer - anything but a coal processor. Either way,we would never find out.Which detail from the passage best suggests that the story's setting is adystopia? y=x^2+7x-3 complete the square to re-write the quadratic function in vertex form.pls help students conducting research observe the rate of an enzyme-catalyzed reaction under various conditions with a fixed amount of enzyme in each sample. when will increasing the substrate concentration likely result in the greatest increase in the reaction rate? Which of the following is NOT one of the options Gorgias invites his audience to consider in discussing the "bad reputation" of Helen? -her noble birth - fortune -persuasion - r*pe - her own free will Uri paid a landscaping company to mow his lawn. The company charged $74 for the service plus 5% tax. After tax, Uri also included a 10% tip with his payment. How much did he pay in all? Chang, the founder of a multinational corporation, believes that his business should mainly focus on the benefit of those people who own its stock. In this scenario, he most likely follows _______, a model of business management.a. Stakeholders modelb. Shareholders primacyc. Customer value Immigration vs emigration in the American Rocky Mountains chart How was the Montgomery Bus Boycott an influential part of the Civil Rights Movement?ResponsesIt brought the leadership of Thurgood Marshall to national attention.It led to the desegregation of interstate transportation.It demonstrated the effectiveness of nonviolent protest.It resulted in the integration of the citys schools. The Kingston County Basketball Conference (KCBC) is an amateur basketball association. Each city in the county has one team that represents it. Each team has a maximum of twelve players and a minimum of nine players. Each team also has up to three coaches (offensive, defensive, and PT coaches.) Each team plays two games (home and visitor) against each of the other teams during the season.a. Draw the ER diagram.b. Create a relational model based on the ER diagram. mrs. grundy believes that boarding schools provide the best education because after attending such a school, she found herself well prepared for college. the fallacy in her thinking is Which evidence suggests that some of the first life on earth was prokaryotic bacteria? in a peptide bond, which parts of the two amino acids are joined together? Solve please geometry, solve for x which of the following pharmacologic features is shared by all of the medications that have received fda approval for maintenance treatment of opioid use disorder?A. FDA approved medications for maintenance or detoxificationB. Medications in schedules III, IV, or VC. Buprenorphine or Buprenorphine/naloxoneD. Methadone the muscle name literally meaning below the tongue is blank.target 1 of 5 the muscle connecting the hyoid bone to the styloid process of the temporal bone is the blank.target 2 of 5 the shorter of the muscles over the fibula is the blank.target 3 of 5 the muscle extending from the arm to the lateral forearm is the blank.target 4 of 5 the hamstring that becomes tendinous midway along its length is the on what part of the face was a female moai tatooed a market shortage results from an excess of quantity over quantity at a given price. (insert one word in each blank.) which idea of evolution is supported by the existence of vestigial structures? Help me. Do you think people have a responsibility to learn how to use new technologies? Why or why not? how might a scientist determine whether a trait is sex-linked by observing the offspring of several genetic crosses? 4. compare and contrast how is the expression of sex-linked genes both similar to and different from the expression of autosomal genes?