@@ -0,0 +1,1665 @@
+package com.sunny.grokkingalgorithms.fasttrack.dynamicprogrammingandrecursion;%0A%0A/**%0A * Created by sundas on 6/13/2018.%0A */%0Apublic class CostOfPath %7B%0A%0A  /*%0A  We are given a matrix where each cell denotes the cost at%0A  that cell. So the cost of reaching a cell j from cell i , is sum of all%0A  costs for a path from  i to j, we can move down or right. We have%0A  to find minimum cost from moving from top lect cell to bottom right cell.%0A   */%0A%0A  static  int minCost = Integer.MAX_VALUE;%0A%0A  /**%0A   *%0A   * @param costMatrix%0A   * @param i%0A   * @param j%0A   * @return%0A   */%0A  public static void findMinCost(int%5B%5D%5B%5D costMatrix,%0A                                int i,%0A                                int j,%0A                                int curCost,%0A                                 String path)%7B%0A    path += costMatrix%5Bi%5D%5Bj%5D + %22-%3E%22;%0A    curCost += costMatrix%5Bi%5D%5Bj%5D;%0A    /*%0A    Found bottom node rebound technique%0A     */%0A    if(i == costMatrix.length - 1%0A        && j == costMatrix%5Bi%5D.length - 1)%7B%0A      /*%0A      Reached end%0A       */%0A      if(curCost %3C minCost)%7B%0A        System.out.println(%22Cost: %22 + curCost);%0A        System.out.println(%22Path: %22 + path);%0A        minCost = curCost;%0A      %7D%0A      return;%0A    %7D%0A    if(i+1 %3C costMatrix.length) %7B%0A      findMinCost(costMatrix, i + 1, j, curCost,path);%0A    %7D%0A    if(j+1 %3C costMatrix%5Bi%5D.length) %7B%0A      findMinCost(costMatrix, i, j + 1, curCost,path);%0A    %7D%0A  %7D%0A%0A  /**%0A   *%0A   * @param args%0A   */%0A  public static void main(String%5B%5D args) %7B%0A    int%5B%5D%5B%5D costMatrix = new int%5B%5D%5B%5D%7B%0A        %7B1,3,5,8%7D,%0A        %7B4,2,1,7%7D,%0A        %7B4,3,2,3%7D%0A           %7D;%0A    findMinCost(costMatrix,0,0,0,%22%22);%0A    System.out.println(minCost);%0A  %7D%0A%0A%7D%0A

FInd minimum cost of path fro top left cell to bottom right cell. O(2.pow(n))