Question: Consider a situation where your data is almost sortedfor example you are receiving time-stamped stock quotes and earlier quotes may arrive after later quotes because
Consider a situation where your data is almost sorted—for example you are receiving time-stamped stock quotes and earlier quotes may arrive after later quotes because of differences in server loads and network traffic routes. Focus only on the time-stamps. To simplify this problem, assume that each time-stamp is an integer, all time-stamps are different, and for any two time-stamps, the earlier time-stamp corresponds to a smaller integer than the later time-stamp. The time-stamps arrive in a stream that is too large to be kept in memory completely. The time-stamps in the stream are not in their correct order, but you know that every time-stamp (integer) in the stream is at most hundred positions away from its correctly sorted position. Design an algorithm that outputs the time-stamps in the correct order. You can only a constant amount of storage , i.e., the memory used should be independent of the number of time-stamps processed. As a second requirement: your algorithm should use a linked list and NOT a heap.
Step by Step Solution
3.46 Rating (166 Votes )
There are 3 Steps involved in it
To tackle this problem of sorting a nearlysorted stream of integers where each integer is at most 100 positions away from its correct sorted position ... View full answer
Get step-by-step solutions from verified subject matter experts
