Editing Talk:399: Travelling Salesman Problem

Jump to: navigation, search
Ambox notice.png Please sign your posts with ~~~~

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 23: Line 23:
 
:I find it more curious that you think O(n!) is equivalent to O(n log(n))… it most certainly isn’t. O(n log(n)) is (provably) the optimal complexity of a {{w|Comparison sort}}; O(n!) is the complexity of {{w|Bogosort}}, one of the stupidest sorting algorithms imaginable. —[[Special:Contributions/162.158.90.162|162.158.90.162]] 21:23, 23 August 2015 (UTC)
 
:I find it more curious that you think O(n!) is equivalent to O(n log(n))… it most certainly isn’t. O(n log(n)) is (provably) the optimal complexity of a {{w|Comparison sort}}; O(n!) is the complexity of {{w|Bogosort}}, one of the stupidest sorting algorithms imaginable. —[[Special:Contributions/162.158.90.162|162.158.90.162]] 21:23, 23 August 2015 (UTC)
 
::This is so, but when one examines the theory of big O notation, one finds that they are mathemticaly equivalent. The point, therefore, is that the difference is purely in form. To illustrate: A list has O(n!) permutations possible. A sorting algorithm can therefore never sort a worst-case random list with less than O(n!) comparisons, as this is the minimum required to get the list in the correct order for the best case, when we assume the worst possible list for the algorithm. It is possible to prove that O(n!) is O(n log(n)) re-expressed. Therefore the difference seems merely to exist to highlight the general behaviour to humans. Agreed, however, that until the advent of the wavefunction-based "quantum" computer, the bogosort is as bad as it gets. This does not change the fact that any comparison sort must distinguish between O(n!) lists, and therefore can never do that with less than O(n! -1)=O(n!) comparisons. The proof of the n log n barrier rests on this, and n log n is merely a nicer-looking way of writing n! here. Unless I have encountered a flawed proof, this should hold, and even then, the number of possibilities that must be distinguished should bound it... Provided of course that this idea, too, is not logically flawed. If so, how, and if not, then why the notation? Is this somehow applying the same logic that distinguishes a binary sort from a linear one to the set of possible orderings? If so, it must be functionally pre-sorted, by some logic... Where have I erred, if I have erred, and, should I have erred, how might the correct solution be explained?
 
::This is so, but when one examines the theory of big O notation, one finds that they are mathemticaly equivalent. The point, therefore, is that the difference is purely in form. To illustrate: A list has O(n!) permutations possible. A sorting algorithm can therefore never sort a worst-case random list with less than O(n!) comparisons, as this is the minimum required to get the list in the correct order for the best case, when we assume the worst possible list for the algorithm. It is possible to prove that O(n!) is O(n log(n)) re-expressed. Therefore the difference seems merely to exist to highlight the general behaviour to humans. Agreed, however, that until the advent of the wavefunction-based "quantum" computer, the bogosort is as bad as it gets. This does not change the fact that any comparison sort must distinguish between O(n!) lists, and therefore can never do that with less than O(n! -1)=O(n!) comparisons. The proof of the n log n barrier rests on this, and n log n is merely a nicer-looking way of writing n! here. Unless I have encountered a flawed proof, this should hold, and even then, the number of possibilities that must be distinguished should bound it... Provided of course that this idea, too, is not logically flawed. If so, how, and if not, then why the notation? Is this somehow applying the same logic that distinguishes a binary sort from a linear one to the set of possible orderings? If so, it must be functionally pre-sorted, by some logic... Where have I erred, if I have erred, and, should I have erred, how might the correct solution be explained?
::[[Special:Contributions/108.162.249.183|108.162.249.183]] 11:21, 2 September 2015 (UTC)
+
[[Special:Contributions/108.162.249.183|108.162.249.183]] 11:21, 2 September 2015 (UTC)
:::> ''It is possible to prove that O(n!) is O(n log(n)) re-expressed.''
 
:::Then prove it.
 
:::> ''any comparison sort must distinguish between O(n!) lists, and therefore can never do that with less than O(n! -1)=O(n!) comparisons.''
 
:::This suggests to me that you've never written a comparison sort. Here's merge sort in JS:
 
<pre style="margin: 0 6em;">
 
window.comparisons = 0;
 
 
 
function merge_sort(arr) {
 
if(arr.length <= 1) {return arr;}
 
 
 
var left = merge_sort(arr.slice(0, Math.floor(arr.length / 2)));
 
var right = merge_sort(arr.slice(Math.floor(arr.length / 2)));
 
 
 
var lp = 0;
 
var rp = 0;
 
for(var ap = 0; ap < arr.length; ap++) {
 
window.comparisons++;
 
if(rp >= right.length || (lp < left.length && left[lp] < right[rp])) {
 
arr[ap] = left[lp];
 
lp++;
 
}
 
else {
 
arr[ap] = right[rp];
 
rp++;
 
}
 
}
 
return arr;
 
}
 
 
 
console.log(merge_sort([5, 4, 3, 2, 1]), comparisons); //12; log2(5) is 2.3, ceil(2.3 * 5) == 12; 5! is 120
 
window.comparisons = 0;
 
var arr = [];
 
for(var i = 0; i < (1 << 16); i++) {arr[i] = (1 << 16) - i;}
 
console.log(arr); //1 through 65536
 
console.log(merge_sort(arr), comparisons); //1,048,576; log2(65536) is 16, ceil(16 * 65536) == 1,048,576; 65536! is 5*10^287193
 
</pre>
 
:::If what you said was true, modern computer science would collapse. Even if you don't believe me, you have to concede that the mere fact you ''can'' sort 65536 things before the heat death of the universe is proof that you did the math wrong. [[Special:Contributions/173.245.54.28|173.245.54.28]] 03:42, 19 November 2015 (UTC)
 
::1) I think you might be confused on how math works. n! refers to factorial (1*2*3...n). n log n is n multiplied by the logarithm of n.
 
::2) Didn't read all of the rambling, but it seems like you believe a list can only be sorted by brute-force, going over each item and comparing it to the rest of the list. This would in fact be n!. Most sorting algorithms do not use the brute force method since humans are built to recognize patterns and come up with algorithms regarding those patterns. [[User:Flewk|Flewk]] ([[User talk:Flewk|talk]]) 01:13, 28 December 2015 (UTC)
 
 
 
:Actually, it's not O(n!) that is equivalent to O(n log(n)), but O(log(n!)) is. See {{w|Stirling formula}} for details.
 
:Seems your memory just dropped that log. [[Special:Contributions/198.41.242.245|198.41.242.245]] 08:57, 27 June 2016 (UTC)
 
::Thank you to all of ye helpful contributors. I am not sure what led me to write the seed of this (tiredness?), but it is, as noted, a complete and steaming pile of rubbish. [[Duty Calls]], and so forth. I hope I have inadvertently amused someone. Possibly this is a result of abstract mathematics being learned at around four layers of abstraction. Have a good day/night. [[Special:Contributions/162.158.58.141|162.158.58.141]] 09:35, 26 December 2016 (UTC)
 

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)

Templates used on this page: