• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

algorithm question

holycow

Senior member
i have an array consist of 10 number(not in sorted order). what kinda algorithm should i use in order to achieve O(lg n) runtime? i'm thinking about using heap, but is there a better way to do it?
 
With only 10 elements, it really doesn't matter....... In fact, a bubble sort could end up faster with such a small dataset because of the simplicity. Especially if you have a lightweight comparison function.

For larger datasets, I would recommend using a priority_queue which does an extremely efficient tree sort, rather than reinventing the wheel.


 
Back
Top