What is the function alg1 doing from the following code snippet? Provide the complexity analysis of the function.

To be done : documentation with the description of the algorithm and its complexity analysis.

int alg1(int[] a, int b) { int c = 0; int d = a.length - 1; while (d >= c) { int e = alg2(a, c, d, c); if (e == b) { return a[e]; } else if (e < b) { c = e + 1; } else { d = e - 1; } } return -1; } int alg2(int[] a, int b, int c, int d) { int e = a[d]; int f = b; alg3(a, d, c); for (int i = b; i < c; i++) { if (a[i] < e) { alg3(a, i, f); f++; } } alg3(a, c, f); return f; } void alg3(int[] a, int b, int c) { if (b != c) { a[c] = (a[b] = (a[c] = a[b] ^ a[c]) ^ a[b]) ^ a[c]; } }