Download presentation
Presentation is loading. Please wait.
Published byClyde Goodwin Modified over 8 years ago
1
Alignment, Part II Vasileios Hatzivassiloglou University of Texas at Dallas
2
Finding the optimal alignment Simple algorithm: Construct all possible alignments, score them, and pick the best How many alignments are there for two strings of length n and m?
3
or C(p, q): Number of combinations of q objects out of p, p≥q Arrange the p objects in line from 1 to p Pick the first (p choices), second (p-1 choices), up to q-th (p-q+1 choices) This will generate all permutations of each set of q objects, so divide by q! Combinatorics basics
4
Asymptotic analysis How large is C(n+m, n)? Asymptotic analysis: we look at how fast C(n+m, n) grows in comparison to functions like (n+m) 2 or 2 n+m Ultimately, constants have a small effect on the growth rate – they are dominated by terms involving the variables n and m
5
Example function growth n2n2 100n 2 2n2n n=5252,50032 n=1010010,0001,024 n=10010,0001,000,0001.27e30
6
Asymptotic analysis of C(p,q)
7
Upper bound for C(p,q) There are 2 p subsets of a set with p elements, some of which will have q elements Therefore, C(p, q) ≤ 2 p In particular, C(2n, n) ≤ 2 2n = 4 n
8
Alignments versus scoring We have explored the potential alignments of two strings The set of such alignments (and their number) remains constant and independent of the scoring function The scoring function may make it hard or easy to locate the optimal alignment(s)
9
Dynamic programming A general strategy for addressing computationally intractable problems by solving all smaller subproblems and remembering the results “Programming” in the mathematical sense Developed in the 1950’s and applied to many problems
10
Calculating the Fibonacci sequence f(n) = f(n-1)+f(n-2) if n>1; f(0)=0; f(1)=1 int fib(int n) { if (n==0) {return 0}; if (n==1) {return 1}; return fib(n-1)+fib(n-2); }
11
Recursive computation of Fibonacci 6 01 21 34 01 2012134012012135 8 100 0 11 1 11 1 1 0 0 1111 2 5 1 2 3 3 2
12
How long does the recursion take? Calculating fib(n) takes at least f(n) addition steps –because we ultimately add 0 or 1 each time How large is f(n)?
13
Dynamic programming for the Fibonacci sequence int MAX_N = 10,000; int known_fib[MAX_N]; known_fib[0]=0; known_fib[1]=1; known_n=1; int dynamic_fib(int n) { if (n==MAX_N) {printf(“N is too large!”); exit;} if (n<=known_n) {return known_fib[n];} new_fib = dynamic_fib(n-1) + dynamic_fib(n-2); known_n++; /* Necessarily, n==known_n */ known_fib[known_n] = new_fib; return new_fib; }
14
Complexity of alternative solution Linear in n This is not necessarily the best algorithm for calculating the Fibonacci sequence –Can be calculated iteratively in O(logn) time –Can be calculated directly
15
Dynamic programming for optimizing choices We have three departments in an organization, each of which comes up with a number of proposals Each proposal has a cost and an estimated revenue Each department can execute at most one proposal Find the optimal set of proposals (maximizing expected revenue) with a fixed total budget
16
Proposal data Total budget = 5 Dept ADept BDept C ProposalCostRevCostRevCostRev I000000 II152814 III2639-- IV--412--
17
Recursive solution The optimal solution with n+1 departments must include a combination of proposals for n departments Is this included combination optimal for the n departments when the (n+1)th department is not considered? –Not necessarily!
18
Dynamic programming basics Choices correspond to stages Each stage has a number of states, each of which encodes relevant information about choices in previous stages The principle of optimality: We need to know only the state of a stage to make an optimal choice for that stage We only need to deal with viable states, that can be reached from a previous stage
19
Proposal example Three stages, one for each department State in each stage: Total money left before reaching that stage Principle of optimality: To choose the optimal project for department X we only need to know how much money is left for X
20
Solving the proposal problem Construct table with states as rows, stages as columns Each cell contains the best value we can obtain for the quantity we optimize Fill it in from left to right (by stages) Within a given stage, consider each viable prior state and all transitions that can happen from that state in the current stage Update the value for the resulting state from a transition; keep the best result
21
DP for the proposal problem Money leftDept ADept BDept C 0 1 2 3 4 5
22
DP for the proposal problem Money leftDept ADept BDept C 0 1 2 3 4 5
23
DP for the proposal problem Money leftDept ADept BDept C 0 1 2 3 4 5 0
24
DP for the proposal problem Money leftDept ADept BDept C 0 1 2 3 4 5 0 5
25
DP for the proposal problem Money leftDept ADept BDept C 0 1 2 3 4 5 0 5 6
26
DP for the proposal problem Money leftDept ADept BDept C 0 1 2 3 4 5 0 5 6 0
27
DP for the proposal problem Money leftDept ADept BDept C 0 1 2 3 4 5 0 5 6 0 8
28
DP for the proposal problem Money leftDept ADept BDept C 0 1 2 3 4 5 0 5 6 0 8 9
29
DP for the proposal problem Money leftDept ADept BDept C 0 1 2 3 4 5 0 5 6 0 8 9 12
30
DP for the proposal problem Money leftDept ADept BDept C 0 1 2 3 4 5 0 5 6 0 8 9 12 5
31
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 12 5
32
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 12 5
33
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5
34
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5
35
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17
36
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17
37
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17
38
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17
39
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17
40
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17
41
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17
42
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17 0
43
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17 0 4
44
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17 0 5
45
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17 0 5 9
46
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17 0 5 9
47
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17 0 5 9 12
48
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17 0 5 9 13
49
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17 0 5 9 13 17
50
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 14 5 17 0 5 9 13 17
51
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 18 14 5 17 0 5 9 13 17
52
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 18 14 5 17 0 5 9 13 17
53
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 18 14 5 17 0 5 9 13 17
54
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 18 14 5 17 0 5 9 13 17
55
Money leftDept ADept BDept C 0 1 2 3 4 5 DP for the proposal problem 0 5 6 0 8 13 18 14 5 17 0 5 9 13 17
56
Complexity If we have n stages, m possible states, and k options at each stage –Time complexity O(nmk) –Space complexity O(nm) Straightforward recursion would take –O(k n ) time and space
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.