You have been hired at an open-air mine. You are to write a program to control a digger. For your task, you have been given a 'map' of all the underground resources in the mine. This map comes as a two-dimensional integer array. The array has n rows and k columns. Each integer is between zero and one hundred (inclusive). This array represents a grid map of the mine – with each row representing a different height level. Each square in the grid can contain valuable resources. The value of these resources can go from zero (no resources) to 100 (max resources). The grid maps the resources just below the surface, and down to the lowest diggable depths. The digger starts at the surface (so, just on top of the topmost row in the grid)—at any horizontal position between 1 and k. The digger cannot dig directly downwards, but it can dig diagonally in either direction, left-down, or right-down. In its first time-step, it will dig onto the first row of the grid. In its second time-step, it'll hit the second row, and so on. When the digger reaches row number n, it has to be air-lifted out of the mine, and is no longer usable. Every time the digger hits a square with resources in it, it collects those resources. We want to find out the maximum number of resources a digger can collect from this mine in one run. Let’s implement a recursive solution to this problem, reducing the problem of finding the maximum number of resources reachable from any point in the grid to finding the maximum number of resources that can be achieved by moving down-left, then finding the maximum number of resources by moving down-right, and selecting the highest of the two.       Task 2.1 Recursive maxResources: Let’s write a method called maxResources. This method will take a two-dimensional integer array as input and produce one integer output. The input represents the grid map of the mine and the integer output should be equal to the maximum amount of resources that can be collected by a digger in a single run. We want to have a method that is implemented recursively, so it may be useful to implement a version with additional inputs to allow it to keep track of which cell it is looking at. The recursive formula should define maxResources for a particular coordinate (x,y) as the sum of the number of resources in (x,y) and the value o.   Task 2.2 maxResourcesM: If you have implemented the maxResources method and tried testing it with large input sizes, you may have noticed that it starts to run very slowly after a certain depth. This is because the time complexity of the maxResources method is very large, close to O(2n ). Let’s improve this method by adding memoization to its implementation. Make a copy of the original maxResources method and call it maxResourcesM. Re-implement this method in a way that would allow it to store the results of previous calls and use those when the same calls are made again.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

You have been hired at an open-air mine. You are to write a program to control a digger. For your task, you have been given a 'map' of all the underground resources in the mine. This map comes as a two-dimensional integer array. The array has n rows and k columns. Each integer is between zero and one hundred (inclusive). This array represents a grid map of the mine – with each row representing a different height level. Each square in the grid can contain valuable resources. The value of these resources can go from zero (no resources) to 100 (max resources). The grid maps the resources just below the surface, and down to the lowest diggable depths. The digger starts at the surface (so, just on top of the topmost row in the grid)—at any horizontal position between 1 and k. The digger cannot dig directly downwards, but it can dig diagonally in either direction, left-down, or right-down. In its first time-step, it will dig onto the first row of the grid. In its second time-step, it'll hit the second row, and so on. When the digger reaches row number n, it has to be air-lifted out of the mine, and is no longer usable. Every time the digger hits a square with resources in it, it collects those resources. We want to find out the maximum number of resources a digger can collect from this mine in one run. Let’s implement a recursive solution to this problem, reducing the problem of finding the maximum number of resources reachable from any point in the grid to finding the maximum number of resources that can be achieved by moving down-left, then finding the maximum number of resources by moving down-right, and selecting the highest of the two.

 

 

 

Task 2.1 Recursive maxResources:

Let’s write a method called maxResources. This method will take a two-dimensional integer array as input and produce one integer output. The input represents the grid map of the mine and the integer output should be equal to the maximum amount of resources that can be collected by a digger in a single run. We want to have a method that is implemented recursively, so it may be useful to implement a version with additional inputs to allow it to keep track of which cell it is looking at. The recursive formula should define maxResources for a particular coordinate (x,y) as the sum of the number of resources in (x,y) and the value o.

 

Task 2.2 maxResourcesM:

If you have implemented the maxResources method and tried testing it with large input sizes, you may have noticed that it starts to run very slowly after a certain depth. This is because the time complexity of the maxResources method is very large, close to O(2n ). Let’s improve this method by adding memoization to its implementation. Make a copy of the original maxResources method and call it maxResourcesM. Re-implement this method in a way that would allow it to store the results of previous calls and use those when the same calls are made again.

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education