<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.explainxkcd.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=77.179.85.233</id>
		<title>explain xkcd - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://www.explainxkcd.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=77.179.85.233"/>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php/Special:Contributions/77.179.85.233"/>
		<updated>2026-07-09T16:16:07Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=1185:_Ineffective_Sorts&amp;diff=30363</id>
		<title>1185: Ineffective Sorts</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=1185:_Ineffective_Sorts&amp;diff=30363"/>
				<updated>2013-03-13T18:57:40Z</updated>
		
		<summary type="html">&lt;p&gt;77.179.85.233: /* Transcript */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 1185&lt;br /&gt;
| date      = March 13, 2013&lt;br /&gt;
| title     = Ineffective Sorts&lt;br /&gt;
| image     = ineffective_sorts.png&lt;br /&gt;
| titletext = StackSort connects to StackOverflow, searches for 'sort a list', and downloads and runs code snippets until the list is sorted.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
The comic gives examples of four non-functional sorting algorithms written in pseudo python. &lt;br /&gt;
&lt;br /&gt;
The first sort is an unfinished merge sort. The merge sort works recursively by dividing a list in half and performing a merge sort to each half. After the two halves are sorted, they are merged, taking advantage of the fact that the two halves are now in correct order and thus the merge can be done with a minimum number of comparisons. The sort will divide the list until it contains elements of size one, then would begin merging. However, the author of the merge sort in the comic appears to have given up on writing the merge part of the sort. In its current state, the sort would divide the list into elements of size one, do nothing to them, and return the two halves of the original list.&lt;br /&gt;
&lt;br /&gt;
The second sort is a bogosort, a sort that works by randomly shuffling the elements in the list. In a comment, the author claims the sort will run in O(nlog(n)) time, when bogosorts actually run in O(n*n!) time and may never finish. The author cheats this limitation by reporting a fictitious error in the operating system (a &amp;quot;kernel page fault&amp;quot;) if the list isn't ordered after shuffling log(n) times.&lt;br /&gt;
&lt;br /&gt;
The third sort parodies a programmer explaining a quicksort during a job interview. The quicksort works by choosing a index as a pivot value and sorting all elements less than the pivot before the pivot and all the elements greater than the pivot after the pivot. It then does a quicksort to the section less than the pivot and the section greater than the pivot until the whole list is sorted. The interviewee flounders for a little while, then asks whether he can use the standard libraries to call a quicksort. Using the standard library's quicksort would allow the programmer to successfully execute a quicksort, but would not demonstrate that he knows how it works.&lt;br /&gt;
&lt;br /&gt;
The final sort is just a mess. First it checks to see if the list is sorted, and exits if it is. Then it cuts the list 10,000 times (like a deck of cards) and exits if the list is sorted. Next, in desperation, it checks if the list is sorted three times. It then empties the list, tries to shutdown the computer and attempts to delete first the current directory, second the user's home directory, and finally the entire file system. rm is a POSIX command; the -r and -f flags mean that the remove command will remove all contents of the specified directories and will not prompt the user beforehand. The program next runs rd, the windows equivalent of rm, in an attempt to delete the &amp;quot;C:&amp;quot; drive. The /s flag does the same thing as -r and the /q flag does the same thing as -f. Finally, the program returns a list containing the numbers one through five in order.&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
 define HalfheatedMergeSort(list):&lt;br /&gt;
     if length(list)&amp;lt;2:&lt;br /&gt;
         return list&lt;br /&gt;
     pivot=int(length(list)/2)&lt;br /&gt;
     a=HalfheartedMergeSort(list[:pivot])&lt;br /&gt;
     b=HalfheartedMergeSort(list[pivot:])&lt;br /&gt;
     // ummmmm&lt;br /&gt;
     return [a,b] // Here. Sorry.&lt;br /&gt;
&lt;br /&gt;
 define FastBogoSort(list):&lt;br /&gt;
     // An optimized BogoSort&lt;br /&gt;
     // Runs in O(n log n)&lt;br /&gt;
     for n from 1 to log(length(list)):&lt;br /&gt;
         shuffle(list):&lt;br /&gt;
         if isSorted(list):&lt;br /&gt;
             return list&lt;br /&gt;
     return &amp;quot;Kernel Page Fault (Error code: 2)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 define JobInterviewQuicksort(list):&lt;br /&gt;
     Ok so you choose a pivot&lt;br /&gt;
     Then divide the list in half&lt;br /&gt;
     for each half:&lt;br /&gt;
         check to see if it's sorted&lt;br /&gt;
             no, wait, it doesn't matter&lt;br /&gt;
         compare each element to the pivot&lt;br /&gt;
             the bigger ones go in a new list&lt;br /&gt;
             the equal ones go into, uh&lt;br /&gt;
             the second list from before&lt;br /&gt;
         hang on, let me name the lists&lt;br /&gt;
             this is list A&lt;br /&gt;
             the new one is list B&lt;br /&gt;
         put the big ones into list B&lt;br /&gt;
         now take the second list&lt;br /&gt;
             call it list, uh, A2&lt;br /&gt;
         which one was the pivot in?&lt;br /&gt;
         scratch all that&lt;br /&gt;
         it just recursively calls itself&lt;br /&gt;
         until both lists are empty&lt;br /&gt;
             right?&lt;br /&gt;
         not empty, but you know what I mean&lt;br /&gt;
     am I allowed to use the standard libraries?&lt;br /&gt;
&lt;br /&gt;
 define PanicSort(list):&lt;br /&gt;
     if isSorted(list):&lt;br /&gt;
         return list&lt;br /&gt;
     for n from 1 to 10000:&lt;br /&gt;
         pivot=random(0,length(list))&lt;br /&gt;
         list=list[pivot:]+list[:pivot]&lt;br /&gt;
         if isSorted(list):&lt;br /&gt;
             return list&lt;br /&gt;
     if isSorted(list):&lt;br /&gt;
         return list:&lt;br /&gt;
     if isSorted(list): //this can't be happening&lt;br /&gt;
         return list&lt;br /&gt;
     if isSorted(list): //come on come on&lt;br /&gt;
         return list&lt;br /&gt;
     // oh jeez&lt;br /&gt;
     // i'm gonna be in so much trouble&lt;br /&gt;
     list=[]&lt;br /&gt;
     system(&amp;quot;shutdown -h +5&amp;quot;)&lt;br /&gt;
     system(&amp;quot;rm -rf ./&amp;quot;)&lt;br /&gt;
     system(&amp;quot;rm -rf ~/*&amp;quot;)&lt;br /&gt;
     system(&amp;quot;rm -rf /&amp;quot;)&lt;br /&gt;
     system(&amp;quot;rd /s /q C:\*&amp;quot;) //portability&lt;br /&gt;
     return [1,2,3,4,5]&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&amp;lt;!-- Include any categories below this line--&amp;gt;&lt;/div&gt;</summary>
		<author><name>77.179.85.233</name></author>	</entry>

	</feed>