Grokking Algorithms


Longest common subsequence—solution



Download 6,4 Mb.
Pdf ko'rish
bet90/120
Sana21.12.2022
Hajmi6,4 Mb.
#893167
1   ...   86   87   88   89   90   91   92   93   ...   120
Bog'liq
Grokking Algorithms An Illustrated Guide for Programmers and Other

Longest common subsequence—solution
Here’s the inal grid.


185
Longest common substring
Here’s my formula fo
r illing in each cell.
And here it is in pseudocode:
if
word_a[i] == word_b[j]: 
The letters match.
cell[i][j] = cell[i-1][j-1] + 1
else

The letters don’t match.
cell[i][j] = max(cell[i-1][j], cell[i][j-1])
Whew—you did it! his is deinitely one of the toughest chapters in the 
book. So is dynamic programming ever really used?
Yes:
• Biologists use the longest common subsequence to ind similarities 
in DNA strands. hey can use this to tell how similar two animals or 
two diseases are. he longest common subsequence is being used to 
ind a cure for multiple sclerosis.
• Have you ever used dif (like 
git diff
)? Dif tells you the diferences 
between two iles, and it uses dynamic programming to do so.
• We talked about string similarity. 
Levenshtein distance
measures 
how similar two strings are, and it uses dynamic programming. 
Levenshtein distance is used for everything from spell-check to 
iguring out whether a user is uploading copyrighted data. 


186
Chapter 9
 
 
I
 
 
Dynamic programming
• Have you ever used an app that does word wrap, like Microso
t Word? 
How does it igure out where to wrap so that the line length stays 
consistent? Dynamic programming!
EXERCISE
9.3
Draw and ill in the grid to calculate the longest common substring 
between 
blue 
and 
clues
.
Recap
• Dynamic programming is useful when you’re trying to optimize 
something given a constraint. 
• You can use dynamic programming when the problem can be
broken into discrete subproblems.
• Every dynamic-programming solution involves a grid.
• he values in the cells are usually what you’re trying to optimize.
Each cell is a subproblem, so think about how you can divide your 
problem into subproblems.
• here’s no single formula for calculating a dynamic-programming 
solution.


187
In this chapter
• 
You learn to build a classiication system using
the k-nearest neighbors algorithm.
• 
You learn about feature extraction.
• 
You learn about regression: predicting a number, 
like the value of a stock tomorrow, or how much
a user will enjoy a movie.
• 
You learn about the use cases and limitations
of k-nearest neighbors.

Download 6,4 Mb.

Do'stlaringiz bilan baham:
1   ...   86   87   88   89   90   91   92   93   ...   120




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish