|
|
swasta
Fresh Boarder
Blog Posts: 0
Forum Posts: 17
Rating: 0  
|
|
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
|
|
|
paydayuscf
Junior Boarder
Blog Posts: 0
Forum Posts: 29
Rating: 0  
|
|
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 Content on this site is provided for general information purposes only. Your use of the Content, or any part thereof, is made solely at Your own risk and responsibility. By entering this site you declare you read and agreed to its Terms, Rules & Privacy.
Copyright © 2006 - 2010 Fun Quizzes Club
|
TIP: Write your question in details [ why? ]
|