is this compulsory that if want to have frequency by the upper_bound - lower_bound method the array must be sorted?
Frequency of an element
yes, they have to be sorted, otherwise the answer would not be correct, these functions are useful only for sorted arrays
Yes this is because upper_bound and lower_bound are based on binary search algorithms.