My Profile

Keep Up to Date:
Blog RSS
Blog
Forum RSS
Forum
Search

Buy & Sell

Used (Like New) $20

Post New Topic Post Reply
Posted 1 Year, 3 Months ago
swasta
Senior Boarder
Posts: 72
graphgraph
User Offline
 
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.
Posted 1 Year, 3 Months ago
paydayuscf
Senior Boarder
Posts: 79
graphgraph
User Offline
 
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.
 
Copyright © 2006 - Jan 2009 Fun Quizzes Club