Abstract:his paper considers the problem of sorting m×n maze (m>1, n>1 ) and proves an sufficient and necessary condition that anoriginal state can be changed into specified-target state in finite step for m×u maze, then presents a sorting algorithm for m×n maze, its time complexity is O(mn (m+n)), its space complexity is O (mn), finaly, this paper gives a lower bound and shows that the algorithm is optimal where m=n.