DEV Community

Mujahida Joynab
Mujahida Joynab

Posted on

What is a 2D grid?

Why to learn?
A lot of competitive programming question comes from this topic . To solve dfs we use 2D grid .

Every graph is not tree but every tree is graph

We can up down left and right by 1 unit

DFS on 2D grid

Image description

If we go to the right side - j+1
If we go to the left side - j-1
If we go to up - i - 1
If we go to down - i + 1

Changes -
-1,0
1,0
0,1
0,-1

If we go to eight side To go to konakoni

  • i - 1 , j+1 i+1,j+1 i-1,j-1 i+1,j-1 DFS on 2D grid Implementation

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →