Folding a HP-string with the 1/4

Folding a HP-string with the
1/4-approximation algorithm
Folding a HP-string with the
1/4-approximation algorithm
eoeoeoeoeoeo o o eo eo e oe oe o eo eo e e eoeoeoeoeoeo
hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
0123456789012345678901234567890123456789012345678901234567890123
Folding a HP-string with the
1/4-approximation algorithm
eoeoeoeoeoeo o o eo eo e oe oe o eo eo e e eoeoeoeoeoeo
hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
0123456789012345678901234567890123456789012345678901234567890123
Terminology
Even(S) = “hydrophobes in S at even-indexed positions” = {i | S[i] = h and i mod 2 = 0}
Odd(S) = “hydrophobes in S at odd-indexed positions” = {i | S[i] = h and i mod 2 = 1}
We will show how to make an HP fold F=Fold(S) in time O(|S|) such that:
HP-Score(F) ≧ ¼ OPT(S)
Step 1: Match odd's and even's
eoeoeoeoeoeo o o eo eo e oe oe o eo eo e e eoeoeoeoeoeo
hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
0123456789012345678901234567890123456789012345678901234567890123
1) Match even's from the left with odd's from the right
2) Match odd's from the left with even's from the right
3) Pick the maximum sized matching
Step 1: Match odd's and even's
eoeoeoeoeoeo o o eo eo e oe oe o eo eo e e eoeoeoeoeoeo
hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
0123456789012345678901234567890123456789012345678901234567890123
1) Match even's from the left with odd's from the right
2) Match odd's from the left with even's from the right
3) Pick the maximum sized matching
Step 1: Match odd's and even's
Size = 10
eoeoeoeoeoeo o o eo eo e oe oe o eo eo e e eoeoeoeoeoeo
hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
0123456789012345678901234567890123456789012345678901234567890123
1) Match even's from the left with odd's from the right
2) Match odd's from the left with even's from the right
3) Pick the maximum sized matching
Step 1: Match odd's and even's
Size = 10
eoeoeoeoeoeo o o eo eo e oe oe o eo eo e e eoeoeoeoeoeo
hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
0123456789012345678901234567890123456789012345678901234567890123
Size = 11
1) Match even's from the left with odd's from the right
2) Match odd's from the left with even's from the right
3) Pick the maximum sized matching
How big is the matching?
There exists S1 and S2 such S=S1 S2 and 1) or 2) holds:
1) |Even(S1)| ≧ ½ |Even(S)| and |Odd(S2)| ≧ ½ |Odd(S)|
2) |Odd(S1)| ≧ ½ |Odd(S)| and |Even(S2)| ≧ ½ |Even(S)|
Size >= ½ min(|Even(S)|, |Odd(S)|)
≧ ½ |Even(S)|
≧ ½ |Odd(S)|
eoeoeoeoeoeo o o eo eo e oe oe o eo eo e e eoeoeoeoeoeo
hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
0123456789012345678901234567890123456789012345678901234567890123
Size = 11
Step 2: Make a fold from the matching
Make an HP fold F=Fold(S) such that:
HP-Score(F) ≧ “Size of matching” ≧ ½ min(|Even(S)|, |Odd(S)|)
Make S1 and S2 face each other:
Fold S1 and S2 such that every other grid point is occupied by a matched h:
Step 2: Make a fold from the matching
Make an HP fold F=Fold(S) such that:
HP-Score(F) ≧ “Size of matching” ≧ ½ min(|Even(S)|, |Odd(S)|)
$ python hpfold.py hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - h
.
.
.
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - p
p - p
p
p
.
.
.
|
|
|
|
|
|
h - H - h - H - h - H - h - H - h - H - h - H - p - H - p - H * h - H * h - H
p - H - h - p
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
|
H - h - H - h - H - h - H - h - H - h - H - h - p - h - p - h - p
h - p
h - p
h - H - p
|
|
|
|
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - H
p - H
p
p
.
.
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
H - p
.
.
Score: 20
eoeoeoeoeoeo o o eo eo e oe oe o eo eo e e eoeoeoeoeoeo
hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
0123456789012345678901234567890123456789012345678901234567890123
Size = 11
Step 2: Make a fold from the matching
Make an HP fold F=Fold(S) such that:
HP-Score(F) ≧ “Size of matching” ≧ ½ min(|Even(S)|, |Odd(S)|)
$ python hpfold.py hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Score ≧ 11
.
p - h
.
.
.
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - p
p - p
p
p
.
.
.
|
|
|
|
|
|
h - H - h - H - h - H - h - H - h - H - h - H - p - H - p - H * h - H * h - H
p - H - h - p
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
|
H - h - H - h - H - h - H - h - H - h - H - h - p - h - p - h - p
h - p
h - p
h - H - p
|
|
|
|
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - H
p - H
p
p
.
.
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
H - p
.
.
Score: 20
eoeoeoeoeoeo o o eo eo e oe oe o eo eo e e eoeoeoeoeoeo
hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
0123456789012345678901234567890123456789012345678901234567890123
Size = 11
How good is the fold?
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
Observation:
A h can form at most 2 bonds with h's of
opposite parity:
OPT(S) ≦ 2 min(|Even(S)|, IOdd(S)|)
$ python hpfold.py hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - h
.
.
.
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - p
p - p
p
p
.
.
.
|
|
|
|
|
|
h - H - h - H - h - H - h - H - h - H - h - H - p - H - p - H * h - H * h - H
p - H - h - p
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
|
H - h - H - h - H - h - H - h - H - h - H - h - p - h - p - h - p
h - p
h - p
h - H - p
|
|
|
|
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - H
p - H
p
p
.
.
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
H - p
.
.
Score: 20
Make an HP fold F=Fold(S) such that:
HP-Score(F) ≧ “Size of matching”
≧ ½ min(|Even(S)|, |Odd(S)|)
≧ ½ (½ OPT(S))
≧ ¼ OPT(S)
How good is the fold?
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
Observation:
A h can form at most 2 bonds with h's of
opposite parity:
OPT(S) ≦ 2 min(|Even(S)|, IOdd(S)|)
$ python hpfold.py hhhhhhhhhhhhphphpphhpphhpphpphhpphhpphpphhpphhpphphphhhhhhhhhhhh
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - h
.
.
.
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - p
p - p
p
p
.
.
.
|
|
|
|
|
|
h - H - h - H - h - H - h - H - h - H - h - H - p - H - p - H * h - H * h - H
p - H - h - p
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
|
H - h - H - h - H - h - H - h - H - h - H - h - p - h - p - h - p
h - p
h - p
h - H - p
|
|
|
|
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - H
p - H
p
p
.
.
|
|
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
H - p
.
.
Score: 20
Make an HP fold F=Fold(S) such that:
HP-Score(F) ≧ “Size of matching”
≧ ½ min(|Even(S)|, |Odd(S)|)
≧ ½ (½ OPT(S))
≧ ¼ OPT(S)
Summary
We have shown how to make an HP fold F=Fold(S) such that:
HP-Score(F) ≧ “Size of matching” ≧ ½ min(|Even(S)|, |Odd(S)|) ≧ ¼ OPT(S)
Running time?
1) Pick maximum sized matching: O(n)
2) Make corresponding folding: O(n)
Attempts to improve the algorithm
Exercise
Use the presented algorithm to fold the following HP string:
hhphphphphhhhphppphppphpppphppphppphphhhhphphphphh
What is the score of the fold? What is the size of the matching?
Exercise
Use the presented algorithm to fold the following HP string:
hhphphphphhhhphppphppphpppphppphppphphhhhphphphphh
What is the score of the fold? What is the size of the matching?
p - H
.
| |
H
p
.
| |
p
H
.
| |
H
p
.
|
|
h * H - h *
*
*
H - h * H |
|
.
p
h
| |
.
h
p
| |
.
p
h
| |
.
h - p
Score: 10
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
p - p
p |
|
|
H - h - p - h
p - h
*
*
*
*
h - H - p - H - p
H |
|
.
.
.
.
p - p
p
.
|
p - h *
p
H |
|
p - p
p - p
|
p - p
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.