Sorting algorithm method timeout occurred

StackOverflowError: This sketch is attempting too much recursion.

Your problem is twofold – first, this may run for a long time. For arrays of any appreciable size, it could run forever (well, for longer than the life of your laptop). That is because you aren’t biased towards increasing in order – you are actively destroying order with your random swaps. If you started with this list:

0123456798

and ran your sort, the list will become worse.

0129456738

And worse.

5129604783

And worse…

At a certain point you are doing something like calling (int)random(99999) and telling the program to stop when it guesses correctly.

Second problem: recursion. You are calling your function from inside your function each time – you may need to do this a few hundred thousand times. But this increases the stack, and eventually causes a stack overflow.

supernaturalOccurenceSort(0123456798)
   supernaturalOccurenceSort(0129456738)
      supernaturalOccurenceSort(5129604783)
        ...x999999

So, instead you would use a while() loop, not recursion.

Recursion works great for sorting that involves progress – for example, divide and conquer, where at each step you are doing a smaller part of the job, and all the small completed jobs add up to one big job that is complete. That is definitely not the case in your approach.