I am not very sure about the correctness of this procedure.

But my approach would be as follows:

Concept: Maintain a set of numbers in which you maintain the values along 
with its array indices, such that the next number in the sorted output will 
be a part of this set. Consider the set contains elements as tuples (i,j) 
where i,j are the indices of the array of an element. Since, it's a set, we 
shall not maintain duplicate tuples.
 
1. Pick a[0][0] and output it as first element in sorted array.
2. Invariant : Whenever you output any element at a[i][j], then we include 
the elements at a[i+1][j] and a[i][j+1] (checking boundary conditions) in 
the set i mentioned above, along with the indices.
3. Now, find the smallest element in this set and output it. Suppose   it is 
a[i][j], then repeat step 2 and then again step 3, until we find the set 
becomes empty.


Please check if i am missing something here.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to