Question: 1 - public class DynamicProgrammingAlgorithm { public static int mapMinPath ( int [ ] [ ] map, int N ) { int [ ] [
public class DynamicProgrammingAlgorithm
public static int mapMinPathint map, int N
int map new intNN;
Initialize the map array
for int i ; i maplength ; i
forint j ; j mapilength ; j
mapij Integer.MAXVALUE;
map map;
Fill the map table
for int i ; i N; i
for int j ; j N; j
if i
mapij Math.minmapij mapi j mapij; up
if j
mapij Math.minmapij mapij mapij; left
if i N
mapi j Math.minmapi j mapij mapi j; down
if j N
mapij Math.minmapij mapij mapij ; right
return mapN N ;
class BruteForce
static int N;
static int map;
static boolean visited;
static int minCost Integer.MAXVALUE;
static void bruteForceint row, int column, int cost
cost maprowcolumn;
if row N && column N
minCost Math.minminCost cost;
return;
visitedrowcolumn true;
int dRow ; down
int dColumn ; right
for int i ; i ; i
int newRow row dRowi newColumn column dColumni;
if newRow N && newColumn N && visitednewRownewColumn
bruteForcenewRow newColumn, cost;
visitedrowcolumn false;
write Time complexity
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
