Grokking Algorithms



Download 24,82 Mb.
Pdf ko'rish
bet17/122
Sana22.07.2022
Hajmi24,82 Mb.
#839971
1   ...   13   14   15   16   17   18   19   20   ...   122
Bog'liq
grokking-algorithms-illustrated-programmers-curious

The number of
operations
increases drastically.


19
Recap
In general, for 
n
items, it will take 
n
! (
n
factorial) operations to 
compute the result. So this is O(
n
!) time, or 
factorial time
. It takes a 
lot of operations for everything except the smallest numbers. Once 
you’re dealing with 100+ cities, it’s impossible to calculate the answer in 
time—the Sun will collapse first.
This is a terrible algorithm! Opus should use a different one, right? But 
he can’t. This is one of the unsolved problems in computer science. 
There’s no fast known algorithm for it, and smart people think it’s 
impossible
to have a smart algorithm for this problem. The best we can 
do is come up with an approximate solution; see chapter 10 for more.
One final note: if you’re an advanced reader, check out binary search 
trees! There’s a brief description of them in the last chapter.
Recap
• Binary search is a lot faster than simple search.
• O(log 
n
) is faster than O(
n
), but it gets a lot faster once the list of 
items you’re searching through grows.
• Algorithm speed isn’t measured in seconds.
• Algorithm times are measured in terms of 
growth
of an algorithm.
• Algorithm times are written in Big O notation.



2
In this chapter
• You learn about arrays and linked lists—two of the 
most basic data structures. They’re used absolutely 
everywhere. You already used arrays in chapter 1, 
and you’ll use them in almost every chapter in this 
book. Arrays are a crucial topic, so pay attention! 
But sometimes it’s better to use a linked list instead 
of an array. This chapter explains the pros and cons 
of both so you can decide which one is right for 
your algorithm.
• You learn your first sorting algorithm. A lot of algo-
rithms only work if your data is sorted. Remember 
binary search? You can run binary search only 
on a sorted list of elements. This chapter teaches 
you selection sort. Most languages have a sorting 
algorithm built in, so you’ll rarely need to write 
your own version from scratch. But selection sort is 
a stepping stone to quicksort, which I’ll cover in the 
next chapter. Quicksort is an important algorithm, 
and it will be easier to understand if you know one 
sorting algorithm already.

Download 24,82 Mb.

Do'stlaringiz bilan baham:
1   ...   13   14   15   16   17   18   19   20   ...   122




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