Questions tagged [square-grid]
42 questions
16
votes
1 answer
Are "Flow Free" puzzles NP-hard?
A "Flow Free" puzzle consists of a positive integer $n$ and a set of (unordered) pairs of distinct vertices in the $n \times n$ grid graph such that each vertex is in at most one pair. A solution to such a puzzle is a set of undirected paths in the…
user12859
12
votes
1 answer
Treewidth of k x k square grid graphs
According to some slides I found on google, the treewidth of any $k \times k$ square grid graph $G$ is $tw(G) = k$. I just started researching about treewidth and tree decomposition, and for the most part it makes sense. However, I am particularly…
saltthehash
- 293
- 2
- 7
6
votes
0 answers
Upper bound on the number of hamiltonian cycles on a $n \times n $ grid graph
What is the best upper bound that is known for the number of hamiltonian cycles on a $n \times n $ grid graph?
I did some searching and found that the number of hamiltonian cycles on a planar graph with $n$ vertices is $O(\sqrt[4]{30}^n)$ where $n$…
Gaganpreet
- 161
- 4
6
votes
1 answer
Route on a square grid with only (x,y) → (x,x+y) and (x,y) → (x+y,y) moves
This problem is about finding a route on a square grid.
The starting point is $(1,1)$ and the target point $(n,m)$.
I can move each step from my current point $(x,y)$ either to $(x+y,y)$ or $(x,y+x)$.
Now I need to determine if there is a path from…
Gilad
- 201
- 1
- 7
6
votes
1 answer
Can someone explain this formula for calculating Manhattan distance?
This is from a Kickstart problem:
Note: The Manhattan distance between two squares (r1,c1) and (r2,c2)
is defined as |r1 - r2| + |c1 - c2|, where |*| operator denotes the
absolute value.
Then in the analysis:
Note that the manhattan distance…
Eugene Yarmash
- 275
- 3
- 8
4
votes
1 answer
Maximizing number of selected squares in a grid
We have an $n\times n$ grid of squares, each square has a non-negative integer. Two distinct squares are neighbours if they share a row or column. A selection of squares is good if every selected square has a number of selected neighbours less than…
user26358
4
votes
1 answer
Find a simple cycle in an undirected subgraph of a grid graph that encloses the most faces
Imagine a finite $n*n$ grid graph $G(V,E)$, much like a chessboard. Imagine further an undirected subgraph $H(V',E')$ of $G$. Let us call the squares of chessboard $G$ "faces". A DFS algorithm can detect a simple cycle in $H$ in linear time.…
Nucleonix
- 41
- 4
4
votes
2 answers
Largest N squares that fit in a rectangle
I was working on a project and I needed to display N squares inside a rectangle area and I want them to be as large as possible, no rotations. More formally:
Problem: Given N equal-sized squares and a rectangle with width W and height H, find out…
kunigami
- 141
- 5
4
votes
0 answers
Algorithm to find equivalent classes of homotopic pathes on a grid with obstacles
Given a $n \times n$ grid with some walls and two cells $a$ and $b$, I want to compute the non-homotopics paths from $a$ to $b$ on this grid. A path is a sequence of adjacent cells (diagonal does not count) such that from one cell to another, we…
Johan
- 141
- 3
3
votes
1 answer
Find smallest enclosing circle
On a 2d plane, there is a large circle centered at $(0, 0)$ with a radius of $R_{{o}}$. It encloses $\sim 100$ or so smaller circles distributed randomly across the parent circle otherwise with known radii and positions with respect to the origin.…
Rebel
- 133
- 5
3
votes
0 answers
Algorithm to traverse all unblocked $1*1$ squares in a $n*m$ grid
Given a $n*m$ grid, some $1*1$ squares are blocked(can't be entered) and some are unblocked(can be entered).
What is the algorithm which prints the shortest path, such that the path covers all unblocked $1*1$ squares in a $n*m $ grid ?
The starting…
nequit
- 31
- 8
3
votes
0 answers
Approximation ratio of a greedy grid-cover algorithm
We're given a $N\times M$ grid, and we want to cover all coordinates in the greedy by rectangles of size $\le k$.
Consider the following greedy algorithm. At each iteration, it chooses a rectangle of area $\le k$ which covers as many uncovered…
R B
- 2,644
- 17
- 35
3
votes
2 answers
Maximize enclosed area of given figures on 2d grid
I need to solve an optimization problem for a given set of polyominoes, for example the five Tetrominoes known from Tetris. The goal is to place each one of the figures on the 2d grid, so the area they enclose is maximal.
Staying with our Tetromino…
Tobi
- 153
- 4
3
votes
2 answers
Finding a hamiltonianISH path in a graph
Problem statement
Given a graph of all the blue squares in the following image where each blue square is connected to other blue squares in all 4 cardinal directions.
Given any starting node.
What algorithm will allow for finding the longest(ish)…
snowfrogdev
- 201
- 1
- 8
2
votes
2 answers
Finding the number of squares by connected coordinates
If I have a list of lists as below ,
[[1, 2], [3, 4], [1, 5], [2, 6], [4, 8], [5, 6], [6, 7],
[7, 8], [6, 10], [7, 11], [8, 12], [10, 11],
[10, 14], [12, 16], [14, 15], [15, 16]]
and
[[1, 2], [2, 3], [3, 4], [1, 5], [4, 8],
[6, 7], [5,…
user1411837
- 121
- 1