added check for sorted array
removed comments
added explanation and complexities