T G A C T T T C C C C G G A A A A A C T G A A A G G G G C C T T T T.
CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A...
-
Upload
jett-yardley -
Category
Documents
-
view
217 -
download
0
Transcript of CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A...
![Page 1: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/1.jpg)
CMSC 150RECURSION
CS 150: Mon 26 Mar 2012
![Page 2: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/2.jpg)
Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T
Want to compare sequences for similarity
Similar sequences: common ancestors? Point mutations Insertions Deletions − − A G A C T A G T T A C
C G A G A C − − G − T − −
![Page 3: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/3.jpg)
Global Alignment Algorithm
Think about brute force
A G A C T A G T T A C C G A G A C G T
Where should gaps go? Enumerate all possible alignments?
![Page 4: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/4.jpg)
Global Alignment Algorithm
Think about brute force
A G A C T A G T T A C C G A G A C G T
For two sequences of length L: # of possible global alignments: ~ 22L
if L = 250, this is ~10149 alignments @ 1B alignments / second, takes 3.21 X 10132
years age of universe: ~1.4 X 1010 years
![Page 5: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/5.jpg)
Global Alignment Algorithm
Think about brute force
A G A C T A G T T A C C G A G A C G T
For two sequences of length L: # of possible global alignments: ~ 22L
if L = 250, this is ~10149 alignments @ 1B alignments / second, takes 3.21 X 10132
years age of universe: ~1.4 X 1010 years
![Page 6: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/6.jpg)
Needleman-Wunsch Algorithm Computes optimal global alignment
Technique: Uses dynamic programming combine optimal solutions from
subproblems number of subproblems must be
(relatively) small
Typically bottom-up: find solution using a recursive series of
simpler solutions
![Page 7: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/7.jpg)
Recursion
Use same algorithm on smaller subproblems
Need: Base case: simplest input possible, solution
immediately available Recursive call: invoke the algorithm on a
smaller set of the input
Without base case, recursion would be infinite!
![Page 8: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/8.jpg)
An Example
Search phone book for a name start in middle: if found, stop otherwise, repeat process in correct “half”
of book
Base case: only one name to search Recursive call: search remaining “half” of
book
![Page 9: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/9.jpg)
Another Example : Factorial
n! = n x (n-1) x (n-2) x … x 2 x 1
5! = 5 x 4 x 3 x 2 x 1 = 120 4! = 4 x 3 x 2 x 1= 24 3! = 3 x 2 x 1 = 6 2! = 2 x 1 = 2 1! = 1 0! = 1 (multiplicative identity)
![Page 10: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/10.jpg)
Another Example : Factorial
n! = n x (n-1) x (n-2) x … x 2 x 1
5! = 5 x 4 x 3 x 2 x 1 = 120 4! = 4 x 3 x 2 x 1= 24 3! = 3 x 2 x 1 = 6 2! = 2 x 1 = 2 1! = 1 0! = 1 (multiplicative identity)
![Page 11: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/11.jpg)
Another Example : Factorial
n! = n x (n-1) x (n-2) x … x 2 x 1
5! = 5 x 4 x 3 x 2 x 1 = 5 x 4! = 120 4! = 4 x 3 x 2 x 1= 24
![Page 12: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/12.jpg)
Another Example : Factorial
n! = n x (n-1) x (n-2) x … x 2 x 1 n! = n x (n-1)!
Defined recursively:
1if n = 0
n! = n(n-1)! if n > 0
![Page 13: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/13.jpg)
Compute n! in BlueJ…
![Page 14: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/14.jpg)
Another Example : Fibonacci Fibonacci sequence:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …
After first two, each term is sum of previous two
Defined recursively: Let fn be the nth term, n = 0, 1, 2…0 if n = 0
fn = 1 if n = 1
fn-1 + fn-2 if n > 1
![Page 15: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/15.jpg)
Another Example : Fibonacci Fibonacci sequence:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …
0 if n = 0fn = 1 if n = 1
fn-1 + fn-2 if n > 1
f0 = 0 f1 = 1 f2 = f1 + f0 = 1 + 0 = 1 f3 = f2 + f1 = 1 + 1 = 2 f4 = f3 + f2 = 2 + 1 = 3
![Page 16: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/16.jpg)
Fibonacci in Nature
Fibonacci spiral: Fibonacci tiling: squares of sizes 1, 1, 2, 3, 5,
8, 13, 21, 34 Draw circular arc connecting opposite corners
of squares
![Page 17: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/17.jpg)
Fibonacci in Nature
Fibonacci spiral: Fibonacci tiling: squares of sizes 1, 1, 2, 3, 5, 8, 13, 21,
34 Draw circular arc connecting opposite corners of
squares More explanation: Fibonacci in nature
![Page 18: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/18.jpg)
Compute nth Fibonacci in BlueJ…
![Page 19: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/19.jpg)
Another Example : Towers of Hanoi 3 towers, n disks each of different size Rules:
Can move only one disk at a time No larger disk can be on top of smaller disk
Goal: move n-tower from 1st tower to 3rd tower
![Page 20: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/20.jpg)
Think Recursively
n n - 1
Consider the n-tower as a tower of n-1 and a tower of 1…
![Page 21: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/21.jpg)
Think Recursively
n - 1
If we can somehow move the n-1 tower to the middle…
![Page 22: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/22.jpg)
Think Recursively
n - 1
And then the largest disk to the right…
![Page 23: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/23.jpg)
Think Recursively
n - 1
And finally the n-1 tower to the right, we have a solution!
![Page 24: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/24.jpg)
Think Recursively
What is the base case? a tower of n = 1 disk
![Page 25: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/25.jpg)
Think Recursively
n n - 1
What is the recursive step? Move n-1 tower to middle Then largest disk to right Then n-1 tower from middle to right
1
2
3
![Page 26: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/26.jpg)
Think Recursively
n n - 1
In pseudocode: moveTower( n-1, 1, 2
); moveDisk( 1, 3 ); moveTower( n-1, 2, 3
);
1
2
3
Note that we do not explicitly implement
the steps for a tower of size n-1
![Page 27: CMSC 150 RECURSION CS 150: Mon 26 Mar 2012. Motivation : Bioinformatics Example A G A C T A G T T A C C G A G A C G T Want to compare sequences.](https://reader035.fdocuments.in/reader035/viewer/2022062713/56649cb85503460f9497f7f4/html5/thumbnails/27.jpg)
Solve Towers in BlueJ…