Explain the trade-offs between using a hash map versus a sorted array for counting occurrences in an array.