Lagrange's four-square Implementation - algorithm

I am learning about Lagrange theorem , According to which every number can be represent a sum of square , But how do i implement this algorithm , i have search the web but i could not find any relevant material on this. Can anyone help me implement this algorithm or provide some reference ?

It doesn't look like there's an easy answer for this. Here are some references I think will help, though.
https://math.stackexchange.com/questions/483101/rabin-and-shallit-algorithm
https://cs.stackexchange.com/questions/2988/how-fast-can-we-find-all-four-square-combinations-that-sum-to-n

Related

Precalculate Result of A*

Currently learning about the A* search algorithm and using it to find the quickest solution to the N-Puzzle. For some random seed of the initial starting state, the puzzle may be unsolvable which would result in extremely long wait times until the algorithm has search the entire search-space and determined there is not solution to the give start state.
I was wondering if there is a method of precalculating whether the A* algorithm will fail to avoid such a scenario. I've read a bit about how it is possible but can't find a direct answer as to a method in which to do it.
Any guidance or options are appreciated.
I think A* does not offer you a mechanism to know whether or not a problem is solvable. Specifically for N-Puzzle, I think this could help you to check if it can be solved or not:
http://www.geeksforgeeks.org/check-instance-8-puzzle-solvable/
It seems that if you are in a state where you have an odd amount inversion, you know for sure the problem for that permutation is infeasible.
For the N-puzzle specifically, there are only two possible parities, so you just need to check which parity the current puzzle is.
There is an in-depth explanation on how to do this on the math stackexchange
For general A* problems, no, there is no way to pre-compute if the graph is solvable.

HackerRank Maximum Disjoint Subtree Product

Can anybody give me a better explained insight about the problem Maximum Disjoint Subtree Product (link here) ?? I can't figure it out from the psetter analysis.
I don't understand 2nd DFS approach (it tries to calculate the solution for "up subtrees"??)
Please can someone help me and/or give me other problems following the same solution approach ??? I really appreciate other problems like this one. Thanks in advance :D
It seems like a dynamic programming problem. Check out this link before, it contains great tutorial on problems that involve dynamic programming on Trees.

how does galil substring finding algorithm work

I read the galil-seiferas algorithm mentioned in book Handbook of Exact StringMatching Algorithms by Christian Charras and Thierry Lecroq in chapter 28.
according to algorithm the string must be decomposed to two parts but in the example there's no partitioning i think i did't understand the algorithm can any one explain it to me or give and example or at least give a resource.i have to represent it and really need it.giving an example could be very helpful.
tnx

Algorithm to compare images

I'm thinking of writing an app that can compare images: i.e. check if one image exists inside another.
Let's imagine a picture with people, trees and another stuff. Let's imagine another picture of a tree. Is it possible to check if that second picture has some similarity with the trees in the first picture?
I've tried to read bytes and compare them but it didn't work.
What's the best approach to do something like this? What is the algorithm that i should use? And what is the best ( faster ) language to do this?
Thanks in advance.
Look at openCV, follow the link :
http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html#feature-homography
You can use a pHash algorithm from here:http://www.phash.org.
SURF and SIFT are two good algorithms, widely available in libraries for languages of your choice.
It is also instructive to imple.ent them yourself in your preferred language to familiarise yourself with this topic.
You need algorithm similar to fast algorithm of searching substring in a string, but developed to search in 2D space.
For example, here is good solution:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.45.581&rep=rep1&type=pdf
Its complexity is O(n2) in worst case, where n is dimension of big matrix.

Solving puzzle with tree data structure

I am currently following an algorithms class and we have to solve a sudoku.
I have already a working solution with naive backtracking but I'm much more interest in solving this puzzle problem with a tree data structure.
My problem is that I don't quite understand how it works. Is anyone can explain to me the basic of puzzle solving with tree?
I don't seek optimization. I looking for explanation on algorithms like the Genetic algorithm or something similar. My purpose only to learn at this point. I have hard time to take what I read in scientific articles and translate it on real implementation.
I Hope, I've made my question more clear.
Thank you very much!
EDIT: I edit the post to be more precise.
I don't know how to solve Sudoku "with a tree", but you're trying to mark as many cells as possible before trying to guess and using backtrace. Therefore check out this question.
Like in most search problems, also in Sudoku you may associate a tree with the problem. In this case nodes are partial assignments to the variables and branches correspond to extensions of the assignment in the parent node. However it is not practical (or even feasible) to store these trees in memory, you can think of them as a conceptual tool. Backtracking actually navigates such a tree using variable ordering to avoid exploring hopeless branches. A better (faster) solution can be obtained by constraint propagation techniques since you know that all rows, columns, and 3x3 cells must contain different values. A simple algorithm for that is AC3 and it is covered in most introductory AI books including Russell & Norvig 2010.

Resources