Recursion What is Recursion?



Download 379 Kb.
bet2/3
Sana28.09.2021
Hajmi379 Kb.
#187675
1   2   3
Bog'liq
Materi #2 Recursion

Factorial Expression 2:

  • Factorial Expression 2:
  • fact(n) = n * (n – 1) * (n – 2) * … * 1
  • fact(n – 1) = (n – 1) * (n – 2) * … * 1
  • fact(n – 2) = (n – 2) * … * 1
  • :
  • fact(1) = 1
  • I.e.,
  • fact(n) = n * (n – 1) * (n – 2) * … * 1
  • = n * fact(n – 1)
  • fact(n-1)

Solving Problems Recursively

  • Suppose that the general form of the problem has some parameter n (integer)
  • Simply assume that the answer for the case n-1 is known (given)
  • Then express the solution for the n case in terms of the n-1 case
  • Find “base case”
  • This may be easy (often, fortunately) but is occasionally quite difficult
  • You have to imagine that the "case n-1" solution has been handed to you for free!
  • The key is to express the "case n" solution in terms of the n-1 solution
  • This involves domain-specific knowledge

Download 379 Kb.

Do'stlaringiz bilan baham:
1   2   3




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