-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Given a matrix, sort the rows (either in ascending or descending order) based on the values of column (column index given as an input to the function). #159
Comments
@pbiswas101 Similarly, this can be extended to sorting the columns of a matrix based on a row index. For example , given matrix Sorting the rows by last column gives. M = [[3 2 1] |
@chichra can you be more specific on this:
I mean are you talking about just swapping two rows? and how do the sorting works? In the example you mentioned, what if the last row was |
@pbiswas101 I suppose, she is talking about swapping the two rows. If the last row was [ 3 4 7 ], please look at the below example. M = Sorting the rows by last column gives. There is no swapping required in the above scenario. |
For sorting rows by a column number let say 2, we have to look upon sorting the numbers in the given column. And accordingly the rows are swapped. Sorting rows by 1 column gives: Since numbers in first column are 3 4 3 sorted = (3 3 4), we have Sorting rows by 2 column gives: Since numbers in second column are 2 6 4 sorted = (2 4 6), we have Sorting rows by 3 column gives: Since numbers in third column are 10 7 5 sorted = (5 7 10), we have @chichra I believe this is what you suppose to mean? |
@sakshichahal53 yes absolutely, that is what I wanted. |
@pbiswas101 as I mentioned earlier that similarly, this can be extended to sorting the columns of a matrix based on a row index. For example , given matrix the same matrix, If i wish to sort (rather rearrange) the columns of matrix based on the values of row 1 Original matrix is Sorting the columns by row indices gives. sorted matrix M(based on row 1)= sorted matrix M (based on row 2)= sorted matrix M (based on row 3)= |
I have a doubt: How will this help in competitive programming? |
@chichra will you be working on this issue? |
@pbiswas101 yes |
@chichra okay, how are you planning to implement this? const a = new M.Matrix([ [3, 2, 1], [4, 6, 5], [3, 4, 2] ]) |
a.sort('row', 0) a.sort('column', 0) The first parameter in function signature represents if we want to sort based on row/column and the second parameter denotes the index. |
@chichra this issue is more or less similar to issue #152 and the sorting also need to include both ascending / descending order as mentioned in the PR #169 So, the overall implementation would be: a.sort('row', true, 0) where 2nd and 3rd arguments are optional! If the 3rd argument is to be omitted, then the behavior of sorting would go along as mentioned in issue #152 Hence, once that issue is resolved you may start working on this one, building on top of that implementation. |
Yes, sure. |
Do the checklist before filing the issue:
NOTE: Provide a clear and concise description of the feature that needs to be added! Or if its a bug, then provide the necessary steps to reproduce it along with screenshots.
The text was updated successfully, but these errors were encountered: