Grokking Algorithms



Yüklə 348,95 Kb.
Pdf görüntüsü
səhifə101/122
tarix05.12.2023
ölçüsü348,95 Kb.
#173611
1   ...   97   98   99   100   101   102   103   104   ...   122
grokking-algorithms-illustrated-programmers-curious

Chapter 11
 
 
I
 
 
Where to go next
See how it’s leaning to the right? This tree doesn’t have very good 
performance, because it isn’t balanced. There are special binary search 
trees that balance themselves. One example is the red-black tree. 
So when are binary search trees used? 
B-trees, 
a special type of binary 
tree, are commonly used to store data in databases. 
If you’re interested in databases or more-advanced data structures, 
check these out:
• B-trees
• Red-black trees
• Heaps
• Splay trees
Inverted indexes
Here’s a very simplified version of how a search engine works. Suppose 
you have three web pages with this simple content.


207
The Fourier transform
Let’s build a hash table from this content.
The keys of the hash table are the words, and the values tell 
you what pages each word appears on. Now suppose a user 
searches for 
hi
. Let’s see what pages 
hi
shows up on.
Aha: It appears on pages A and B. Let’s show the user those pages as 
the result. Or suppose the user searches for 
there
. Well, you know that 
it shows up on pages A and C. Pretty easy, huh? This is a useful data 
structure: a hash that maps words to places where they appear. This 
data structure is called an 
inverted index
, and it’s commonly used to 
build search engines. If you’re interested in search, this is a good place 
to start.
The Fourier transform
The Fourier transform is one of those rare algorithms: brilliant, 
elegant, and with a million use cases. The best analogy for the Fourier 
transform comes from Better Explained (a great website that explains 
math simply): given a smoothie, the Fourier transform will tell you the 
ingredients in the smoothie.
1
Or, to put it another way, given a song, the 
transform can separate it into individual frequencies.
It turns out that this simple idea has a lot of use cases. For example, if 
you can separate a song into frequencies, you can boost the ones you 
care about. You could boost the bass and hide the treble. The Fourier 
transform is great for processing signals. You can also use it to compress 
music. First you break an audio file down into its ingredient notes. The 
Fourier transform tells you exactly how much each note contributes 
to the overall song. So you can just get rid of the notes that aren’t 
important. That’s how the MP3 format works!
Music isn’t the only type of digital signal. The JPG format is another 
compressed format, and it works the same way. People use the Fourier 
transform to try to predict upcoming earthquakes and analyze DNA. 
1

Yüklə 348,95 Kb.

Dostları ilə paylaş:
1   ...   97   98   99   100   101   102   103   104   ...   122




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin