<?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=Kazim27</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=Kazim27"/>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php/Special:Contributions/Kazim27"/>
		<updated>2026-04-25T19:17:22Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3026:_Linear_Sort&amp;diff=359819</id>
		<title>3026: Linear Sort</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3026:_Linear_Sort&amp;diff=359819"/>
				<updated>2024-12-18T14:19:53Z</updated>
		
		<summary type="html">&lt;p&gt;Kazim27: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3026&lt;br /&gt;
| date      = December 18, 2024&lt;br /&gt;
| title     = Linear Sort&lt;br /&gt;
| image     = linear_sort_2x.png&lt;br /&gt;
| imagesize = 385x181px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = The best case is O(n), and the worst case is that someone checks why.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created in Θ(N) TIME by a recursive Bubble Sorter working on a multidimensional array - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
A common task in programming is to sort a list, a list being a collection of related elements of data that are stored in a linear fashion. There are dozens of algorithms that have been created through the years, from simple to complex, and each has its own merits with regards to how easy it is to understand / implement vs. how efficient it operates on the data.&lt;br /&gt;
&lt;br /&gt;
The efficiency of an algorithm is measured in terms of O(), commonly referred to as &amp;quot;Big-O&amp;quot;, which classifies the amount of time needed to execute the algorithm with respect to the size of the data. Specifically, the Big-O assignment describes the change in execution time when the size of the data set changes (typically, when it doubles). There are various measures of efficiency, such as:&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;&amp;lt;i&amp;gt;O&amp;lt;/i&amp;gt;(1)&amp;lt;/b&amp;gt; - Constant, which means the execution time is independent of the size of the data&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;&amp;lt;i&amp;gt;O&amp;lt;/i&amp;gt;(&amp;lt;i&amp;gt;n&amp;lt;/i&amp;gt;)&amp;lt;/b&amp;gt; - Linear, which means the execution time varies in direct proportion to the size of the data&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;&amp;lt;i&amp;gt;O&amp;lt;/i&amp;gt;(&amp;lt;i&amp;gt;n&amp;lt;/i&amp;gt; log &amp;lt;i&amp;gt;n&amp;lt;/i&amp;gt;)&amp;lt;/b&amp;gt; - &amp;quot;&amp;lt;i&amp;gt;n&amp;lt;/i&amp;gt; log &amp;lt;i&amp;gt;n&amp;lt;/i&amp;gt;&amp;quot;, usually assigned to the fastest sorting algorithms&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;&amp;lt;i&amp;gt;O&amp;lt;/i&amp;gt;(&amp;lt;i&amp;gt;n&amp;lt;/i&amp;gt;&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;)&amp;lt;/b&amp;gt; - Quadratic&amp;quot;, meaning the execution time is proportional to the square of the size of the data.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
An algorithm that sorts data in Linear time would be a fantastic discovery, as the best general-purpose sorting methods are &amp;quot;&amp;lt;i&amp;gt;n&amp;lt;/i&amp;gt; log &amp;lt;i&amp;gt;n&amp;lt;/i&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In computer science, the complexity of a problem can be described using {{w|Big O Notation}}. Operations generally take longer when they act on more elements (notated as &amp;quot;n&amp;quot;). A linear algorithm would be very simple: each element would take a short amount of time on its own, so the time it takes would be a multiple of the size of the list. For instance, if it takes one second to look at a picture, it would take ten seconds to look at ten pictures. So &amp;quot;look at a list of pictures&amp;quot; is a linear operation and would be described as having complexity O(n).&lt;br /&gt;
&lt;br /&gt;
Sorting is more complex. The time it takes to sort a list of items grows quickly as you add more items to the list. The complexity of sorting algorithms generally ranges from O(n^2) to O(n*log n). For example, one way to sort is to look at all the values to find the first item, then look at all the values to find the second item, and so on until you've positioned every item in the right place. If &amp;quot;looking at a number&amp;quot; takes one second, then you could sort a list of 2 numbers in 4 seconds: look at both numbers, then look at them a second time. Sorting 3 numbers would take 9 seconds: look at all 3 numbers 3 times to find the right position. Sorting a deck of cards this way would take 52*52 seconds = about 45 minutes. You can probably read a card more quickly than that, but the point is that the amount of time it takes to sort a list grows faster the more items you are looking at. This is not the most efficient way to sort, but it gets the job done.&lt;br /&gt;
&lt;br /&gt;
The 'linear' sort here uses the more efficient {{w|merge sort}}, which is linearithmic, taking O(n * log n) time. To give the illusion of taking linear time, it tries to make sure it takes 1e6 units of time (likely milliseconds) per item in the list by sleeping for that length of time minus the time it actually took. This will appear to be linear time for up to very large values of n, since linearithmic time will take a huge value of n to exceed the time buffer given by the `sleep()`.&lt;br /&gt;
&lt;br /&gt;
In other words, sorting 20 items will take 10 times as long as sorting 2 items, because after quickly sorting the two items, you just sit around wasting a huge amount of time until it is as slow as sorting a longer list.&lt;br /&gt;
&lt;br /&gt;
The title text refers to the {{w|Best, worst and average case|best and worst case}} of the sort. The best, average and worst case of a merge sort is O(n log n), but this 'linear' sort is pretending that the best case is O(n). The title text then treats 'worst case' as the worst case for the creator of the algorithm (i.e. someone finds out that the sort isn't actually linear), rather than the worst case of the algorithm.&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:function LinearSort(list):&lt;br /&gt;
::StartTime=Time()&lt;br /&gt;
::MergeSort(list)&lt;br /&gt;
::Sleep(1e6*length(list)-(Time()-StartTime))&lt;br /&gt;
::return&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:How to sort a list in linear time&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Kazim27</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3026:_Linear_Sort&amp;diff=359815</id>
		<title>3026: Linear Sort</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3026:_Linear_Sort&amp;diff=359815"/>
				<updated>2024-12-18T14:12:26Z</updated>
		
		<summary type="html">&lt;p&gt;Kazim27: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3026&lt;br /&gt;
| date      = December 18, 2024&lt;br /&gt;
| title     = Linear Sort&lt;br /&gt;
| image     = linear_sort_2x.png&lt;br /&gt;
| imagesize = 385x181px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = The best case is O(n), and the worst case is that someone checks why.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created in Θ(N) TIME by a BOT - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
In computer science, the complexity of a problem can be described using {{w|Big O Notation}}. Operations generally take longer when they act on more elements (notated as &amp;quot;n&amp;quot;). A linear algorithm would be very simple: each element would take a short amount of time on its own, so the time it takes would be a multiple of the size of the list. For instance, if it takes one second to look at a picture, it would take ten seconds to look at ten pictures. So &amp;quot;look at a list of pictures&amp;quot; is a linear operation and would be described as having complexity O(n).&lt;br /&gt;
&lt;br /&gt;
Sorting is more complex. The time it takes to sort a list of items grows quickly as you add more items to the list. The complexity of sorting algorithms generally ranges from O(n^2) to O(n*log n). For example, one way to sort is to look at all the values to find the first item, then look at all the values to find the second item, and so on until you've positioned every item in the right place. If &amp;quot;looking at a number&amp;quot; takes one second, then you could sort a list of 2 numbers in 4 seconds: look at both numbers, then look at them a second time. Sorting 3 numbers would take 9 seconds: look at all 3 numbers 3 times to find the right position. Sorting a deck of cards this way would take 52*52 seconds = about 45 minutes. You can probably read a card more quickly than that, but the point is that the amount of time it takes to sort a list grows faster the more items you are looking at. This is not the most efficient way to sort, but it gets the job done.&lt;br /&gt;
&lt;br /&gt;
The 'linear' sort here uses a {{w|merge sort}}, which actually as a linearithmic sort: O(nlog n). To give the illusion of taking linear time, it tries to make sure it takes 1e6 units of time (likely milliseconds) per item in the list by sleeping for that length of time minus the time it actually took. This will appear to be linear time for up to very large values of n, since linearithmic time will take a huge value of n to exceed the time buffer given by the `sleep()`.&lt;br /&gt;
&lt;br /&gt;
In other words, sorting 20 items will take 10 times as long as sorting 2 items, because after quickly sorting the two items, you just sit around wasting a huge amount of time until it is as slow as sorting a longer list.&lt;br /&gt;
&lt;br /&gt;
The title text refers to the {{w|Best, worst and average case|best and worst case}} of the sort. The best, average and worst case of a merge sort is O(n log n), but this 'linear' sort is pretending that the best case is O(n). The title text then treats 'worst case' as the worst case for the creator of the algorithm (i.e. someone finds out that the sort isn't actually linear), rather than the worst case of the algorithm.&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:function LinearSort(list):&lt;br /&gt;
::StartTime=Time()&lt;br /&gt;
::MergeSort(list)&lt;br /&gt;
::Sleep(1e6*length(list) - (Time()-StartTime))&lt;br /&gt;
::return&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:How to sort a list in linear time&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Kazim27</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3026:_Linear_Sort&amp;diff=359814</id>
		<title>3026: Linear Sort</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3026:_Linear_Sort&amp;diff=359814"/>
				<updated>2024-12-18T14:05:29Z</updated>
		
		<summary type="html">&lt;p&gt;Kazim27: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3026&lt;br /&gt;
| date      = December 18, 2024&lt;br /&gt;
| title     = Linear Sort&lt;br /&gt;
| image     = linear_sort_2x.png&lt;br /&gt;
| imagesize = 385x181px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = The best case is O(n), and the worst case is that someone checks why.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created in Θ(N) TIME by a BOT - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
In computer science, the complexity of a problem can be described using {{w|Big O Notation}}. Operations generally take longer when they act on more elements (notated as &amp;quot;n&amp;quot;). A linear algorithm would be very simple: each element would take a short amount of time on its own, so the time it takes would be a multiple of the size of the list. For instance, if it takes one second to look at a picture, it would take ten seconds to look at ten pictures. So &amp;quot;look at a list of pictures&amp;quot; is a linear operation and would be described as having complexity O(n).&lt;br /&gt;
&lt;br /&gt;
Sorting is more complex. The time it takes to sort a list of items grows quickly as you add more items to the list. The complexity of sorting algorithms generally ranges from O(n^2) to O(n*log n). For example, one way to sort is to look at all the values to find the first item, then look at all the values to find the second item, and so on until you've positioned every item in the right place. If &amp;quot;looking at a number&amp;quot; takes one second, then you could sort a list of 2 numbers in 4 seconds: look at both numbers, then look at them a second time. Sorting 3 numbers would take 9 seconds: look at all 3 numbers 3 times to find the right position. Sorting a deck of cards this way would take 52*52 seconds = about 45 minutes. You can probably read a card more quickly than that, but the point is that the amount of time it takes to sort a list grows faster the more items you are looking at. This is not the most efficient way to sort, but it gets the job done.&lt;br /&gt;
&lt;br /&gt;
The 'linear' sort here uses a {{w|merge sort}}, which actually as a linearithmic sort: O(nlog n). To give the illusion of taking linear time, it tries to make sure it takes 1e6 (1 million) units of time (likely milliseconds) per item in the list by sleeping for that length of time minus the time it actually took. This will appear to be linear time for up to very large values of n, since linearithmic time will take a huge value of n to exceed the time buffer given by the `sleep()`.&lt;br /&gt;
&lt;br /&gt;
The title text refers to the {{w|Best, worst and average case|best and worst case}} of the sort. The best, average and worst case of a merge sort is O(n log n), but this 'linear' sort is pretending that the best case is O(n). The title text then treats 'worst case' as the worst case for the creator of the algorithm (i.e. someone finds out that the sort isn't actually linear), rather than the worst case of the algorithm.&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:function LinearSort(list):&lt;br /&gt;
::StartTime=Time()&lt;br /&gt;
::MergeSort(list)&lt;br /&gt;
::Sleep(1e6*length(list) - (Time()-StartTime))&lt;br /&gt;
::return&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:How to sort a list in linear time&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Kazim27</name></author>	</entry>

	</feed>