Find the longest increasing or decreasing subsequence of a sequence.
Project description
Longest Increasing Subsequence
Find the longest increasing or decreasing subsequence of a sequence.
Install with:
pip install longest-increasing-subsequence
Usage:
from longest_increasing_subsequence import (longest_increasing_subsequence,
longest_decreasing_subsequence,
longest_increasing_subsequence_indices)
longest_increasing_subsequence([0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15])
# [0, 2, 6, 9, 11, 15]
longest_increasing_subsequence([0, 0, 1, 2, 3, 2, 1, 0, 0])
# [0, 0, 1, 2, 2]
longest_decreasing_subsequence([0, 0, 1, 2, 3, 2, 1, 0, 0])
# [3, 2, 1, 0, 0]
longest_increasing_subsequence([0, 0, 1, 2, 3], strict=True)
# [0, 1, 2, 3]
longest_increasing_subsequence(['A', 'B', 'CC', 'D', 'EEE'], key=len)
# ['A', 'B', 'D', 'EEE']
"".join(longest_increasing_subsequence('aababbbdccddd'))
# 'aaabbbccddd'
longest_increasing_subsequence_indices([0, 0, 1, 2, 3, 2, 1, 0, 0])
# [0, 1, 2, 3, 5]
Free software: MIT license
Documentation: https://longest-increasing-subsequence.readthedocs.io.
Features
Works with arbitrary sequence types (list, tuple, str, numpy array, pandas series, etc.)
Works with arbitrary comparable elements (anything that has < and >).
Can compute increasing or decreasing subsequences.
Can compute strictly increasing or strictly decreasing subsequences.
Can compare elements by an optional key function (e.g. compare strings by length).
Can return the subsequence or the indices of the subsequence.
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.1.0 (2021-02-15)
First release on PyPI.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file longest_increasing_subsequence-0.1.6.tar.gz
.
File metadata
- Download URL: longest_increasing_subsequence-0.1.6.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea96ccefa2f6fec9af90f5cd63d13f4822ddba639c7cfa89a1637f61507b0279 |
|
MD5 | 3a9f48f32a25c184a0cf4b75551d5fc0 |
|
BLAKE2b-256 | 6f4f2bd4579c34cec79ce871e565f2dc586a3a027e28438ee4a81718401966f4 |
File details
Details for the file longest_increasing_subsequence-0.1.6-py2.py3-none-any.whl
.
File metadata
- Download URL: longest_increasing_subsequence-0.1.6-py2.py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e44da101243e1733363b928d57a81264331c72979b1d1be8f05741c454691b3e |
|
MD5 | 2b8e28003cfef8864814f821595c3192 |
|
BLAKE2b-256 | 4ef9885c7ae5791e22497f7d1793d36e6337cc0059cf2e2964a88081dcfeffd9 |