What algorithm is this? [closed]

3

Knowing that: [] denotes an array [A|B] extracts the first element of the array in A and the rest of the array in B [X, Y] ++ [Z] creates a concatenated array [X, Y, Z] [ X || X <- [1, 2, 3, 4], X > 2] returns the array [3, 4] (read: create a array with the following [1, 2, 3, 4] values that are greater than 2)

What is the name of this algorithm?

bla([A|B]) -> bla([ X || X <- B, X < A]) ++ [A] ++ bla([ X || X <- B, X >= A]);
bla([]) -> [].
    
asked by anonymous 06.10.2016 / 02:16

1 answer

2

I think this algorithm is Quick Sort.

My implementation in Haskell is very similar to yours, although the statement has not made it clear in what language you are working. An example recursive code (Haskell language):

quicksort [] = []
quicksort (x:xs) = quicksort menor ++ (x : quicksort maior)
  where menor = [y | y <- xs, y <= x]
    maior = [y | y <- xs, y > x]
    
06.10.2016 / 05:47