This question evaluates algorithmic problem-solving and complexity-analysis skills, focusing on frequency counting and selection techniques within the Coding & Algorithms domain and testing both practical application of efficient data-structure-driven solutions and conceptual understanding of time/space trade-offs.

Given an integer array nums and an integer k, return any ordering of the k elements that occur most frequently. Achieve O(n log k) time with typical data structures, then improve it to an O(n) expected-time approach that does not use global sorting. Discuss the time and space complexities of your approaches and when each is preferable.