If memory use is the problem, write the numbers to a file, call the program
sort to sort the file, then read the median, 25th and 75th percentile from the appropriate line. Sure, this will take more time (sorting is
N log N, finding the Nth element can be done in linear time), but
sort knows how to deal with low memory (
sort was written when 1Mb of memory was an awful lot, and out of reach for most).
Sorting 30m numbers took a couple of minutes on my aging box, but once sorted, you can quickly any percentile query.