Grokking Algorithms



Download 6,4 Mb.
Pdf ko'rish
bet110/120
Sana21.12.2022
Hajmi6,4 Mb.
#893167
1   ...   106   107   108   109   110   111   112   113   ...   120
Bog'liq
Grokking Algorithms An Illustrated Guide for Programmers and Other

CHAPTER 3
3.1
Suppose I show you a call stack like this.
What information can you give me, just based on this call stack? 
 Answer: 
Here are some things you could tell me:
• 
he 
greet
function is calle
d irst, with 
name = maggie.
hen the 
greet
function calls the 
greet2
function, with
name = maggie
.
• At this point, the 
greet
function is in an incomplete,
suspended state.
• he current function call is the 
greet2
function.
• Ater this function call completes, the 
greet
function will 
resume.
3.2
Suppose you accidentally write a recursive function that runs 
forever. As you saw, your computer allocates memory on the
stack for each function call. What happens to the stack when
your recursive function runs forever?
 Answer: 
The stack grows forever. Each program has a limited 
amount of space on the call stack. When your program runs 
out of space (which it eventually will), it will exit with a stack-
overflow error.
answers to exercises


226
CHAPTER 4
4.1
Write out the code for the earlier 
sum
function.
 Answer:
def
sum(list):
if
list == []:
return
0
return
list[0] + sum(list[1:])
4.2
Write a recursive function to count the number of items in a list.
 Answer:
def
count(list):
if
list == []:
return
0
return
1 + count(list[1:])
4.3
Find the maximum number in a list.
 Answer:
def
max(list):

Download 6,4 Mb.

Do'stlaringiz bilan baham:
1   ...   106   107   108   109   110   111   112   113   ...   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