apache / apache/kvrocks

Space efficient LCS using Hirschberg's algorithm

Open
#3,314 5 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
4.4k
Forks
658
Avg merge
1d 20h
Merged PRs (30d)
10

Description

### Search before asking

- [x] I had searched in the [issues](https://github.com/apache/kvrocks/issues) and found no similar issues.

### Motivation

In kvrocks LCS command, it uses Dynamic Programming. When two string S, T and get LCS(S, T),
- Time Complexity: O(|S||T|)
- Space Complexity: O(|S||T|)

When |S| and |T| is about 10000, it requires over 400MB.

### Solution

We can reduce space complexity to O(|S|+|T|) using Hirschberg's algorithm, also it can recover LCS string.

Relevant paper: A Linear Space Algorithm for Computing Maximal Common Subsequences (Author: D.S. Hirschberg)

### Are you willing to submit a PR?

- [x] I'm willing to submit a PR!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the kvrocks LCS command implementation and its existing tests, then read how the current dynamic-programming approach computes and recovers the result. The work is done when LCS uses Hirschberg's algorithm, preserves LCS string recovery, reduces space to O(|S|+|T|), and the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
database, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.