Finding neighbor in 2D array using delta - java

I was going through one of the online courses for Data strudcture and Algorithms. There I saw saw a topic "Delta based two dimensional array search". Which describes below:
A techinque to search adjoing array elements of four directions in coordinates of two directions.
Delta value is an array that saves coordinates of four direction in coordinates as well as difference between X and Y.
Delta value is employed to approach the elements located up down left right side of certain element.
As per m understanding, its basically searching neighbors in four directions of a given array. I found couple of good answers on stack overflow:
Finding the neighbors of 2D array
Finding 8 neighbours in 2d Array
Finding a neighbour in a 2d array
More efficient way to check neighbours in a two-dimensional array in Java
Finding neighbours in a two-dimensional array
However I am not clear with the 2nd point "Delta value is an array that saves coordinates of four direction in coordinates as well as difference between X and Y". Can anyone explain what does this point means? Also the stack overflow links that I mentioned above serve the purpose? Thank You

Related

Finding an equation to connect the max number of possible points

I would like to find a way, given a set of any points on a 2 dimensional (or 3 dimensional if possible) plane, to connect as many of these points as possible with an equation, preferably in the form of X^n+BX^n and so on. X being of course a variable, and b and n being any numbers.
This would hopefully work in a way that given say, 50 random points, I would be able to use the equation to draw a line that would pass through as many of these points as possible.
I plan on using this in a compression format where data is converted to X,Y coordinate pairs, the goal is then to create equations that can reproduce these points. The equation would then be stored and the data would be replaced with a pointer to the equation as well as the number to enter into the equation to get the data back.
Any feedback is nice, this is just an idea I thought of during class and wanted to see if it would be possible to implement in a usable format.
To connect n points you need a polynomial of at most degree n-1. You can use Polynomial Regression to form your line.

graph representation with minimum cost (time and space)

i have to represent a graph in java but neither as an adjacency list nor an adjacency matrix..
the basic idea is that if
deg[i]
is that exit degree of vertex i, then its neigboors can store in
edges[i][j] where
i <= j <= deg[i]
, but given that
edges[][]
must be initialized with some values i dont know how to make it differ from an adjacency matrix..
any suggestions?
In my knowledge there are only two ways to represent a graph in a language.
Either Use Adjacency matrix
Or Use Incidence matrix
You can make an incidence matrix like
E1 E2 E3 E4
V1 1 2 1
1 V2 2
1 2 1 V3
1 1 1 2
V4 1 1 2 1
You are fighting against lower bounds on this question. The two main representations of the graph are already very good for their respective use.
Adjacency list, minimizes space. You will be hard pressed to use less memory than 1 pointer per edge. Space: O(V*E). Search: O(V)
Adjacency matrix, is very fast, at the cost of v^2 space. Space: O(V^2). Search: O(1)
So, to make something that is better for both space and time you will have to combine the ideas from both. Also realize will just have better practical performance, theoretically you will not improve O(1) search, or O(V*E) size.
My idea would be to store all the graph nodes in one array. Then for each Node have an adjacency list represented as a bit vector. This would essentially be a matrix like representation, but only for those nodes that exist in the graph, giving you a smaller size than a matrix. Search would be slightly improved over an Adjacency list as the query node can be tested against the bit vector.
Also check out sparse matrix representations.

presort data for balanced quadtree

The PMR Rectangle Quadtree is a quadtree which has an list of (Rectangle) objects in each leaf. This is called a bucket.
The structure of this quadtree is dependent on the order of inserting the elements.
The inventor of that quadtree proposed to achieve a balanced quadtree for data that are in advance known (static), that way that the (rectangles) objects to be inserted should be pre-sorted by x and y coordinates.
What exactly is meant by sorting by x and y coordinates to achieve a balanced quadtree?
Asume we take the SW corner of the rectangle, Does this mean sort by x and if equal x sort by y? Or doest it mean the first elem is the smallest x, the second the smallest y (independent of x) ?
The bible for that topic (Hanan Samet: Multidimensional and Metric Search Structures) does not explain that.
Seems to be a topic where the know how is not really widespread, I have to answer it myself:
The pre sorting order of the elements to be added to the quad tree should be in morton order. ( see also papers from Hanan Samet)
The morton index calculates an int value from given two (x,y) coordinates, in a way that two coordinates close together also have little difference
in their morton index.

JAVA Hole in Grid

I need to find "holes" in a 2D grid in java - can you point me toward the best sort of algorithm to do this?
With the input of the following points:
5,3
5,4
8,4
5,5
6,3
7,3
7,4
6,5
I need to figure out the positions of the "hole" or surrounded space in this grid. I'm a bit lost as to how to do this.
Plot of the points:
Assuming each point is 1x1
This is basically a blob extraction algorithm + a bit extra. Do this:
1) Find the westmost, eastmost, northmost and southmost any solid is placed. Remember them as xmin xmax ymin ymax.
2) Allocate an 2d array of integers (initialized to 0) with those dimensions, and place all solid points in it as the value -1.
3) Make a counter initialized to 1. Scan the 2d array. Every time you find a point that is 0, set it to counter and floodfill counters onto every adjacent point that is not a -1 until you've run out of points to floodfill onto. (To do a floodfill, one way is to keep a set of all points you haven't floodfilled all the neighbours of yet, and iterate over these, adding new points to the set until the set is exhausted -> nothing left to floodfill onto.) Now increment the counter and continue.
4) When you've scanned the whole grid, scan the perimeter. Every time you see a non -1 on the perimeter, mark that blob as not being surrounded (by having an array of bools as long as the number of blobs you found).
5) Every numbered blob you have not marked is surrounded.
Read about blob extraction here: http://en.wikipedia.org/wiki/Blob_extraction

Calculating Manhattan Distance

I'm implementing NxN puzzels in Java 2D array int[][] state. am required to use the Manhattan heuristic in the following way:
the sum of the vertical and horizontal distances from
the current node to the goal node/tile
+(plus)
the number of moves to reach the goal node from the initial position
At the moment I don't know how to go further. Am a beginner in puzzle game programming with 2D arrays so am having trouble to understand certain concepts. How can I write this code in Java?
This is more a math question, but anyways the Manhattan distance is the sum of the absolute values of the horizontal and the vertical distance
int distance = Math.abs(x1-x0) + Math.abs(y1-y0);
More info: http://en.wikipedia.org/wiki/Taxicab_geometry

Categories

Resources