* allocation of intermediate arrays outside recursive function