Algorithm Analysis (CSC 301 2015F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Outline] [EBoard] [Reading] [Lab] [Assignment]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Algorist]
Related Courses: [Walker (2014F)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Overview
abbababa to bbaababbaRecursive formulation using s[1] ... s[n-1], t[1] .. t[m-1], s[n], t[m]
mincost(s[1]...s[n], t[1]...t[m]) =
if (s[n] == t[m])
mincost(s[1]...s[n-1], t[1]...t[m-1])
else
min(
; Delete the last character in the source and do the
; remaining transofrmations
delCost(s[n]) + mincost(s[1]...s[n-1], t[1]...t[m]),
; Insert the last character in the target and do the
; remainign transformations
insCost(t[m]) + mincost(s[1]...s[n], t[1]...t[m-1]),
; Replce the last character in the source by the last
; character in the target and do the mainreing fortransmations
trnCost(s[n],t[m]) + mincost(s[1]...s[n-1], t[1]...t[m-1]))
But we can make this a table! (See whiteboard.)
What is the cost of this algorithm? O(nm) running time with O(nm) space.
Is there a better solution? Not that I know of.