1 / 15

Pertemuan 1

Pertemuan 1. Rekursi. Fungsi Rekursif. Definisi fungsi rekursif . Contoh 1 : Triangle Contoh 2 : Faktorial Contoh 3 : Perkalian Contoh 4 : Fibonacci Contoh 5 : Tower of Hanoi. Fibonacci. 0,1,1,2,3,5,8,13,21,34,55,89,144,..

kelda
Télécharger la présentation

Pertemuan 1

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. Pertemuan 1 Rekursi

  2. Fungsi Rekursif • Definisifungsirekursif. • Contoh 1 : Triangle • Contoh2 : Faktorial • Contoh3 : Perkalian • Contoh4 : Fibonacci • Contoh5 : Tower of Hanoi

  3. Fibonacci • 0,1,1,2,3,5,8,13,21,34,55,89,144,.. • The Fibonacci seriesfn≥0 is a famous series defined by:f0 :≡ 0, f1 :≡ 1, fn≥2 :≡ fn−1 + fn−2 • f2 = f0 + f1 = 0 + 1 = 1 • f3 = f1 + f2 = 1 + 1 = 2 • f4 = f2 + f3 = 1 + 2 = 3 • f5 = f3 + f4 = 2 + 3 = 5 • …. Leonardo Fibonacci1170-1250

  4. Fibonacci

  5. Tracing Fibonacci • fibo (4) = ? F(4) F(2) F(3) F(2) F(0) F(1) F(1) F(0) F(1)

  6. Towers of Hanoi • Sebuah game /puzzle matematikakunodimanaadaadatigabuahtiang, dimanasalahsatutiangterdapatbeberapapiringan • Piringanakandipindahkanketiang yang lain dengansalahsatutiangmenjaditiang bantu • Untukmemindahkanadabeberapsyarat • Hanyaadasatupiringan yang berpindahdalamsatulangkah • Tidakbolehadapiringan yang beradadiataspiringan yang lebihkecil • Total langkah yang dibutuhkanuntukmenyelesaikan puzzle secaramatematikaadalah 2n -1 dengan n adalahbanyaknyapiringan

  7. Tracing Towers of Hanoi • towers(3, A, C, B) = ?

  8. resume • Kelebihan : • Program menjadilebihsingkat/sederhana • Dalambeberapakasuskasusmemangdibutuhkanpenggunaanrekursi • Kekurangan : • Kurangefektifdalamhalkecepatan • Membutuhkahmemorilebih, karenaketikasatufungsi / method memanggildirinya , dibutuhkantambahanalokasimemori. Sehinggaalokasimemori total menjadilebihbesar

  9. Tugas Rumah : TRACING 1. NPM genap : towers (4, A, C, B) = ? NPM ganjil : towers (4, C, A, B ) = ? 2. fibo(6) = ?

  10. http://coding-n-inspiring.blogspot.com • wikipedia

More Related