I found an implementation of algorithm in c++ here https://gist.github.com/andlima/1774060 but I don't understand a purpose of few lines and how they work,
- Should I add an if statement that if n is below certain amount we should just sort an array and return v[k]?
- In 4th line, why we create a variable by increasing it by 4? I understand that we have to divide it by 5 in order to have an amount of little arrays
- What is that "for loop" in 6 line responsible for? Is it for spliting main array into smaller ones which we wanna sort and then create an array of medians? Why there is a swap function and why we split it into if and else conditions?
- Why we delete medians array after calling same function line before
- What is the purpose of for loop in 25 line and this in 33 and also swap in 38?
I'll be really really grateful for any help with this.