conduit icon indicating copy to clipboard operation
conduit copied to clipboard

Implement an Insertion-Sort Reducer

Open nikhedonia opened this issue 7 years ago • 0 comments

Sort can be implemented via scan by performing an inserting incoming elements into a vector. To find the right position to insert can be found using a binary search. This approach would lead to a runtime complexity of O(n log n).

potential API:

 range() 
   >> scan( vector<int>{}, sort() )
   >> drop(4)
   >> take(1);
   // should return {4,3,2,1,0}

To limit the size of the buffer, a higher order function may be handy eg.:

  range()
     >> scan( vector<int>{}, sort() | slice(10) );

nikhedonia avatar Oct 29 '18 13:10 nikhedonia