"Check Is Sorted" algorithm