0% found this document useful (0 votes)
10 views

Dynamic Programming For The Subset Sum Problem

Algorithm

Uploaded by

huzaifmanzoor988
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Dynamic Programming For The Subset Sum Problem

Algorithm

Uploaded by

huzaifmanzoor988
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

FORMALIZED MATHEMATICS

Vol. 28, No. 1, Pages 89–92, 2020


DOI: 10.2478/forma-2020-0007 https://www.sciendo.com/

Dynamic Programming for the Subset Sum


Problem1

Hiroshi Fujiwara Hokuto Watari


Shinshu University Nagano Electronics Industrial Co., Ltd.
Nagano, Japan Chikuma, Japan
Hiroaki Yamamoto
Shinshu University
Nagano, Japan

Summary. The subset sum problem is a basic problem in the field of


theoretical computer science, especially in the complexity theory [3]. The input
is a sequence of positive integers and a target positive integer. The task is to
determine if there exists a subsequence of the input sequence with sum equal
to the target integer. It is known that the problem is NP-hard [2] and can be
solved by dynamic programming in pseudo-polynomial time [1]. In this article
we formalize the recurrence relation of the dynamic programming.

MSC: 90C39 68Q25 68V20


Keywords: dynamic programming; subset sum problem; complexity theory
MML identifier: PRSUBSET, version: 8.1.09 5.60.1371

1. Preliminaries

Let x be a finite sequence and I be a set. The functor Seq(x, I) yielding


a finite sequence is defined by the term
(Def. 1) Seq(xI).
1
This work was supported by JSPS KAKENHI Grant Numbers JP16K00033, JP17K00013
and JP17K00183.
c 2020 University of Białystok
CC-BY-SA License ver. 3.0 or later
89 ISSN 1426–2630(Print), 1898-9934(Online)
90 hiroshi fujiwara, hokuto watari, and hiroaki yamamoto

Let D be a set and x be a D-valued finite sequence. One can check that
Seq(x, I) is D-valued.
Let x be a real-valued finite sequence. Let us observe that Seq(x, I) is real-
valued.
Let D be a set, x be a D-valued finite sequence, and i be a natural number.
Let us observe that xi is D-valued as a finite sequence-like function.
Let x be a real-valued finite sequence. One can verify that xi is real-valued
as a finite sequence-like function.

2. Summing Up Finite Sequences

Let x be an R-valued finite sequence and a be a real number. We say that


the sum of x is equal to a if and only if
(Def. 2) there exists a set I such that I ⊆ dom x and
P
Seq(x, I) = a.
The functor Qx yielding a function from Seg len x×R into Boolean is defined
by
(Def. 3) for every natural number i and for every real number s such that 1 ¬
i ¬ len x holds if the sum of xi is equal to s, then it(i, s) = true and if
the sum of xi is not equal to s, then it(i, s) = false.
Let A be a subset of N, i be a natural number, s be a real number, and f
be a function from A × R into Boolean. Let us note that f (i, s) is Boolean.
Let a, b be objects. The functor a =Σ b yielding an object is defined by the
term
(Def. 4) (a = b → true, false).
Note that a =Σ b is Boolean.
Let a, b be extended reals. The functor a ¬Σ b yielding an object is defined
by the term
(Def. 5) (a > b → false, true).
Let us note that a ¬Σ b is Boolean.
Now we state the propositions:
(1) Let us consider a real number s, and an R-valued finite sequence x.
Suppose 1 ¬ len x. Then Qx (1, s) = (x(1) =Σ s) ∨ (s =Σ 0).
(2) Let us consider functions f , g, and sets X, Y. Suppose rng g ⊆ X. Then
(f (X ∪ Y )) · g = (f X) · g.
Proof: For every object i, i ∈ dom((f (X ∪ Y )) · g) iff i ∈ dom g and
g(i) ∈ dom(f X). For every object i such that i ∈ dom((f (X ∪ Y )) · g)
holds ((f (X ∪ Y )) · g)(i) = (f X)(g(i)). 
Dynamic programming for the subset sum problem 91

(3) Let us consider an R-valued finite sequence x, a natural number i, and


a set I0 . Suppose I0 ⊆ Seg i and Seg(i + 1) ⊆ dom x. Then Seq(x(i +
1), I0 ∪ {i + 1}) = Seq(xi, I0 ) a hx(i + 1)i. The theorem is a consequence
of (2).
(4) Let us consider a real-valued finite sequence x. If x 6= ∅ and x is positive,
P
then 0 < x.
(5) Let us consider a real-valued finite sequence x, and a natural number i.
Suppose x is positive and 1 ¬ i ¬ len x. Then
(i) xi is positive, and
(ii) xi 6= ∅.
Proof: For every natural number j such that j ∈ dom(xi) holds 0 <
(xi)(j) by [4, (112)]. 
(6) Let us consider a real-valued finite sequence x, and a set I. Suppose x
is positive and I ⊆ dom x and I 6= ∅. Then
(i) Seq(x, I) is positive, and
(ii) Seq(x, I) 6= ∅.
Proof: For every natural number j such that j ∈ dom(Seq(x, I)) holds
0 < (Seq(x, I))(j). 

3. Recurrence Relation of Dynamic Programming


for the Subset Sum Problem

Now we state the proposition:


(7) Let us consider an R-valued finite sequence x. Suppose x is positive. Let
us consider a natural number i, and a real number s. Suppose 1 ¬ i < len x.
Then Qx (i + 1, s) = Qx (i, s) ∨ (x(i + 1) ¬Σ s) ∧ Qx (i, s − x(i + 1)).
Proof: Qx (i+1, s) = true iff Qx (i, s)∨(x(i+1) ¬Σ s)∧Qx (i, s−x(i+1)) =
true. 

Acknowledgement: We are very grateful to Prof. Yasunari Shidama for


his encouraging support. We thank Prof. Pauline N. Kawamoto, Dr. Hiroyuki
Okazaki, and Dr. Hiroshi Yamazaki for their helpful discussions.

References
[1] Michael R. Garey and David S. Johnson. Computers and Intractability: A Guide to the
Theory of NP-Completeness. W. H. Freeman & Co., New York, NY, USA, 1979. ISBN
0716710447.
92 hiroshi fujiwara, hokuto watari, and hiroaki yamamoto

[2] Richard M. Karp. Reducibility among combinatorial problems. In Miller et al. [3], pages
85–103. ISBN 978-1-4684-2001-2. doi:10.1007/978-1-4684-2001-2 9.
[3] Raymond E. Miller, James W. Thatcher, and Jean D. Bohlinger, editors. Complexity of
Computer Computations, 1972. Springer US. ISBN 978-1-4684-2001-2. doi:10.1007/978-1-
4684-2001-2 9.
[4] Wojciech A. Trybulec. Non-contiguous substrings and one-to-one finite sequences. Forma-
lized Mathematics, 1(3):569–573, 1990.

Accepted January 13, 2020

You might also like