SOLVED: Recursive method for summing the dollars

23.99 $

Category:

Description

Rate this product

The recursive method for summing the dollars in the grid grid the array (two-dimensional) that presents a grid of integers – can be of any dimensions;@param row the integer defining the row the user wants to start with;@param column the integer defining the column user wants to start with;@return an integer as the sum; The class has two static methods that perform the same task in different ways – one is doing it recursively, and the other iteratively; there is a third commented recursive method, which is a copy of the recursive used with the only exception that it contains the output at each step such that we can see the whole path from one cell to another of the checker; if it’s on the last line – stop and get the the value of the cell it is on; if in the leftmost column – go below and to the right if in the rightmost column – go below and to the left if inside the grid, check which one is bigger if the right is bigger or equal – choose the right the iterative function that gives the sum of the cells through which the “checker” travels – in this particular case this method looks more complicated that the recursive one maybe because of the nextCol variable we should keep track but given bigger grids, the iterative method will be the preferred one since it will consume much lesser memory.Otherwise, the principle of choosing to which cell to go next remains the same as for the recursive method, thus I wouldn’t leave comments inside this method as I did for the recursive one. @param a_grid the 2D array of integers taken by the method; @param row the integer defining the starting row @param column the integer defining the starting column @return the integer defining the sum the checker accumulated while traveling through the grid;

  • DollarCheckerDemo.rar