I need to know if is there any algorithm that allows to know beforehand, without searching for every possible solution to the the initial set, if we can reach a second given set.
For example:
[1,0,2,3,5,6,4,8,7] -> [2,3,4,5,8,0,7,1,6]
This algorithm would return True if the second set is reachable from the first one, and False otherwise.
I thought a bit about it and I can certainly say that if the initial set is solvable (it is possible to put all the squares in order) and so is the second one, then this algorithm would return True, because:
[1,2,3,4,5,6,7,0,8] <-> [1,2,3,4,5,6,7,8,0] <-> [1,2,3,4,5,0,7,8,6]
For any given puzzle that is solvable it can be reversed to obtain the original set.
On the other hand, if one of the sets is solvable and the second one is not solvable the algorithm would surely return False because, if you could reach the solvable set starting on the unsolvable set than we would have a contradiction.
Now, the real problem is when both sets are unsolvable. For some reason I'm positive that given an unsolvable set, it is possible to reach any other unsolvable set configuration, since that's what happens when the set is solvable. But I can't find proof or any documentation on it! Can someone enlighten me?
Since there is a finite amount of board states (9! = 362,880), there is a finite amount of translations between a pair for board states (9!^2 = 131,681,894,400 = 17 GB of information). So brute force once, and be happy for ever.
Related
I have a list L of lists l[i] of elements e. I am looking for an algorithm that finds a minimum set S_min of elements such that at least one member of S_min occurs in each l.
I am not only curious to find a simple algorithm that does this for me, but also to learn what problems of this sort are actually called. I am sure there is something out there
I have implemented brute force algorithms that start with adding all those elements to S_min which occur in sets of len(l[i])=1. The rest is simple trial and error.
The problem you describe ist the vertex cover problem in hypergraphs, an optimization problem which is NP-hard in the general case but admits approximation algorithms for suitably bounded instances.
This is a homework question to start out. I just have some questions before I begin.
Our problem is:
"Reduce from k-Independent Set to 2−SAT as follows. Given a graph G with n vertices form n propositions, one per vertex. Each proposition xi for vertex i is set to true iff the vertex i belongs to an indepdenent set. Now for every edge (u,v) write a clause that says both u and v cannot belong to the independent set."
My question is that everything I read says 2-SAT is not an NP-Complete problem. How can we be reducing from the Independent Set problem then?
There is an important difference between finding any independent set and finding a maximum independent set (independent set of maximum size).
Finding any independent set nicely reduces to 2-SAT, using the reduction you described in your question. Neither problem is NP-complete. Note that the reduction you described in your question does not constrain the number of nodes in the independent set in any way. Even the empty set will satisfy the 2-SAT problem that is produced by this reduction, because the empty set also is an independent set!
Finding a maximum independent set (or k-independent set) however is an NP-complete problem. It does not reduce to 2-SAT.
Or in other words: The k in "k-Independent Set" is an additional constraint that is not part of this 2-SAT reduction (that's why the k is not even mentioned in the description of the reduction). You could add additional clauses to the SAT problem to count the number of included nodes and enforce that this number is at least k, but you can't do that by adding only 2-clauses. So adding the k is the step where your 2-SAT problem becomes an NP-complete general SAT problem.
MAX-2-SAT is an NP-complete extension of 2-SAT that can also be used to solve the maximum independent set problem using the reduction you posted. (You'd need two trivial modifications to the reduction: (1) Add 1-clauses for each proposition and (2) duplicate the 2-clauses for weighting.)
I am trying to prove the following algorithm to see if a there exists a path from u to v in a graph G = (V,E).
I know that to finish up the proof, I need to prove termination, the invariants, and correctness but I have no idea how. I think I need to use induction on the while loop but I am not exactly sure how.
How do I prove those three characteristics about an algorithm?
Disclaimer: I don't know how much formal you want your proof to be and I'm not familiar with formal proofs.
induction on the while loop: Is it true at the beginning? Does it remain true after a step (quite simple path property)?
same idea, induction on k (why k+1???): Is it true at the beginning? Does it remain true after a step (quite simple path property)?
Think Reach as a strictly increasing set.
Termination: maybe you can use a quite simple property linked to the diameter of the graph?
(This question could probably be better answered elsewhere, on https://cstheory.stackexchange.com/ maybe?)
There is a lot of possibilities. For example, for a Breadth First Search, we note that:
(1) The algorithm never visits the same node twice.(as any path back must be >= the length that put it in the discovered pile already.
(2) At every step, it adds exactly one node.
Thus, it clearly must terminate on any finite graph, as the set of nodes which are discoverable cannot be larger than the set of nodes which are in the graph.
Finally, since, give a start node, it will only terminate when it has reached every node which is connected by any path to the start node, it will always find a path between the start and target if it exists.
You can rewrite these logical steps above in deeper rigour if you like, for example, by showing that the list of visited nodes is strictly increasing, and non convergent (i.e. adding one to something repeatedly tends to infinity) and the termination condition must be met at at most some finite value, and a non convergent increasing function always intersects a given bound exactly once.
BFS is an easy example because it has such simple logic, but proving these things for a given algorithm may be extremely tricky.
Consider a 3SAT instance with the following special locality property. Suppose there are n variables in the Boolean formula, and that they are numbered 1,2,3....n in such a way that each clause involves variables whose numbers are within +-10 of each other. Give a linear-time algorithm for solving such an instance of 3SAT.
I could not solve the problem but my intuition is that if we could map the problem in graph then may be solved but could not go much farther ..
This is a relatively straightforward dynamic programming problem. I'll describe a solution, ignoring the fairly straightforward indexing issues around either boundary.
After the m'th step we have the set of possible values for variables (m-10, m-9, ..., m+10) which could be solutions so far, each linked to a set of values for all previous variables that leads to solutions to equations 1..m.
For the m+1'th step we take each member of this possible solution set, ignore the m-10'th value, and consider each possibility for the m+11'th value. If the m+1'th equation is true, we add this to the next solution set, pointing to our history, only if that solution pattern has not already been added.
This lands us ready for the m+2nd step.
There are n steps required, each of which can have about 2 million possible cases to consider, so this is linear.
(Fun challenge. Modify this algorithm to not just find a solution, but to count how many solutions there are.)
I think you can just brute force it in poly time. Divide the clause list into two pieces. Exhaustive search over variables which are on both sides of the split. There are at most 30 of them, so that's 2^30 = O(1) settings to try. Once those variables are set, you can recursively solve both sides, each one is an independent SAT instance with n/2 variables.
from Mexico. The truth is almost never asked or open new issues, because really the forum and not only this, if not to work instead of the network, you can find plenty of information about topic x or y, however this time I feel very defeated.
I have two years of recursion.
Define the following recursive algorithms.
a. Calculate the next n integers.
At first not referred to the master with this is that if the algorithm returns a sum, or set of numbers. Furthermore, although in principle and algorithm design for the second case is asked to resolve by its expression as a recurrence relation ... this is where I am more than lost, not how to express this as a RR. And that can be solved
b. Calculate the minimum of a set of integers
In the other case suppose that calls for the minimum of a set of integers. that's solved, but the fact and pass it to a RR fix, has left me completely flooded.
APPRECIATE ANY HELP, thanks
Answering on b)
You have a set of integers. You pick one and you know that minimal element is either that you've picked or the minimal is still in the set. Recursivly you call function unless you pick all elements from set, you assume that minimum of set that contain no elements is infinity. Then your recurrence is going back updateing the minimal value.
minimum (S) = min(any element, minimum(Rest of S))
if (S is empty) then minimum(empty) = infinity.
Not an implementation in any language cause surely depend on representation of set.
P.S why doing this recursivly?