0 оценок0% нашли этот документ полезным (0 голосов)
6 просмотров13 страниц
The document discusses and compares two techniques for sorting cards. Technique 1 involves applying the sorting strategy once per card and has a time complexity of O(n^2) due to needing to move cards up. Technique 2 applies the overall strategy about n log n times, with swaps costing a constant time regardless of step. For large n, Technique 2 has a time complexity of O(n log n) and is much more efficient than Technique 1.
Исходное описание:
Comparing Data Sorting Efficiencies via Cart Sorting
The document discusses and compares two techniques for sorting cards. Technique 1 involves applying the sorting strategy once per card and has a time complexity of O(n^2) due to needing to move cards up. Technique 2 applies the overall strategy about n log n times, with swaps costing a constant time regardless of step. For large n, Technique 2 has a time complexity of O(n log n) and is much more efficient than Technique 1.
The document discusses and compares two techniques for sorting cards. Technique 1 involves applying the sorting strategy once per card and has a time complexity of O(n^2) due to needing to move cards up. Technique 2 applies the overall strategy about n log n times, with swaps costing a constant time regardless of step. For large n, Technique 2 has a time complexity of O(n log n) and is much more efficient than Technique 1.
once per card. Analysis Technique 1 Analysis Technique 1
Late in the sort, we have to move up to
cards to make space on average. This depends on the size of the sorted space. Analysis Technique 1 We apply the strategy times. When applied to the th card in the original set, the strategy (on average) costs time. Analysis Technique 2
For cards, we apply the overall strategy
about times. Analysis Technique 2
Within each step, cards are only swapped
theres no major movement penalty. swaps are possible in each strategy step. Analysis Technique 2
swaps are possible in each strategy step.
This is regardless of which step were in even later steps sum up to roughly . Analysis Technique 2 We apply the strategy times. Each application costs roughly . Comparison When comparing techniques for large , the key part is the largest term. Technique 1: Technique 2: Comparison
Comparison For Technique 1:
Technique 2: (Note that )
Comparison vs thats a ratio of 25000:1. It only gets worse for larger .
The true coefficients (for the
dominant term) are more in favor of Technique 1 but at this scale, Technique 2 still wins, hands-down. Conclusion Note: Technique 1 is more intuitive than Technique 2. Only by studying and research did the more efficient Technique 2 come to be. In short, computer science.