1 / 6

REKURSI

REKURSI. Struktur data. Pengertian Rekursi. Rekursi berarti suatu proses yg bisa memanggil dirinya sendiri. Sifat rekursi dimiliki oleh beberapa statement Pascal

ova
Download Presentation

REKURSI

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. REKURSI Struktur data

  2. Pengertian Rekursi • Rekursi berarti suatu proses yg bisa memanggil dirinya sendiri. • Sifat rekursi dimiliki oleh beberapa statement Pascal • Rekursi merupakan teknik pemrograman yg berdaya guna untuk digunakan pada pekerjaan pemrograman dg mengekspresikannya kedalam modul-modul dr program lain dg menambahkan langkah-langkah sejenis. • Contoh paling sederhana dr proses rekursi adalah menghitung nilai FAKTORIAL dan deret FIBONACCI dr suatu bilangan bulat.

  3. Menentukan Nilai Faktorial bilangan bulat positif! Contoh : 0! = 1 1! = 1 x 0! = 1 x 1 = 1 2! = 2 x 1! = 2 x 1 x 0! = 2 x 1 x 1 = 2 N! = 1  jika N=0 N! = N x (N-1)  jika N > 0 N = Bilangan yg akan difaktorialkan Notasi pemrograman : faktorial (N) = 1 , untuk N=0 faktorial (N) = N x faktorial (N-1) , untuk N>0

  4. Example program : Function faktorial (N:byte) : longint ; begin if N=0 then faktorial:=1 else faktorial:=N x faktorial (N-1) ; end; begin clrscr; write (‘Input Bilangan yang akan difaktorialkan=‘); readln (N); write (N , ’!=’ , faktorial(N) ); end

  5. Menentukan Deret Fibonacci • Contoh : fibonacci(0)=1 fibonacci (N)=1 jika N=0 atau N=1 fibonacci(1)= 1 fibonacci (N) = fibonacci (N-2) + fibonacci (N-1)  jika N>1 fibonacci (2) = fibonacci (0) + fibonacci (1) fibonacci (3) = fibonacci (3-2) + fibonacci (3-1) = fibonacci 1 + fibonacci 2 = 1 + fibonacci (2-2) + fibonacci (2-1) = 1 + 1 + 1 = 3

  6. Example program : function fibo (N:byte) : byte ; begin if (N=0) or (N=1) then fibo:=1 else fibo:=fibo (N-1) + fibo (N-2) end; begin clrscr; writeln (‘Menentukan Deret Fibonacci ke-N’) writeln (‘---------------------------------------------’) writeln; write (‘Input deret ke =‘); readln (N) ; write (‘Deret fibo ke =‘,N,’=‘, fibo (N)) ; end

More Related