Your SlideShare is downloading. ×
Recursive
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Recursive

332

Published on

Published in: Travel, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
332
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Ðåêóðñèâ àëãîðèòì
  • 2. Ðåêóðñèâ àëãîðèòì ãýæ þó âý?
    • Ðåêóðñèâ (äàõèí äàâòàãäàõ) àëãîðèòì ãýäýã íü íýã áóþó õýä õýäýí ðåêóðñèâ ïðîöåäóð áà ôóíêöýýñ òîãòñîí àëãîðèòì þì.
    • Õýðýâ ïðîöåäóð Ï íü íýã áóþó õýä õýäýí óäàà ïðîöåäóð Ï-ã äóóääàã áîë ýíý ïðîöåäóðûã ðåêóðñèâ ïðîöåäóð ãýíý.
  • 3. Ðåêóðñèâ àëãîðèòì ãýæ þó âý?
    • Õýðýâ ïðîöåäóð áîëîí ôóíêö ººðºº ººðòºº õàíääàã, ººðººð õýëáýë ººðºº ººðèé㺺 äóóäàæ àøèãëàäàã áîë ò¿¿íèéã ðåêóðñèâ ïðîöåäóð áîëîí ôóíêö ãýæ íýðëýíý.
    • Òýäãýýð äóóäàëòûã ðåêóðñèâ äóóäàëò ãýíý.
  • 4. Ðåêóðñèâ àëãîðèòì ãýæ þó âý?
  • 5. Ðåêóðñèâèéí òºðë¿¿ä
    • Ýíãèéí ðåêóðñ - ðåêóðñèâ äóóäàëò íü òóõàéí äýä àëãîðèòìûíõàà äîòîð äóóäàãääàã.
    • Çýðýã ðåêóðñ - Ðåêóðñèâ äóóäàëò íü ðåêóðñèâ äýä àëãîðèòìûí äîòîðõ ººð äýä àëãîðèòìä äóóäàãääàã.
    Ï ïðîöåäóðûí äîòîð Ê ïðîöåäóð áèé. Ýíý Ê ïðîöåäóð äîòðîîñ Ï ïðîöåäóðò õàíääàã. Ï ïðîöåäóðûí äîòðîîñ Ï ïðîöåäóðò õàíääàã.
  • 6. Þóíä õýðýãëýãääýã âý?
    • Ðåêóðñèâ àðãà íü
    • - ªºð àðãààð áîäîõîä íèëýýä õ¿íä áîäëîãóóäûã áîäîõ
    • - Ðåêóðñèâýýð áîäîãäîõîîð òîäîðõîéëîãäñîí áîäëîãóóäûã áîäîõ
  • 7. ßìàð áîäëîãûã áîäîõ âý?
    • 1.ªºðòýé íü èæèë áîëîâ÷ ò¿¿íýýñ õÿëáàð áîäëîãîîð ñîëèæ äàõèí òîäîðõîéëîõ áîëîìæòîé.
    • 2.Øèéä íü øóóä ìýäýãäýæ áàéõ ýñâýë øóóä áîäîæ áîëîõ íýã þìóó õýä õýäýí ¿íäñýí òîõèîëäîë òîé.
    Øèéä íü øóóä îëäîæ áàéõ, öààø äàõèí ðåêóðñèâýýð òîäîðõîéëîõ áîëîìæã¿é òóñãàé òîõèîëäîë.
  • 8. ßìàð áîäëîãûã áîäîõ âý?
    • 3.Õÿëáàð áîäëîãîîð ñîëèõ ïðîöåññûã äàâòàæ õýðýãëýõýä óã áîäëîãî ò¿¿íèé ¿íäñýí òîõèîëäîëä çààâàë õ¿ðäýã.
    • 4.¯íäñýí òîõèîëäîëûí øèéäèéã àøèãëàí àíõíû áîäëîãûí øèéäèéã îëæ áîëäîã.
  • 9. Ðåêóðñèâ áîäëîãûí ¿íäñýí òîõèîëäîë
    • Ðåêóðñèâ áîäëîãî á¿ðò ÿäàæ íýã ¿íäñýí òîõèîëäîë áàéõ ¸ñòîé.
    • - Õÿëáàð áîäëîãîíä äàâòàí øèëæèõ ïðîöåññûã òºãñãºõ íºõöºë áîëíî.
    • - Áîäëîãûí øèéäèéã áîäîæ ãàðãàõàä àøèãëàãäàõ ¿íäñýí íýãæ áîëíî.
    Øóóä òîäîðõîéëîãäîõ ¿íäñýí òîõèîëäîë áàéõã¿é áîë ðåêóðñèâ àëãîðèòì ººðºº ººðòºº òºãñãºëã¿é õàíäàõàä õ¿ðíý.
  • 10. Ðåêóðñèâýýð ÿàæ áîäëîãî áîäîõ âý?
    • 1. Òîäîðõîé òîõèîëäîëä øóóä øèéäèéã òîäîðõîéëíî.
    • 2. Áîäëîãûã ò¿¿íòýé èæèë òàâèëòàé äýä áîäëîãóóäàä õóâààíà.
    • 3. Äýä áîäëîãóóäûã øèéäíý.
    • 4. Äýä áîäëîãóóäûí øèéäèéã àøèãëàí ¿íäñýí áîäëîãûã øèéäíý.
    ¯íäñýí áà äýä áîäëîãóóäûí øèéäèéã òîäîðõîé-ëîõäîî ðåêóðñèâ àðãûã àøèãëàñàí áàéõ
  • 11. Ðåêóðñèâ àðãûí îíöëîã
    • Àëãîðèòì õèð õ¿íä, íèéëìýë áàéõ íü
    • à) õè÷íýýí ðåêóðñèâ äóóäàëò áàéõ ,
    • á) òýäãýýð íü ïðîãðàììûí õààíà äóóäàãäàõ çýðãýýñ õàìààðíà.
    • Ðåêóðñèâýýð áîäëîãûã áîäîõäîî òºãñãºõ íºõöëèéã òàâèõ øààðäëàãàòàé. Ýñ òýãâýë ýíý íü ¿ë òºãñºõ ïðîãðàìì áîëíî.
    Òîäîðõîé õÿçãààðëàëò
  • 12. Ðåêóðñèâ àðãûí ñóë òàëóóä
    • Çàðèì ïðîãðàìì÷èëàëûí õýëí¿¿ä ðåêóðñ-èéã çºâøººðäºãã¿é. Æ: Ìàøèíû õýë¿¿ä. Fortran, Cobol ãýõ ìýò.
    • ªðòºã ºíäºðòýé àðãà: Ïðîãðàììûí áèåëýõ õóðä óäààí, ñàíàõ îé èõ øààðääàã.
    • Çàðèì òîõèîëäîëä ýíý àðãûã àøèãëàõ íü áîäëîãûã õýò õ¿íäð¿¿ëñýí, íèéëìýë áîëãîñîí áàéõ òàëòàé áàéäàã.
  • 13. Æèøýý
    • Function factorial (unsigned integer n)
    • unsigned integer f
    • if n>1
    • f:=n*factorial (n-1)
    • else
    • f:=1
    • return (f);
  • 14. Æèøýý
    • n=3 f=3*factorial (2)
    • n=2 f=2*factorial (1)
    • n=1 f=1*factorial (0)
    • n=0
    • f=1
    • return(1)
    • f=1*1 return(1)
    • f=2*1 return(2)
    • f=3*2 return(6)
  • 15. Æèøýý
    • Function fibonacci (unsigned integer n)
    • unsigned integer fib
    • if n<2
    • fib:=n
    • else
    • fib:=fibonacci (n-1)+fibonacci (n-2)
    • return (fib);
  • 16. Æèøýý
      • n=3 fib=fibonacci (2)+fibonacci (1)
      • n=2 fib=fibonacci (1)+fibonacci (0)
      • n=1
      • fib=1
      • n=0
      • fib=0
      • return(0)
      • fib=1 return(1)
      • fib=1+0 return(1)
      • fib=1+1 return(2)
  • 17. Æèøýý
    • Function factorial (unsigned integer n)
    • i, fac: unsigned integer
    • fac:=1
    • for i:=1 to n do fac:=fac*i
    • return (fac);
  • 18. Æèøýý
    • Function fibonacci ( unsigned integer n)
    • i, older, new, old, fib: unsigned integer;
    • older:=1 old:=0 new:=0
    • for i:=1 to n do
    • begin
    • new:=old+older
    • older:=old
    • old:=new
    • end
    • fib:=new
    • return (fib);
  • 19. Æèøýý:Õàíîéí öàìõàã
    • 19-ð çóóíä Edward Lucas àíõ ýíý áîäëîãûã äýâø¿¿ëæ áàéñàí áºãººä ¿¿íèéã ðåêóðñèâ àðãûã àøèãëàí áîääîã áºãººä ýíý íü ðåêóðñèâ àëãîðèòìûí ñîíãîäîã æèøýý áîëîí ñóäëàãääàã. ßàãààä ãýâýë ýíý áîäëîãûã ðåêóðñ àøèãëàõã¿éãýýð áîäîõîä òèéì ÷ óõààëàã áîäîëò ãàðäàãã¿é áàéíà.
  • 20. Æèøýý a b c
  • 21. Æèøýý a b c
  • 22. Æèøýý
    • Procedure Hanoi (source,dest,temp,n: integer);
    • if n:=1 then move (a,b)
    • else
    • begin
    • hanoi (a,c,b,n-1)
    • move(a,b)
    • hanoi (c,b,a,n-1)
    • end
    • end;
  • 23. Æèøýý
    • Ãýâ÷ ýíý áîäëîãûã ðåêóðñ àøèãëàõã¿é-ãýýð áîäîõ îðîëäëîãóóä íèëýýä ãàð÷ áàéæýý. Òóõàéëáàë 1984 îíä Kruse ýíý áîäëîãûí ðåêóðñ áèø õóâèëáàðûã äýâø¿¿ëæ, 1986 îíä Reingold & Hansen èë¿¿ íàðèéâ÷èëàí ñóäàëæ áàéæýý.

×