News for hackers. Stuff that matters.
Re:Not Your Grandmother's Textbook Exercise by umanwizard on Thursday September 01, 2022 @06:50PM (#32684404)
Presumably the list is not ordered adversarially, so you can just use quickselect, at O(n) running time.
Re:Not Your Grandmother's Textbook Exercise by pjscott on Thursday September 01, 2022 @07:51PM (#32684891)
My personnel records are always ordered adversarially, on general principle. :-)

But if you’re willing to assume that none of the ages are more than some reasonable constant bound, like no employees over the age of 65535 or something, then there’s a fun guaranteed O(n) algorithm closely related to counting sort.

Re:Not Your Grandmother's Textbook Exercise by naniwaduni on Thursday September 01, 2022 @11:53PM (#32686399)
I wouldn't really expect your personnel ages to leave the range of an unsigned octet in the foreseeable future. Hell, I'm pretty sure we're not expecting to have personnel exceeding 127yo anytime soon.

(Note, however, that counting occurrences is in principle at least O(log n) space and, without a bit of cleverness, likely O(n log n) time—your integers need to be O(log n) wide to count that big!)

Re:Not Your Grandmother's Textbook Exercise by tantalor on Thursday September 01, 2022 @08:56PM (#32685358)
> counting sort

There's the right answer right there.

I'll add: let the AI handle the details.

  def getMedianAge(person_list):
    # Let copilot fill in rest
Re:Not Your Grandmother's Textbook Exercise by exact_string on Friday September 02, 2022 @08:08AM (#32689616)
You can use the median of medians with quickselect to guarantee the O(N) time complexity.