Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/longest increasing subsequence #7

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

mkurdej
Copy link
Member

@mkurdej mkurdej commented Aug 17, 2014

A new algorithm: longest increasing subsequence that permits as well to find the longest decreasing/non-increasing/non-decreasing or differently ordered subsequence by defining comparison predicate. I have added tests for it using iterators, ranges, pointers and object's operator().

There are 2 functionalities actually: computing length (function longest_increasing_subsequence_length or method longest_increasing_subsequence::compute_length) and retrieving the subsequence (function longest_increasing_subsequence_search or longest_increasing_subsequence::operator()).
There is also a creator function make_longest_increasing_subsequence.

There are 3 possibilities to retrieve the subsequence:

  • through an output iterator as an argument
  • returning a vector of values
  • returning a vector of iterators (useful for big objects when there is no need for copy)
    The two latter variants are chosen by giving a corresponding tag as an argument.

Documentation will come soon.

Add .clang-format configuration file (requires version >3.5.0).

Conflicts:
	test/Jamfile.v2
…ining the return type (a collection of values or a collection of iterators).
A) with two iterators
B) with a range
C) with two pointers
D) using object methods directly with case A.
1) output iterator
2) vector of values (with value_output_tag as argument)
3) vector of iterators (with iterator_output_tag as argument)
@zamazan4ik
Copy link
Contributor

@mclow what do you think about this pull request? I think, these functions are very-very useful. We should add it to Boost.Algorithm.

@Morwenn
Copy link
Contributor

Morwenn commented Mar 27, 2018

I know this pull request is a bit old, but I had to compute the length longest non-decreasing subsequence of a sequence at some point (to compute the measure of presortedness Rem), which is notably one of the features proposed here, so I'm willing to share some thoughts about implementation details:

  • I used a modified patience sort algorithm to compute the length, which also runs in O(n log n) and O(n) extra memory, but my implementation actually uses extra memory equivalent to the size of the longest non-decreasing subsequence, and not to the size of the original sequence. While this is still O(n), it can use less memory on average.
  • I can compute the size of the longest non-decreasing subsequence for forward iterators without added cost compared to random-access iterators.

Now I'm not sure whether these improvements are useful since they are limited to the computation of the size of a longest increasing subsequence (I haven't try to compute the subsequence itself), which is rather specific, but it can be done to make the current proposed implementation more powerful if needed :)

@mkurdej
Copy link
Member Author

mkurdej commented Mar 27, 2018

@Morwenn, that looks like nice optimizations for lis_length. Especially space reduction in the average case seems very promising. Some people might be interested in lowering requirements to forward iterators too.

Anyway, I don't really work on this kind of things now and I don't have much time to work on this PR, so I let anyone interested hijack the authorship of this PR and continue the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants