Welcome to the Party, Pal

Here are some other weird algorithms, just a disclaimer though, all of these can be found on r/ProgrammerHumor:

  1. Schrödinger's Sorting Algorithm

    We are all familiar with Schrödinger's cat, a thought expeiment which involves a hypothetical scenario where a cat is placed in a box with a mechanism that has an equal chance of killing the cat or not, and until the box is opened and observed, the cat is considered both alive and dead simultaneously, in a superposition of states, according to quantum mechanics.

    On the same note, Schrödinger's Sorting Algorithm suggests a sorting algorithm where items are both sorted and unsorted at the same time until observed. It is of course, a joke. An alternate way to comprehend it would be as follows: encrypt the list and until it is decrypted, it will be assumed to be both sorted and unsorted.

    It is a whimsical algorithm but if it were to be expressed as a pseudocode, it may look something like this:

                                    
    function schrodingerSort(arr):
        sorted = checkIfSorted(arr)  // A function that checks if the array is sorted
        if sorted is true:
            return arr  // If already sorted, return the array
        else:
            observe(arr)  // Observe the array to see if it becomes sorted
            return arr
    
    function observe(arr):
        // A magical function that might sort the array or might not, the result is uncertain until observed
        // This function doesn't actually exist and would be a placeholder for the random/satirical behavior of the Schrodinger Sort.
        // It reflects the uncertain nature of the sorting process.
    
    function checkIfSorted(arr):
        for i from 0 to length of arr - 2:
            if arr[i] > arr[i + 1]:
                return false  // Array is not sorted
    
        return true  // Array is sorted
    
                                    
                                
  2. Intelligent Design Sort

    The term "Intelligent Design" (ID) is often associated with the debate about the origins of life and the universe. Please bear this in mind as I describe what this algorithm proposes.

    For a list of size 'n', the probability of it being in the order that it is is 1/n!. For example:

                                        
    list = {2,3,5,6,1}
    Here, n = 5 and there are 120 other possible orders this list could be in which implies that the probability that the list appears as it is 1/120.
                                        
                                    

    At a much grander scale than n=5, the probility becomes so small that , the algorithm posits, it must have been put in this order by an "Intelligent Sorter". The algorithm further states that since this order has been decreed by a "higher power", therefore it must already be optimally sorted in a way that transcends our "mortal" understanding. Additionally, altering the order to fit our definition of sorted would only make it less sorted. Obviously, the algorithm performs in constant time and occupies no additional memory at all which indeed makes it divine.

  3. Sleep Sort

    The sleep sort algorithm uses time delays based on the values of elements in an array to sort them. While it's an interesting concept, it's not an efficient or practical sorting algorithm.

    The idea behind the sleep sort is to utilize the sleep function or a similar time-delay mechanism available in programming languages to sort an array by delaying the output based on the value of each element. Elements in the array are used to determine the duration of the delay before they are printed or appended to a new list.

    Let's take a look at the psudocode to understand it a bit better:

                                        
    sleepSort(array)
        for each element in the array
            create a new thread or process for each element inside each thread/process, sleep for an amount of time based on the value of the element
            after the sleep, output/print the element                                  
                                        
                                    

    This code creates a thread for each element in the array. Each thread sleeps for an amount of time proportional to the value of the element and then prints the element. This results in the elements being printed in ascending order based on their values due to the delay introduced by the sleep function. While it makes sense, sleep sort isn't really used in the real world because its performance is heavily contingent on the value of the elements and it can be very slow or impractical for large arrays or arrays with larger values. To know more about this algorithm, please check out this article.