Skip to content

Implement an Insertion-Sort Reducer #1

Description

@nikhedonia

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) );

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions