Grokking Algorithms



Download 6,4 Mb.
Pdf ko'rish
bet98/120
Sana21.12.2022
Hajmi6,4 Mb.
#893167
1   ...   94   95   96   97   98   99   100   101   ...   120
Bog'liq
Grokking Algorithms An Illustrated Guide for Programmers and Other

Chapter 10
 
 
I
 
 
k-nearest neighbors
• Feature extraction means converting an item (like a fruit or a user) 
into a list of numbers that can be compared.
• Picking good features is an important part of a successful KNN 
algorithm.


203
In this chapter
• 
You get a brief overview of 10 algorithms
that weren’t covered in this book, and why
they’re useful.
• 
You get pointers on what to read next,
depending on what your interests are.
where to 
go next
11
Trees
Let’s go back to the binary search example. 
When a user logs in to Facebook, Facebook 
has to look through a big array to see if the 
username exists. We said the fastest way to 
search through this array is to run binary 
search. But there’s a problem: every time a new 
user signs up, you insert their username into 
the array
. hen you have to re-sort the array, 
because binary search only works with sorted 
arrays. Wouldn’t it be nice if you could insert 


204
Chapter 11
 
 
I
 
 
Where to go next
the username into the right slot in the array right away, so you don’t 
have to sort the array a
terward? hat’s the idea behind the 
binary search 
tree 
data structure.
A binary search tree looks like this.
For every node, the nodes to its let are
smaller
in value, and the nodes 
to the right are 
larger
in value.
Suppose you’re searching for Maggie. You start at the root node.


205
Trees
Maggie
comes a
ter 
David
, so go toward the right.
Maggie
comes before 
Manning
, so go to the let.
You found Maggie! It’s almost like running a binary search! Searching 
for an element in a binary search tree takes O(log 
n
) time 
on average 
and O(
n
) time in the 
worst case
. Searching a sorted array takes O(log 
n

time in the 
worst case
, so you might think a sorted array is better. But a 
binary search tree is a lot faster for insertions and deletions on average.
Binary search trees have some downsides too: for one thing, you
don’t get random access. You can’t say, “Give me the ith element of
this tree.” hose performance times are also on 
average
and rely on
the tree being balanced. Suppose you have an imbalanced tree like the 
one shown next.


206

Download 6,4 Mb.

Do'stlaringiz bilan baham:
1   ...   94   95   96   97   98   99   100   101   ...   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