Is this considered a valid sorting algorithm?

  • Context:
  • Thread starter Thread starter SlurrerOfSpeech
  • Start date Start date
  • Tags Tags
    Algorithm Sorting
Click For Summary

Discussion Overview

The discussion revolves around the validity of a proposed sorting algorithm that relies on "natural bit flips" to sort a list. Participants explore the theoretical and practical implications of this approach, questioning its efficiency and correctness within the context of sorting algorithms.

Discussion Character

  • Debate/contested
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant proposes a sorting algorithm that checks if a list is sorted and relies on natural bit flips to eventually achieve a sorted state.
  • Another participant questions the feasibility of the algorithm, asking for clarification on "natural bit flips" and whether the algorithm has been tested.
  • A different participant argues that the proposed method is not valid unless one uses an unconventional definition of "valid," highlighting the time complexity concerns and the improbability of achieving a sorted array through random bit flips.
  • Some participants discuss the implications of the algorithm stopping when the array is sorted and whether the sorted array would relate to the original array.
  • One participant suggests that rearranging the list randomly instead of waiting for bit flips could be a faster approach, while another counters that this would lead to a worse time complexity.
  • Concerns are raised about the effectiveness of random rearrangement as a sorting method, with one participant stating it is nearly the worst possible approach.
  • Another participant asserts that the proposed algorithm would not terminate under modern hardware with error checks, further questioning its validity.
  • Ultimately, a participant concludes that the algorithm is not valid and clarifies that it does not operate in O(n) time, but rather O(n!) or worse.

Areas of Agreement / Disagreement

Participants generally disagree on the validity and efficiency of the proposed sorting algorithm, with multiple competing views on its theoretical foundations and practical implications. No consensus is reached regarding its classification as a valid sorting algorithm.

Contextual Notes

Participants express uncertainty regarding the assumptions behind the algorithm's reliance on natural phenomena and the implications of randomness in sorting. The discussion highlights the need for clear definitions of validity and efficiency in sorting algorithms.

SlurrerOfSpeech
Messages
141
Reaction score
11
Let me know if I've invented a valid O(n) sorting algorithm.

Code:
public void Sort ( this List<T> L ) 
{
   // Check every second whether L is sorted
   // Given enough time, natural bit flips will eventually make L sorted
    while ( !L.IsSorted() ) Thread.Sleep(1000); 
}

public bool IsSorted ( this List<T> L ) 
{
    // Returns true or false depending on whether L is in ascending order
   for ( int i = 1, n = L.Length; i < n; ++i ) if ( L[i-1] > L[i] ) return false;
   return true;
}
 
Technology news on Phys.org
Have you tested this sorting method, and does it actually work?
If so, can you explain the concept "natural bit flips"?
 
SlurrerOfSpeech said:
Let me know if I've invented a valid O(n) sorting algorithm.

No, not unless you use a very alternative definition of what "valid" means.

Assuming that you algorithm comprise of waiting for stray cosmic rays and other quantum phenomenon to flip bits and then hope luck will turn it into a sorted array, you may want to ask yourself some questions:
  • How many times will IsSorted be called before the array is sorted? If we call that number M (and ignore the 1 sec sleep) the time-complexity of your algorithm is now O(M*N).
  • If the likelihood of a single bit flip (uncorrected and undetected by the memory subsystem) is p, then what is the likelihood of a sequence of bit flips will produce a sorted array (that is, an array with the same elements as before, but now just in ordered sequence) relative to the likelihood of a different array.
  • Can you express an average M as a function of p and N?
  • Would your "algorithm" be faster if you instead of waiting for natural bit flips just inserted some random numbers here? Would that make sense?
  • Do you know what a standard sorting algorithm look like?
  • Can you see any qualitative difference between such an algorithm and what you are proposing?
  • Have you read up on Bogosort? Even that algorithm have an advantage over yours, can you see what?
 
Thanks to @Filip Larsen (love the Tintin avatar) I now know what "natural bit flips" means.

But then the "algorithm" is not even theoretically correct, as it will stop (if it stops) when the array is sorted.
However, there is no reason to assume that the sorted array will be in any way connected to the original array (except for having the same length).
 
Filip Larsen said:
  • Would your "algorithm" be faster if you instead of waiting for natural bit flips just inserted some random numbers here? Would that make sense?

That makes a lot of sense! Great idea.

Code:
public static void Sort ( this List<T> L )
{
    while ( !L.IsSorted() ) L.RearrageRandomly();
}
 
That would make it a O(n*n!) "algorithm", I think.
 
Rearranging randomly is almost the worst possible sorting algorithm. The only thing worst would be something that maliciously un-sorts it. You need to add something that will actively put it in order.
 
SlurrerOfSpeech said:
Let me know if I've invented a valid O(n) sorting algorithm.
With modern memories and hardware error checks, your algorithm would not terminate as long as the machine it is running on is working.
 
SlurrerOfSpeech said:
Let me know if I've invented a valid O(n) sorting algorithm.

No, for two reasons. One is that this isn't a valid sorting algorithm. Secondly, this isn't an O(n) algorithm. It's O(n!), or worse.

Thread closed.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 3 ·
Replies
3
Views
9K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K