Bloggers Wanted
We're looking for people to help with the main blog. If you are consistent, knowledgeable and you're into it, please drop me a note.
|
|
|
|
|
swasta
Senior Boarder
Posts: 72
|
|
Hi all,
As everybody knows, there is a standard algorithm to solve the magic square problem for a grid of size n*n, where n is an odd number. What about solutions for even n?
What is the best solution? (in terms of time complexity)
Thanks, Sheshagiri.
P.S: The magic square problem is: Arrange the numbers 1 through n^2 in an n by n array
|
|
The administrator has disabled public write access. |
paydayuscf
Senior Boarder
Posts: 79
|
|
I have a two different magic square C programs that solve this problem for any n. There are three separate cases, n is odd, n is a multiply of 4, n is even but not a multiple of 4. Both of them use a different algorithm for each case and all the algorithms run in time O(n^2) which is the asymptotically optimal complexity (n^2 is an obvious lower bound since there are n^2 entries to be printed out).
The two C programs are available from the following page (just scroll down until you get to the magic square stuff). Also grab the text file description of the various algorithms because the code is indecipherable without it (it's not exactly easy to read even with the description).
|
|
The administrator has disabled public write access. |
|
|
|