Code review: What happens if data_elements.size() stays as 0 past line 12?
I think something like finding the mode of a data set is generally O(n log n). You might be able to get that closer to linear time in practice by using a hash set (unordered map), which has O(1) complexity on average (unless it needs to do a rehash).
But a sort + linear traversal may be the fastest method for small-to-medium-sized data sets because of cache locality, which you will not have with a std::map or std::unordered_map. If you're worried about performance, then be sure to measure the difference between implementations on the kind of data you expect to process; everything else is just theory.
Code review: What happens if data_elements.size() stays as 0 past line 12?
An error from trying to access data_elements[0]. Thanks!
I think something like finding the mode of a data set is generally O(n log n). You might be able to get that closer to linear time in practice by using a hash set (unordered map), which has O(1) complexity on average (unless it needs to do a rehash).
But a sort + linear traversal may be the fastest method for small-to-medium-sized data sets because of cache locality, which you will not have with a std::map or std::unordered_map. If you're worried about performance, then be sure to measure the difference between implementations on the kind of data you expect to process; everything else is just theory.
Thanks for the comprehensive insights! I definitely need to learn more about hash sets!