Skip to main content

Find the longest increasing or decreasing subsequence of a sequence.

Project description

Longest Increasing Subsequence

https://img.shields.io/pypi/v/longest_increasing_subsequence.svg https://travis-ci.com/mCodingLLC/longest_increasing_subsequence.svg?branch=master Documentation Status

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]

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

longest_increasing_subsequence-0.1.5.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

longest_increasing_subsequence-0.1.5-py2.py3-none-any.whl (6.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file longest_increasing_subsequence-0.1.5.tar.gz.

File metadata

  • Download URL: longest_increasing_subsequence-0.1.5.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

Hashes for longest_increasing_subsequence-0.1.5.tar.gz
Algorithm Hash digest
SHA256 1c237fbb6ff46903566f20881252cfbf64b4f745042cfd8071279e9f7f82a8f6
MD5 bbe3c5b9afaebda06142eed15de648cc
BLAKE2b-256 57817a91581e4a41404b72dcd0726058dab3fc819a755ea07dd688ad078ff1d3

See more details on using hashes here.

File details

Details for the file longest_increasing_subsequence-0.1.5-py2.py3-none-any.whl.

File metadata

  • Download URL: longest_increasing_subsequence-0.1.5-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

Hashes for longest_increasing_subsequence-0.1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cee7ddf27eccad8c1b198d8089ac7eab71183ba8fa3628bd3ee9995930740b56
MD5 b366c6e7ff434cac0e257677afdf5820
BLAKE2b-256 a9a9ff1bf68de097303751a15e7fa29c2f9ce9f6a7934f2c3457b24d54be9a8d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page