Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Math 230 Proiect I: Mountain Hike Path In this lab you will read a set of topographic (land elevation) data from a 2D array and
Math 230 Proiect I: Mountain Hike Path In this lab you will read a set of topographic (land elevation) data from a 2D array and write a function to compute the path(s) through the mountain:s Background There are many contexts in which you want to know the most efficient way to travel over land. When traveling through mountains (let's say you're walking) perhaps you want to take the route that requires the least total change in elevation with each step you take -call it the path of least resistance. Given some topographic data it should be possible to calculate a "greedy lowest-elevation-change walk" from one side of a map to the other. A Greedy Walk A "greedy" algorithm is one in which, in the face of 3011 2900 2852 2808 2791 2818 too many possible choices, you make a choice that seems best at that moment. For the maps we are dealing with there are many possible paths you could take starting from the "western" side of the map and taking one step forward until you reach the "eastern" 2972 2937 2886 2860 2830 2748 2937 2959 2913 2864 2791 2742 2999 2888 2986 2910 2821 2754 2909 2816 2893 2997 2962 2798 Since our map is in a 2D grid, we can envision a walk" as starting in some in some cell at the left-most edge of the map (column 0) and proceeding forward by taking a "step" into one of the 3 adjacent cells irn the next column over (column I). Our "greedy walk" will assume that you will choose the cell whose elevation is closest to the elevation of the cell you're standing in. (NOTE: this might mean walking uphill or downhill). The overall sum of the changes will be calculated by taking the absolute value of the sum of the changes. Since your code does not know which of the 5 rows will yield the best result, you will calculate 5 sums and then select the smallest value as the best answer. Your program should return the index of each row, and the associated best-sum for that row. Shows a portion of the data. Greedy path shown in green. The diagrams below show a few scenarios for choosing where to take the next step. In the case of a tie with the forward position, you should always choose to go straight forward. In the case of a tie between the two non-forward locations, you should flip a coin to choose where to go. That means you will need to use rand() to make a decision for ties. dev. change elev. change elev elev change 109 9 100 107 7 105 5 09 9 10097 3 055 97 3 100 97 3 055 96 4 00 1055 04 4 Case : smallest change is 5, go fwd- down Case 2: smallest change is 3, go fwd Case 3: smallest change is a tie (3). fwd is an option, so go fwd Case 4: smallest change is a tie (4). choose randomly between fwd up or fwd-down 301 2800 2852 2808 2791 2818 2972 2937 2886 2860 2830 2748 2937 2959 1913 2864 2791 2742 2999 2888 2986 2910 2821 2754 2909 3816 2893 2997 2962/ 2798 Use pathFind.c to start your project. The main() function should not be modified, but the function calcSums(int topog[ROWS][COLS], int sumList[RowS]) will be modified. It should be coded to receive a 2d array as input, calculate the elevation sums, and insert the sums into the array sumList]. Main) will print out the values inserted into sumList] The objective is to use each row of the first column of the 2d array as a starting oint to come up with a sum of absolute value of differences. For each row, a sum will be calculated, therefore, 5 sums must be calculated. Each sum will be placed into the array, sumList #include #include #de fine ROWS 5 #de fine COLS 6 void calcSums (int topog [ROWS] [COLS], int sumList [ROWS] int main() int topography [ROWS] [COLS] - 3011, 2800, 2852, 2808, 2791, 2818, 2972, 2937, 2886, 2860, 2830, 2748, 2937, 2959, 2913, 2864, 2791, 2742, f2999, 2888, 2986, 2910, 2821, 2754, f2909, 3816, 2893, 2997, 2962, 2798 int sumList[ROWS]-(0); int r,C student to implement calcSums */ calcSums (topography, sumList //pass in topography, get back list of elevation sums for (r-0 r
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started