Difference between revisions of "TI-BASIC:Sorta"
(Initial automated import) |
(Automated superscript correction) |
||
Line 21: | Line 21: | ||
= Algorithm = | = Algorithm = | ||
− | The algorithm used by SortA( and [[TI-BASIC:Sortd|SortD(]] appears to be a modified selection sort. It is still O(n | + | The algorithm used by SortA( and [[TI-BASIC:Sortd|SortD(]] appears to be a modified selection sort. It is still O(n<sup>2</sup>) on all inputs, but for some reason takes twice as long on a list with all equal elements. It is not stable. |
= Related Commands = | = Related Commands = |
Latest revision as of 22:25, 24 February 2016
Command Summary
Sorts a list in ascending order.
For more than one list, sorts the first, and reorders other lists accordingly.
Command Syntax
SortA(list1 [,list2, ...])
Menu Location
Press:
- 2nd LIST to access the list menu.
- RIGHT to access the OPS submenu.
- ENTER to select SortA(.
TI-83/84/+/SE
1 byte
The SortA( command sorts a list in ascending order. It does not return it, but instead edits the original list variable (so it takes only list variables as arguments).
SortA( can also be passed multiple lists. In this case, it will sort the first list, and reorder the others so that elements which had the same indices initially will continue having the same indices. For example, suppose the X and Y coordinates of some points were stored in ∟X and ∟Y, so that the Nth point had coordinates ∟X(N) and ∟Y(N). Then SortA(∟X,∟Y) would sort the points by their x-coordinates, still preserving the same points.
However, SortA( is not stable: if several elements in the first list are equal, then the corresponding elements in the subsequent lists may still end up being in a different order than they were initially.
Algorithm
The algorithm used by SortA( and SortD( appears to be a modified selection sort. It is still O(n2) on all inputs, but for some reason takes twice as long on a list with all equal elements. It is not stable.