How to resolve the algorithm Sorting algorithms/Bogosort step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Sorting algorithms/Bogosort step by step in the J programming language

Table of Contents

Problem Statement

Bogosort a list of numbers.

Bogosort simply shuffles a collection randomly until it is sorted. "Bogosort" is a perversely inefficient algorithm only used as an in-joke.
Its average run-time is   O(n!)   because the chance that any given shuffle of a set will end up in sorted order is about one in   n   factorial,   and the worst case is infinite since there's no guarantee that a random shuffling will ever produce a sorted sequence. Its best case is   O(n)   since a single pass through the elements may suffice to order them.

Pseudocode:

The Knuth shuffle may be used to implement the shuffle part of this algorithm.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sorting algorithms/Bogosort step by step in the J programming language

Source code in the j programming language

bogo=: monad define
  whilst.  +./ 2 >/\ Ry  do. Ry=. (A.~ ?@!@#) y  end. Ry
)


  

You may also check:How to resolve the algorithm Sorting algorithms/Cocktail sort step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Dragon curve step by step in the Vedit macro language programming language
You may also check:How to resolve the algorithm Write entire file step by step in the Python programming language
You may also check:How to resolve the algorithm Camel case and snake case step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Fivenum step by step in the Stata programming language