Data Structures in Java

Similar documents
Greedy. Outline CS141. Stefano Lonardi, UCR 1. Activity selection Fractional knapsack Huffman encoding Later:

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

Divide and Conquer. Recurrence Relations

Algorithms Test 1. Question 1. (10 points) for (i = 1; i <= n; i++) { j = 1; while (j < n) {

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee

CS173 Running Time and Big-O. Tandy Warnow

4.8 Huffman Codes. These lecture slides are supplied by Mathijs de Weerd

Algorithm Design and Analysis

Chapter 3 Source Coding. 3.1 An Introduction to Source Coding 3.2 Optimal Source Codes 3.3 Shannon-Fano Code 3.4 Huffman Code

Algorithms And Programming I. Lecture 5 Quicksort

IS 709/809: Computational Methods in IS Research Fall Exam Review

CS Analysis of Recursive Algorithms and Brute Force

Sorting Algorithms. We have already seen: Selection-sort Insertion-sort Heap-sort. We will see: Bubble-sort Merge-sort Quick-sort

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming

CS483 Design and Analysis of Algorithms

Aside: Golden Ratio. Golden Ratio: A universal law. Golden ratio φ = lim n = 1+ b n = a n 1. a n+1 = a n + b n, a n+b n a n

Lecture 4. Quicksort

Data Structures and Algorithms

Bin Sort. Sorting integers in Range [1,...,n] Add all elements to table and then

Lecture 9. Greedy Algorithm

CS4800: Algorithms & Data Jonathan Ullman

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005

Divide-and-Conquer Algorithms Part Two

CS 2210 Discrete Structures Advanced Counting. Fall 2017 Sukumar Ghosh

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14

Chapter 2 Date Compression: Source Coding. 2.1 An Introduction to Source Coding 2.2 Optimal Source Codes 2.3 Huffman Code

ITEC2620 Introduction to Data Structures

Partha Sarathi Mandal

Algorithms. Jordi Planes. Escola Politècnica Superior Universitat de Lleida

Divide-and-conquer: Order Statistics. Curs: Fall 2017

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Recurrence Relations

Algorithms: COMP3121/3821/9101/9801

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 20: Dynamic Programming

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Quiz 1 Solutions. (a) f 1 (n) = 8 n, f 2 (n) = , f 3 (n) = ( 3) lg n. f 2 (n), f 1 (n), f 3 (n) Solution: (b)

More Dynamic Programming

21. Dynamic Programming III. FPTAS [Ottman/Widmayer, Kap. 7.2, 7.3, Cormen et al, Kap. 15,35.5]

Fundamental Algorithms

Fundamental Algorithms

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

More Dynamic Programming

Algorithms and Data Structures 2016 Week 5 solutions (Tues 9th - Fri 12th February)

Randomized Sorting Algorithms Quick sort can be converted to a randomized algorithm by picking the pivot element randomly. In this case we can show th

General Methods for Algorithm Design

CSE 421 Greedy: Huffman Codes

Divide and conquer. Philip II of Macedon

Sorting. Chapter 11. CSE 2011 Prof. J. Elder Last Updated: :11 AM

5. DIVIDE AND CONQUER I

CS325: Analysis of Algorithms, Fall Final Exam

Slides for CIS 675. Huffman Encoding, 1. Huffman Encoding, 2. Huffman Encoding, 3. Encoding 1. DPV Chapter 5, Part 2. Encoding 2

Bandwidth: Communicate large complex & highly detailed 3D models through lowbandwidth connection (e.g. VRML over the Internet)

Divide & Conquer. Jordi Cortadella and Jordi Petit Department of Computer Science

MAKING A BINARY HEAP

Data Structures in Java

Advanced Analysis of Algorithms - Midterm (Solutions)

SIGNAL COMPRESSION Lecture 7. Variable to Fix Encoding

Week 5: Quicksort, Lower bound, Greedy

CPSC 320 Sample Final Examination December 2013

Dynamic Programming. Shuang Zhao. Microsoft Research Asia September 5, Dynamic Programming. Shuang Zhao. Outline. Introduction.

10-704: Information Processing and Learning Fall Lecture 10: Oct 3

Coin Changing: Give change using the least number of coins. Greedy Method (Chapter 10.1) Attempt to construct an optimal solution in stages.

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

Maximum sum contiguous subsequence Longest common subsequence Matrix chain multiplication All pair shortest path Kna. Dynamic Programming

CPS 616 DIVIDE-AND-CONQUER 6-1

CS483 Design and Analysis of Algorithms

MAKING A BINARY HEAP

data structures and algorithms lecture 2

Entropy as a measure of surprise

Review Of Topics. Review: Induction

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016

5. DIVIDE AND CONQUER I

CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Linear Time Selection

Algorithm Design CS 515 Fall 2015 Sample Final Exam Solutions

CS2223 Algorithms D Term 2009 Exam 3 Solutions

Lecture 1 : Data Compression and Entropy

CS325: Analysis of Algorithms, Fall Midterm

Sorting DS 2017/2018

Divide and Conquer Strategy

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d

CS 4407 Algorithms Lecture: Shortest Path Algorithms

CS Algorithms and Complexity

Reductions, Recursion and Divide and Conquer

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

Data Structures and Algorithms CSE 465

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

R ij = 2. Using all of these facts together, you can solve problem number 9.

Partition and Select

1 Quick Sort LECTURE 7. OHSU/OGI (Winter 2009) ANALYSIS AND DESIGN OF ALGORITHMS

Advanced Data Structures

CSE 613: Parallel Programming. Lecture 8 ( Analyzing Divide-and-Conquer Algorithms )

1. Problem I calculated these out by hand. It was tedious, but kind of fun, in a a computer should really be doing this sort of way.

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:

CSC 421: Algorithm Design & Analysis. Spring 2018

INF4130: Dynamic Programming September 2, 2014 DRAFT version

Reductions, Recursion and Divide and Conquer

Chapter 4 Divide-and-Conquer

CS 231: Algorithmic Problem Solving

Transcription:

Data Structures in Java Lecture 20: Algorithm Design Techniques 12/2/2015 Daniel Bauer 1

Algorithms and Problem Solving Purpose of algorithms: find solutions to problems. Data Structures provide ways of organizing data such that problems can be solved more efficiently Examples: Hashmaps provide constant time access by key, Heaps provide a cheap way to explore different possibilities in order When confronted with a new problem, how do we: Get an idea of how difficult it is? Develop an algorithm to solve it? 2

Common Types of Algorithms Greedy Algorithms Divide and Conquer Dynamic Programming We have already seen some examples for each. We will look at the general techniques and some additional examples. 3

Greedy Algorithms Take what you can get now Algorithm uses multiple phases or steps. In each phase a local decision is made that appears to be good. Making a local decision is fast (often O(log N) time). Examples: Dijkstra s, Prim s, Kruskal s Greedy algorithms assume that making locally optimal decisions leads to a global optimum. This works for some problems. For many others it doesn t. Greedy algorithms are still useful to find approximate solutions. 4

ASCII Encoding Character Decimal Binary A 65 1000001 B 66 1000010 C 67 1000011 D 68 1000100 E 69 1000101 a 97 1100000 b 98 1100001 c 99 1100010 d 100 1100011 e 101 1100100 The ASCII codec contains 128 characters (about 100 printable characters + special chars). Each character needs bits of space. Can we store data more efficiently? 5

A 5-Character Alphabet Character Decimal Binary a 0 000" e 1 001" i 2 010" s 3 011" t 4 100" space 5 101" newline 6 110" 6

A 5-Character Alphabet Assume we see each character with a certain frequency in a textfile. We can then compute the total number of bits required to store the file. Character Decimal Binary Code Frequency Total bits a 0 000" 10 30 e 1 001" 15 45 i 2 010" 12 36 s 3 011" 3 9 t 4 100" 4 12 space 5 101" 13 39 newline 6 110" 1 3 7 Total: 175

Prefix Trees Character Binary a 000" 0 1 e 001" i 010" 0 1 0 1 s 011" t 100" space 101" newline 110" file size 0 1 0 1 0 0 a e i s t sp nl depth of character i frequency of i in the file 8

Prefix Trees Character Binary a 000" 0 1 e 001" i 010" 0 1 0 1 s 011" t 100" space 101" newline 110" file size 0 1 0 1 0 0 a e i s t sp nl depth of character i frequency of i in the file Can we restructure the tree to minimize the file size? 9

Prefix Trees Character Binary a 000" 0 1 e 001" i 010" 0 1 0 1 s 011" t 100" space 101" newline 110" 0 1 0 1 0 0 a e i s t sp nl depth of character i file size frequency of i in the file Prefix 11 is not used for any other character than nl. 10

Prefix Trees Character Binary a 000" e 001" i 010" s 011" t 100" space 101" newline 11" 0 1 0 1 0 1 0 1 0 a e i s t depth of character i 0 1 sp nl file size frequency of i in the file Prefix 11 is not used for any other character than nl. 11

Prefix Trees We cannot place characters on interior nodes, or else encoded sequences would be ambiguous. 0 1 0 nl e a 0 1 0 1 i 000110 t s sp 12

Prefix Trees We cannot place characters on interior nodes, or else encoded sequences would be ambiguous. 0 1 0 nl e a 0 1 0 1 i 000110 e i t t s sp 13

Prefix Trees We cannot place characters on interior nodes, or else encoded sequences would be ambiguous. 0 1 0 nl e a 0 1 0 1 i 000110 nl sp t t s sp 14

Huffman Code chr bin fi e 01" 15 sp 11" 13 i 10" 12 a 001 10 t 0001 4 s 00000 3 s 0 0 1 nl 0 1 t 0 1 a 0 1 1 e 0 i 1 sp nl 00001" 1 file size All characters are at leaves. Frequent characters have short codes. Rare characters have long codes. 15

Huffman Code chr bin fi e 01" 15 sp 11" 13 i 10" 12 e i sp a 001 10 a t 0001 4 s 00000 3 nl 00001" 1 Total size: 146 s nl t 0000001001000100001 This example: Save 16% space compared to standard coding. Typically much better compression (for larger files and alphabets). 16

Huffman Code chr bin fi e 01" 15 sp 11" 13 i 10" 12 e i sp a 001 10 a t 0001 4 s 00000 3 nl 00001" 1 Total size: 146 s nl t 0000001001000100001 This example: Save 16% space compared to standard coding. Typically much better compression (for larger files and alphabets). 17

Huffman s Algorithm 10 15 12 3 4 13 1 a e i s t sp nl Maintain a forest of prefix trees. Weight of a tree T = sum of frequencies of characters in T. 18

Huffman s Algorithm 4 T1 10 15 12 4 13 a e i t sp s nl In every phase: Choose the two trees with smallest weight and merge them. 19

Huffman s Algorithm 8 T2 T1 10 15 12 13 a e i sp s nl t In every phase: Choose the two trees with smallest weight and merge them. 20

Huffman s Algorithm T2 18 T3 T1 15 12 13 e i sp s nl t a In every phase: Choose the two trees with smallest weight and merge them. 21

Huffman s Algorithm 18 T3 T4 24 T1 T2 15 e i sp s nl t a In every phase: Choose the two trees with smallest weight and merge them. 22

Huffman s Algorithm 33 T5 T3 T4 24 T1 T2 i sp s nl t a e In every phase: Choose the two trees with smallest weight and merge them. 23

Huffman s Algorithm 58 T6 T5 T2 T3 Selecting the two minimum weight trees: O(log N) each. T4 s T1 nl t We do this N times. O(N log N) e a i sp This is clearly a greedy algorithm as we consider then two lowest-weight trees at any level. Keep the trees in the forest on a heap. 24

Divide and Conquer Algorithms Algorithms consist of two parts: Divide: Decompose the problem into smaller sub-problems. Solve each problem recursively (down to the base case). Conquer: Solve the problem by combining solutions to the sub-problem. 25

Divide and Conquer Example Algorithms Merge Sort. Quick Sort. Binary Search. Towers of Hanoi. These algorithms work efficiently because: The subproblems are independent. Solving the subproblems first makes the overall problem easier. 26

Merge Sort Split the array in half, recursively sort each half. Merge the two sorted lists. 34 8 64 2 51 32 21 1 27

Merge Sort Split the array in half, recursively sort each half. Merge the two sorted lists. 34 8 64 2 51 32 21 1 28

Merge Sort Split the array in half, recursively sort each half. Merge the two sorted lists. 34 8 64 2 51 32 21 1 29

Merge Sort Split the array in half, recursively sort each half. Merge the two sorted lists. 34 8 64 2 51 32 21 1 8 34 2 64 32 51 1 21 30

Merge Sort Split the array in half, recursively sort each half. Merge the two sorted lists. 34 8 64 2 51 32 21 1 8 34 2 64 32 51 1 21 2 8 34 64 1 21 32 51 31

Merge Sort Split the array in half, recursively sort each half. Merge the two sorted lists. 34 8 64 2 51 32 21 1 8 34 2 64 32 51 1 21 2 8 34 64 1 21 32 51 1 2 8 21 32 34 51 64 32

Merge Sort Running Time Base case: N=1 (sort a 1-element list). T(1) = 1 Recurrence: T(N) = 2 T(N/2) + N Merge the two halfs Recursively sort each half 33

Running Time Analysis for Merge Sort and Quick Sort with Perfect Pivot. assume 34

Running time of Divide and Conquer Algorithms: Master Theorem Most divide and conquer algorithms have the following running time equation: The Master Theorem states that this recurrence relation has the following solution: 35

Master Theorem: MergeSort Example: Merge Sort This is Case 2: 36

Dynamic Programming Algorithms In some cases, recursive algorithms (such as the ones used for Divide and Conquer algorithms) won t work. That s because the solution to a subproblem is used more than once. Merge Sort works because each partition is processed exactly once. Dynamic Programming algorithms solve this problem by systematically recording the solution to sub-problems in a table and re-using them later. 37

Broken Fibonacci 1,1,2,3,5,8,13,21,.. public int fibonacci(int k) throws IllegalArgumentException{ if (k < 1) { throw new IllegalArgumentException("Expecting a positive integer."); } if (k == 1 k == 2) { return 1; } else { return fibonacci(k-1) + fibonacci(k-2); } } Base case: 1 step T(1) = O(c), T(2) = O(c) Recursive calls: T(k) = O(T(k-1) + T(k-2)) 38

Analyzing the Recursive Fibonacci Solution Recursive calls: T(k) = O(T(k-1) + T(k-2)) Base case: T(1) = O(c), T(2) = O(c) T(N) each node is one recursive call T(N-1) T(N-2) T(N-2) T(N-3) T(N-3) T(N-4) T(N-3) T(3) T(N-4) T(3) T(1) T(2) T(1) T(2) 39

Dynamic Programming Fibonacci public int fibonacci(int k) throws IllegalArgumentException{ } if (k < 1) { throw new IllegalArgumentException("Expecting a positive integer."); } int b = 1; //k-2 int a = 1; //k-1 for (int i=3; i<=k; i++) { int new_fib = a + b; b = a; a = new_fib; } return a; T(N) = O(N) T(k) = k 40

Longest Increasing Subsequence Given a sequence of numbers, find the longest increasing (not necessarily contiguous) subsequence. 5 2 8 6 3 6 9 7 5 8 9 41

Longest Increasing Subsequence Given a sequence of numbers, find the longest increasing (not necessarily contiguous) subsequence. 5 2 8 6 3 6 9 7 2 3 6 7 42

Longest Increasing Subsequence We can think of this problem as a graph problem. 5 2 8 6 3 6 9 7 This is a DAG. Our goal is to find the longest path. 43

Longest Increasing Subsequence: Recursive Solution 5 2 8 6 3 6 9 7 Step 1: Reducing the problem to easier subproblems (recursive divide-and-conquer solution) LIS(i) { return max( {LIS(j) for j=j..i-1 if a[j] < a[i]} ) + 1 } 44

Longest Increasing Subsequence: Recursive Solution LIS(i) { return max( {LIS(j) for j=0..i-1 if a[j] < a[i]} ) + 1 } LIS(7) LIS(6) LIS(0) LIS(1) LIS(3) LIS(4) LIS(5) LIS(0) LIS(1) LIS(1) LIS(0) LIS(1) LIS(4) LIS(1) 45

Longest Increasing Subsequence: Dynamic Programming L = new Integer[n]; for i = 1 n { L[j] = max( {L(j) for j=0..i-1 if a[j] < a[i]} ) + 1 } i 0 1 2 3 4 5 6 7 a[i] 5 2 8 6 3 6 9 7 L[i] 0 0 46

Longest Increasing Subsequence: Dynamic Programming L = new Integer[n]; for i = 1 n { L[j] = max( {L(j) for j=0..i-1 if a[j] < a[i]} ) + 1 } i 0 1 2 3 4 5 6 7 a[i] 5 2 8 6 3 6 9 7 L[i] 0 0 1 47

Longest Increasing Subsequence: Dynamic Programming L = new Integer[n]; for i = 1 n { L[j] = max( {L(j) for j=0..i-1 if a[j] < a[i]} ) + 1 } i 0 1 2 3 4 5 6 7 a[i] 5 2 8 6 3 6 9 7 L[i] 0 0 1 1 48

Longest Increasing Subsequence: Dynamic Programming L = new Integer[n]; for i = 1 n { L[j] = max( {L(j) for j=0..i-1 if a[j] < a[i]} ) + 1 } i 0 1 2 3 4 5 6 7 a[i] 5 2 8 6 3 6 9 7 L[i] 0 0 1 1 1 49

Longest Increasing Subsequence: Dynamic Programming L = new Integer[n]; for i = 1 n { L[j] = max( {L(j) for j=0..i-1 if a[j] < a[i]} ) + 1 } i 0 1 2 3 4 5 6 7 a[i] 5 2 8 6 3 6 9 7 L[i] 0 0 1 1 1 2 50

Longest Increasing Subsequence: Dynamic Programming L = new Integer[n]; for i = 1 n { L[j] = max( {L(j) for j=0..i-1 if a[j] < a[i]} ) + 1 } i 0 1 2 3 4 5 6 7 a[i] 5 2 8 6 3 6 9 7 L[i] 0 0 1 1 1 2 3 51

Longest Increasing Subsequence: Dynamic Programming L = new Integer[n]; for i = 1 n { L[j] = max( {L(j) for j=0..i-1 if a[j] < a[i]} ) + 1 } i 0 1 2 3 4 5 6 7 a[i] 5 2 8 6 3 6 9 7 L[i] 0 0 1 1 1 2 3 3 52

Longest Increasing Subsequence: Dynamic Programming O(N 2 ) L = new Integer[n]; for i = 1 n { L[j] = max( {L(j) for j=0..i-1 if a[j] < a[i]} ) + 1 } i 0 1 2 3 4 5 6 7 a[i] 5 2 8 6 3 6 9 7 L[i] 0 0 1 1 1 2 3 3 53

Dynamic Programming Example: Minimum Edit Distance The Minimum Edit Distance (Levenshtein Distance) between two strings s and t is the minimal number of insertions, deletions, and substitutions needed to convert s into t. SATURDAY SUNDAY 54

Dynamic Programming Example: Minimum Edit Distance The Minimum Edit Distance (Levenshtein Distance) between two strings s and t is the minimal number of insertions, deletions, and substitutions needed to convert s into t. delete A SATURDAY STURDAY SUNDAY 55

Dynamic Programming Example: Minimum Edit Distance The Minimum Edit Distance (Levenshtein Distance) between two strings s and t is the minimal number of insertions, deletions, and substitutions needed to convert s into t. delete A delete T SATURDAY STURDAY SURDAY SUNDAY 56

Dynamic Programming Example: Minimum Edit Distance The Minimum Edit Distance between two strings s and t is the minimal number of insertions, deletions, and substitutions needed to convert s into t. delete A SATURDAY STURDAY Minimum Edit Distance = 3 delete T Substitute R with N SURDAY SUNDAY 57

Edit Distance as Search Initial state s, Goal state t. Try each operation for each letter. Try to find the shortest path. ins SATURDAY del subs SSATURDAY ATURDAY SATURDAY SUNDAY Search space is HUGE and contains many duplicate states. 58

Dynamic Programming Algorithm for Edit Distance Assume we have two strings s = s1,s2,,sn and t = t1, t2,, tm Let D(i,j) be the minimum edit distance between s[0..i] and t[0..j]. For example s = SATURDAY, t = SUNDAY D(2,3) = 2 SA subs A / U SU 59 insert N SUN

Dynamic Programming Algorithm for Edit Distance Let D(i,j) be the minimum edit distance between s[0..i] and t[0..j]. Basic approach: Fill a table by computing D(i,j) for all (0 < i < n) and (0 < j < m). Do this bottom-up, starting with small i and j. Table entries for larger i and j are based on previous entries. 60

Dynamic Programming Algorithm for Edit Distance For i = 1..n For j = 1..m For i = 1..n { For j = 1..m { } } 61

Edit Distance Example D(i,j) Y 8 initialization A 7 D 6 R 5 U 4 T 3 A 2 S 1-0 1 2 3 4 5 6 - S U N D A Y 62

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 S 1-0 1 2 3 4 5 6 - S U N D A Y 63

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 S 1 0-0 1 2 3 4 5 6 - S U N D A Y 64

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 S 1 0 1-0 1 2 3 4 5 6 - S U N D A Y 65

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 S 1 0 1 2-0 1 2 3 4 5 6 - S U N D A Y 66

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 S 1 0 1 2 3-0 1 2 3 4 5 6 - S U N D A Y 67

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 S 1 0 1 2 3 4-0 1 2 3 4 5 6 - S U N D A Y 68

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 69

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 1 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 70

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 1 1 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 71

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 1 1 2 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 72

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 1 1 2 3 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 73

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 1 1 2 3 3 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 74

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 A 2 1 1 2 3 3 4 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 75

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 T 3 2 2 2 3 4 4 A 2 1 1 2 3 3 4 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 76

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 U 4 3 2 3 3 4 5 T 3 2 2 2 3 4 4 A 2 1 1 2 3 3 4 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 77

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 R 5 4 3 3 4 4 5 U 4 3 2 3 3 4 5 T 3 2 2 2 3 4 4 A 2 1 1 2 3 3 4 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 78

deletion insertion subst or equal D(i,j) Y 8 A 7 D 6 5 4 4 3 4 5 R 5 4 3 3 4 4 5 U 4 3 2 3 3 4 5 T 3 2 2 2 3 4 4 A 2 1 1 2 3 3 4 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 79

deletion insertion subst or equal D(i,j) Y 8 A 7 6 5 5 4 3 4 D 6 5 4 4 3 4 5 R 5 4 3 3 4 4 5 U 4 3 2 3 3 4 5 T 3 2 2 2 3 4 4 A 2 1 1 2 3 3 4 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 80

deletion insertion subst or equal D(i,j) Y 8 7 6 6 5 4 3 A 7 6 5 5 4 3 4 D 6 5 4 4 3 4 5 R 5 4 3 3 4 4 5 U 4 3 2 3 3 4 5 T 3 2 2 2 3 4 4 A 2 1 1 2 3 3 4 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 81

deletion insertion subst or equal D(i,j) Y 8 7 6 6 5 4 3 A 7 6 5 5 4 3 4 D 6 5 4 4 3 4 5 R 5 4 subs 3 3 4 4 5 U 4 3 2 3 3 4 5 T 3 2 2 2 3 4 4 A 2 1 1 2 3 3 4 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 82

deletion insertion subst or equal D(i,j) Y 8 7 6 6 5 4 3 A 7 6 5 5 4 3 4 D 6 5 4 4 3 4 5 R 5 4 subs 3 3 4 4 5 U 4 3 2 3 3 4 5 T 3 2 2 2 3 4 4 A 2 1 1 2 3 3 4 S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 83

deletion insertion subst or equal D(i,j) Y 8 7 6 6 5 4 3 A 7 6 5 5 4 3 4 D 6 5 4 4 3 4 5 R 5 4 subs 3 3 4 4 5 U 4 3 2 3 3 4 5 T 3 2 2 2 3 4 4 ins A 2 1 1 2 3 3 4 ins S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 84

deletion insertion subst or equal SUNDAY +A SAUNDAY + T SATUNDAY N/R SATURDAY D(i,j) Y 8 7 6 6 5 4 3 A 7 6 5 5 4 3 4 D 6 5 4 4 3 4 5 R 5 4 subs 3 3 4 4 5 U 4 3 2 3 3 4 5 T 3 2 2 2 3 4 4 ins A 2 1 1 2 3 3 4 ins S 1 0 1 2 3 4 5-0 1 2 3 4 5 6 - S U N D A Y 85