I'm starting to learn about Complexity Analysis and am finding my text a little hard to understand. Could someone please look at the function below and help work through it explaining how the answer is obtained? I really want to understand the "why" for this topic. Any good resources or suggestions for further reading?

Thanks!

int selectkth (int a[], int k, int n){

int i, j, mini, tmp;

for (i=0; i<k; i++){

mini = i;

for (j = i+1; j < n; j++)

if (a[j]<a[mini])

mini=j;

tmp = a[i];

a[i] = a[mini];

a[mini] = tmp;

}

return a[k-1];

}

--------8<--------

#include <iostream>

#include <algorithm>

#include <cstdlib>

#include <ctime>

using namespace std;

int selectkth (int a[], int k, int n){

int i, j, mini, tmp;

for (i=0; i<k; i++){

mini = i;

for (j = i+1; j < n; j++)

if (a[j]<a[mini])

mini=j;

tmp = a[i];

a[i] = a[mini];

a[mini] = tmp;

}

return a[k-1];

}

int main()

{

int a[20];

const int n = sizeof(a)/sizeof(*a);

int k = n/2;

srand(time(0));

generate(a,a+n,rand);

copy(a,a+n,ostream_iterato

int b[n],c[n];

copy(a,a+n,b);

copy(a,a+n,c);

cout << k << "th element from selectkth is: " << selectkth(a,k,n) << '\n';

cout << "a: ";copy(a,a+n,ostream_itera

nth_element(b,b+k,b+n);

cout << "b: ";copy(b,b+n,ostream_itera

partial_sort(c,c+k,c+n);

cout << "c: ";copy(c,c+n,ostream_itera

}

--------8<--------