Question: import java.util.Arrays; import java.util.Scanner; public class DynamicProgrammingAlgorithm { public static int mapMinPath ( int [ ] [ ] map, int N ) { int [

import java.util.Arrays;
import java.util.Scanner;
public class DynamicProgrammingAlgorithm {
public static int mapMinPath(int[][] map, int N){
int[][] map1= new int[N][N];
// Initialize the DP array
for (int i =0 ; i < map1.length ; i++){
for(int j =0 ; j < map1[i].length ; j++){
map1[i][j]= Integer.MAX_VALUE;
}
}
map1[0][0]= map[0][0];
// Fill the dp table
for (int i =0; i < N; i++){
for (int j =0; j < N; j++){
if (i >0){
map1[i][j]= Math.min(map1[i][j], map1[i -1][j]+ map[i][j]); //up
}
if (j >0){
map1[i][j]= Math.min(map1[i][j], map1[i][j -1]+ map[i][j]); // left
}
if (i < N -1){
map1[i +1][j]= Math.min(map1[i +1][j], map1[i][j]+ map[i +1][j]); //down
}
if (j < N -1){
map1[i][j +1]= Math.min(map1[i][j +1], map1[i][j]+ map[i][j +1]); //right
}
}
}
return map1[N -1][N -1];
}
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter the size of map:");
int N = input.nextInt();
int[][]map = new int[N][N];
System.out.println("Enter "+ N*N +" value for the map:");
for (int i =0; i < N; i++){
for (int j =0; j < N; j++){
map[i][j]= input.nextInt();
}
}
System.out.println(mapMinPath(map ,N));
}
}
what is the big o and show me each line the time complexity

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!