About bubble sort vs merge sort

It’s a trick question. If you just want the maximum, (or indeed, the kth value for any k, which includes finding the median), there’s a perfectly good O(n) algorithm. Sorting is a waste of time. That’s what they want to hear.

As you say, the algorithm for maximum is really trivial. To ace a question like this, you should have the quick-select algorithm ready, and also be able to suggest a heap datastructure in case you need to be able to mutate the list of values and always be able to produce the maximum rapidly.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)