algorithm - Reading streamed data into a sorted list -
we know that, in general, "smarter" comparison sorts on arbitrary data run in worst case complexity o(n * log(n)).
my question happens if asked not sort collection, stream of data. is, values given 1 one no indicator of comes next (other data valid/in range). intuitively, 1 might think superior sort data comes in (like picking poker hand 1 one) rather gathering of , sorting later (sorting poker hand after it's dealt). case?
gathering , sorting o(n + n * log(n)) = o(n * log(n)). if sort comes in, o(n * k), k = time find proper index + time insert element. complicates things, since value of k depends on our choice of data structure. array superior in finding index wastes time inserting element. linked list can insert more cannot binary search find index.
is there complete discussion on issue? when should use 1 method or another? might there desirable in-between strategy of sorting every once in while?
balanced tree sort has o(n log n) complexity , maintains list in sorted order while elements added.
Comments
Post a Comment