Add O(n log n) LIS via patience sorting - #287
Conversation
|
Note to reviewers: This is one of several clique-embedder PRs (four up already, including this). Not urgent and not a blocker for the next PR. This one is only depended on a couple of PRs down the road. |
thisac
left a comment
There was a problem hiding this comment.
Don't forget to add a releasenotes entry.
|
|
||
|
|
||
| def longest_strictly_increasing_subsequence( | ||
| sequence: list[Any], |
There was a problem hiding this comment.
Not sure about this name. It's fine, but something slightly less generic might be better? Maybe comparables? Just sequence to me sounds more like a type.
There was a problem hiding this comment.
The function name already indicates we're returning a subsequence, so sequence naturally names the input we extract it from. The comparability requirement is documented in the args docstring
There was a problem hiding this comment.
And Longest Increasing Subsequence problem is standard in computer science, see eg. https://en.wikipedia.org/wiki/Longest_increasing_subsequence
There was a problem hiding this comment.
I only meant the sequence name, longest_strictly_increasing_subsequence is fine. 🙂
There was a problem hiding this comment.
Great.
I don't terribly mind changing the name but I think with that function name, then sequence is actually the more natural input name.
Co-authored-by: Theodor Isacsson <tisacsson@dwavesys.com> Add release note Address reviewer's comments
3f903aa to
c0b074a
Compare
thisac
left a comment
There was a problem hiding this comment.
Thanks @mahdiehmalekian !
Co-authored-by: Theodor Isacsson <tisacsson@dwavesys.com>
Implements longest strictly-increasing subsequence using the classic patience-sort algorithm (piles + binary search + predecessor reconstruction).
Notes:
Strictly increasing (uses >= in the binary search, not >) — equal values don't extend a subsequence. This is intentional; relaxing it changes semantics for callers relying on distinct endpoints.
Elements need only support < / >= (tuples work).
No external deps.
AI use: I prompted Claude with my own code based on the psuedocode from Wikipedia https://en.wikipedia.org/wiki/Longest_increasing_subsequence which was modified to give strictly increasing output and asked it to clean up the code and document it. I checked the resulting code. I also used Claude to generate the test suite and checked it myself.