Longest Increasing Path In a Matrix

Longest Increasing Path In a Matrix 

In many real-world problems, navigating through grids and finding optimal paths is a common challenge. One interesting variation of this problem involves finding the longest strictly increasing path within a 2D grid of integers. In this scenario, each cell in the grid contains a non-negative integer, and the objective is to traverse from one cell to another in a way that the values of the cells strictly increase as you move.

The movement is constrained to adjacent cells, either horizontally or vertically, but diagonal moves are not allowed. This problem requires an efficient approach to determine the longest path, making it a compelling topic in the realm of algorithm design and optimization.

Problem: 

You are provided with a 2D grid of non-negative integers. Your goal is to determine the length of the longest path in the grid where the values of the cells strictly increase as you move from one cell to the next.

You can move from a cell to its adjacent cells either horizontally or vertically, but diagonal movement is not allowed.

Problem Breakdown

  1. Input: 2D grid of non-negative integers.
  2. Objective: Find the length of the longest strictly increasing path.
  3. Movement: Can move to adjacent cells (up, down, left, right) but not diagonally.
  4. Constraints: Each move must go to a cell with a strictly greater value.
  5. Goal: Determine the longest path by efficiently exploring the grid.

Constraints

  • 1 <= matrix.length, matrix[i].length <= 100

There are mainly three approach to solve this problem – 

  1. Recursion
  2. Dynamic Programming (Top-Down)
  3. Dynamic Programming (Bottom-up)

1. Recursion

  • Time complexity: O(m∗n∗4m∗n)
  • Space complexity: O(m∗n)

2. Dynamic Programming (Top-Down)

Time & Space Complexity
  • Time complexity: O(n^3)
  • Space complexity: O(n^2)

3. Dynamic Programming (Bottom-Up)

Time & Space Complexity
  • Time complexity: O(m∗n)
  • Space complexity: O(m∗n)

More Articles