How to Solve This Dynamic Programming Problem with Two Subsequences?

Click For Summary
SUMMARY

The discussion focuses on solving a dynamic programming (DP) problem involving two subsequences, X and Y, where the goal is to minimize the sum of absolute differences between selected elements of X and Y. The proposed algorithm should operate in O(mn) time complexity. The user defines a function B(i,j) to represent the minimum sum of differences for the first i elements of X and the first j elements of Y. A related problem is also suggested to help clarify the approach.

PREREQUISITES
  • Understanding of dynamic programming concepts
  • Familiarity with subsequences and their properties
  • Knowledge of time complexity analysis, specifically O(mn)
  • Experience with constructing and filling DP tables
NEXT STEPS
  • Implement the dynamic programming solution for the given subsequences problem
  • Explore related dynamic programming problems, such as the "minimal subset sum" problem
  • Study the construction and optimization of DP tables in various algorithms
  • Learn about advanced techniques in dynamic programming, including memoization and tabulation
USEFUL FOR

Students and professionals in computer science, particularly those specializing in algorithms, dynamic programming enthusiasts, and software developers tackling optimization problems.

ydan87
Messages
25
Reaction score
0
I'm having problem to solve this problem in DP:
Given 2 subsequences:

X = {x1, x2,..., xm} and Y = {y1, y2, ... , yn}

so `n <= m` and also `y1 <= y2 <= ... <= yn`.

The goal is to find a sub-sequence of `X` (xi1, xi2, ... , xin) such that:

sum(k is 1 to n) | xik - yk | is minimal

The DP algorithm should be `o(mn)`.

I though about that: define `B(i,j)` as the minimun sum so |Y| is j and |X| is I, but it seems I get stuck here.

Any help?
Thanks in advance
 
Technology news on Phys.org
I think you are on the right track. Define B(i,j) as follows:

B(i,j): minimum of sum(k from 1 to j) | xik - yk |,
where the first i elements of x and the first j elements of y are available.

---

So, basically you are searching for a "subset" of x. I recommend working on a related problem:
Consider the sequence A = [7, 2, 1, 3, 10]. Find a subset with 3 elements such that the sum of these elements is minimized. Let's call this the minimal subset of size 3.

Define B(i,j) as follows:
B(i,j): minimal subset of size j if the first i elements of A are available.

You would then write down a table:
Code:
    | j:    1    2    3
------------------------
i:
1   |      7         
2   |      2          
3   |      1
4   |      1
5   |      1

The first column is easy to fill out. Can you fill the rest?

I'm sure that if you can solve this problem you can also find a solution to your problem.
 
That's great! Thanks :)
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
17
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K