Find a perfect matching or proof that it's impossible [closed] - algorithm

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have to either give a tiling of the figure below by dominoes, or give a proof that it is impossible.
I think to achieve this I have to find a perfect matching of the asociated graph of the figure (every space is a node of the graph and they are connected by edges in the vertical and horizontal way). So the graph is undirected and not bipartite. The number of nodes is 42, so could be possible due to there are an even number of nodes, but I think it's not possible. I thought about the definition that a graph has a perfect matching iff |V|=2·v(G) (where v(G) is the matching number of the graph).
Could you help me to find the tiling if it's exists or continue the proof that it's not possible?

According to Hall's matching theorem, if you choose any subset from one "part" of bipartite graph and the number of vertices adjacent to vertices of this subset is smaller than the subset size, there is no perfect matching.
If we choose 11 green tiles as shown below, we get only 10 adjacent tiles for them. Which means there is no perfect matching and you cannot cover the figure by dominoes.

That is impossible.
Each domino tile consists of one even and one odd square.
Blue area contains equal quantity of odd and even squares.
Yellow squares are even, green are odd.
Consider set of domino tiles that have at least one square inside Blue+Yellow area.
They may also cover some squares in green area.
But in any case it is impossible to equate number of even and odd squares for this set of domino tiles.

I chose to attack this problem using proof by cases. I haven't reached the end of each case, but the work so far suggests that every possibility leads to a dead end, so I think the tiling should be impossible. Have fun filling out the rest of the proof. =)

Related

Approximation for random coloring graph with 2 colors [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
Having trouble figuring out how to show this approximation, hoping someone could lend some advice. I'm quite new to approximation (especially with randomization) and having trouble figuring out how to narrow this down.
The problem:
Suppose we have a graph G = (V,E), each edge with a weight w.
We want to color the graph with 2 colors, red and blue. We want to maximize the edge weight from each vertex from red to blue.
We randomly mark each vertex with either red or blue with probably 1/2 for each. The coloring is done independently of every vertex.
I need to show that this color assignment randomization algorithm is a 4-approximaton. However, not entirely sure where to start. Anyone have any ideas?
Even the simplest greedy algorithm will produce better approximations than randomly assigning colors.
Like this:
Mark all nodes uncolored
Mark all edges unprocessed
Sort edges into decreasing weight
LOOP until all edges processed
Select heaviest unprocessed edge
IF both nodes uncoloured
color nodes on edge opposite colors
IF one node uncolored
color node opposite color to its partner
mark edge processed
ENDLOOP

Algorithmic question: Best angle to view trees from fixed camera [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I was asked this question in an interview, have no clue how to solve it.
"Given a fixed camera in a forest (with predefined trees), give the best angle in which the camera pictures the maximum of trees"
How would you approach it or at least what questions would you ask to get more requirements?
If trees don't obscure over trees then:
Sort all trees by angle around the camera position.
Use sliding window approach to find direction to look at.
If trees can obscure other trees then the second step is a bit trickier.
the idea is this:
convert the list of tree coordinates to a list of angles.
sort the list of angles
use a sliding window to find the starting and ending indices that maximize the number of trees.
note: because the best angle to position the camera might actually be very near the 360 degree, you need to take into account trees on the other side of the 360/0 line. The easiest way to handle that is to add duplicate trees to the list (in step 2) with a 360 shift. for example, a tree in degree 10 would be added twice, at degree 10 and 360+10. you don't actually need to add ALL the trees twice - you only really need to duplicate trees in the range 360+camera_angle, but its easy to just duplicate all the trees and it doesn't hurt.

A* Heuristic implementation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am creating a program to solve this puzzle in the lowest cost
The sliding-title puzzle consists of three black titles, three white titles, and an empty space in the configuration shown in the Figure.
WWW_BBB
The goal of the puzzle is to get all white tiles to the right of the
black tiles while the location of the space does not matter
The puzzle has two legal moves(i.e. actions) with associated costs:
• A title may move into an adjacent empty location. – This has a step cost of
• A title can hop over one or two other tiles into the empty position.
– This has a step cost equal to the number of tiles jumped over.
I am having troubles understand how to create a Heuristic algorithm to be implemented in the algorithm.
I understand the implementation of Dijkstra's algorithm within this problem, but can't figure out how to then make it into the A* algorithm.
Assuming you want to use A* on the graph of puzzle states with edges to the states reachable through one of the two rules, then a good heuristic to use would be the number of inversions: https://en.wikipedia.org/wiki/Inversion_(discrete_mathematics)
That's the number of W,B pairs that are out of order (assuming that the relative order of same-colored tiles doesn't change). The W's and B's are in order when the number of versions is 0, and the number of inversions fixed by each type of move is less than or equal to its cost. Therefore the number of inversions as a heuristic will never overestimate the cost of the best sequence.

What is the shortest path that touches every tile in a square grid? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Suppose a ant is placed on the position (0,0) of a chess-board. That ant wants to walk through every single tile of the board, while walking the least it can to do so. What path it must follow? Is there a formula F(i) that returns the position of the ith tile on that path?
Edit: as requested, I've tried the following:
I tried googling for keywords such as "shortest path", "shortest path in square grid", but couldn't find anything relevant.
I then downloaded, configured and used a Traveling Salesman Problem solver in a square grid. Obviously, the solution wasn't satisfactory, but I could gain an insight on the problem. There is an illustration of my results:
I then, intuitively, speculated wether the answer could be something like the Hilbert Curve: . I googled about it and asked on a IRC programming channel, but I couldn't find any actual evidence this is better than spirals and similars, nor a proof this is the best possible solution.
EDIT 2: Further clarifications:
The ant can move diagonally. The distance refers to the euclidean length of the line defined by the path.
Walk in straight line, with the edge of the board on your left, until you either hit the edge of the chess board or a tile you have visited before. If you do, then take a right.
Or a thousand other obvious patterns.
Any path that takes 63 steps is the minimum and just as good as any other path.
This is going to depend on if you're taking the width of each square into consideration or is this just a double array question?
If we're talking a double-array question f(x,y), then the answer is that there is no least path because the ant will need to travel to each square f(x,y) = x*y, so f(8,8) = 64.
If we start taking the width of the tiles themselves into consideration, then the answer is somewhat different because we can use some strategies to get the least amount of distance traveled (such as starting in the center, staying by the grid separators and walking in a roughly spiral pattern r=xy^(theta)).

how to fit polygon inside another polygon [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have two polygons as shown in the image below.
The left one is "rough polygon" and the right one is "final polygon"
Now, I'm looking for algorithm to fit "final polygon" inside "rough polygon" with best maximum scale.
you can rotate as well as translate "final polygon" as much as you want.
you can't perform individual x dimension or y dimension scaling.
you can only perform uniform scaling (where value of Sx and Sy are same).
Here is a possible line of attack for an exact solution by exhaustive trials; just ideas.
My guess is that a solution is achieved when there are three contacts. I mean three vertexes of either polygon touching an edge of the other or conversely. (If there are less than three contacts, you can inflate the internal polygon so that it comes into a third contact.)
Given two arbitrary triangles, it shouldn't be so difficult to find all possible three-contact positions.
So the global scheme is to take all triples of vertexes/sides from one polygon, and take all complementary triples of sides/vertexes of the other. For every combination, momentarily consider that you have triangles and find the possible three-contact positions. For for every candidate position check if the inner polygon stays confined in the outer one. In the end, keep the admissible solution with the largest scale factor.
For polygons with N and M sides, there will be O(N³M³) configurations to try, and the containment test can be as costly as O(NM). So this approach is only viable for very small polygons.
Scale the rightside polygon by 0.01. (geometrical)
Start spinnning it so fast that it draws circle. (geometrical)
Start incrementing the scale 0.01 by 0.01. (geometrical)
Stop when it touches the outer polygon. (geometrical)
Then bounce it to opposite direction until it bounces again. (physical)
Again and again.(iterations)
Until it cannot move/bounce again.(stuck optimally) (physical)
Use simulated annealing in case of false local solutions.(you need global solution)

Resources