DFS Anomaly
I wasted hours debugging my DFS Solution and a lesson learned for life that I will never ever use DFS to find shortest path from now onwards.\n \nCode which is 
I wasted hours debugging my DFS Solution and a lesson learned for life that I will never ever use DFS to find shortest path from now onwards.\n \nCode which is finally working:\n```java\nclass Solution {\n    int[][] dp = new int[101][101];\n    boolean[][] visited = new boolean[101][101];\n    int i;\n    int j;\n    \n    public int nearestExit(char[][] maze, int[] entrance) {\n        int m = maze.length;\n        int n = maze[0].length;\n        i = entrance[0];\n        j = entrance[1];\n        int res = dfs(maze, i, j, m, n);\n        return res >= 10001 ? -1 : res;\n    }\n    \n    int dfs(char[][] maze, int row, int col, int m, int n) {\n        \n        if (row < 0 || row >= m || col < 0 || col >= n || maze[row][col] == \'+\' || visited[row][col]) {\n            return 10001;\n        } else if (dp[row][col] != 0) {\n            return dp[row][col];\n        } else if (isExit(row, col, m, n) && !isEntrance(row, col)) {\n            return dp[row][col] = 0;\n        }\n        \n        visited[row][col] = true;\n        int down = dfs(maze, row + 1, col, m, n);\n        int up = dfs(maze, row - 1, col, m, n);\n        int right = dfs(maze, row, col + 1, m, n);\n        int left = dfs(maze, row, col - 1, m, n);\n        visited[row][col] = false;\n        \n        return dp[row][col] = Math.min(Math.min(up, down), Math.min(left, right)) + 1;\n    }\n    \n    boolean isExit(int row, int col, int m, int n) {\n        if (row == 0 || row == m - 1 || col == 0 || col == n - 1) { \n            return true;\n        } else {\n            return false;\n        }\n    }\n    \n     boolean isEntrance(int row, int col) {\n        if (row == i && col == j) { \n            return true;\n        } else {\n            return false;\n        }\n    }\n}\n```\n\nBut if I change the order of traversal to child nodes for example:\n```java\n int up = dfs(maze, row - 1, col, m, n);\nint right = dfs(maze, row, col + 1, m, n);\nint down = dfs(maze, row + 1, col, m, n);\nint left = dfs(maze, row, col - 1, m, n);\n```\n**Boom it fails for some of the testcases.**\n\nThings I know about this problem:\n- Unweighted graph\n- Cyclic graph\n- Only One SCC(Strongly Connected Component)\n\nBut can someone give me a proof that why DFS will never work(well I think it was just a luck that all the testcases happend to pass for one particular order but there is no gaurantee that DFS will work in this kind of problem).
['Dynamic Programming', 'Depth-First Search', 'Breadth-First Search', 'Graph', 'Recursion', 'Java']