number of reversals = (n^2-1)/3 number of swaps = n(n-1)/2 n = length of array (this is more efficient than n^2 smh) (depending on the nested loops the time complexity could be n^3 idk) update: the time complexity for this algorithm is O(n^2)
One of the most inefficient but systematic ways of reversing an array of length 2^k. It relies on a pre-defined set of instructions of length n-1 where n is the length of the array = 2^k(k is input by the user). These instructions tell the program the block size to reverse. Since this method of reversal doesn't depend on RNG, its computational time can be easily predicted beforehand through a short benchmark. UPDATE: Removed the dependency of the algorithm on the instructions list, thus, subsequent block sizes to reverse can now be calculated instead of referenced. + Benchmark components: Measures the time taken by swaps(1st part) and variable actions(2nd part). The number of swaps necessary are calculated by the formula n(n-1)/2 and variable actions are calculated by the formula 3n^2 + 4n - 7 - log2(n).