Penjelasan Algoritma Rekursif | Algoritma Faktorial dan Pangkat | Algoritma Pertemuan 57

Ridwan Ilyas
9 Jan 202118:38

Summary

TLDRThis educational video script delves into the concept of recursion in algorithms, which the author considers both challenging and beautiful. It explains recursion as a problem-solving technique where the solution involves the problem itself, often implemented within functions that call themselves. Using the analogy of mirrors reflecting each other to illustrate the self-referencing nature of recursion, the script provides a detailed example with factorial calculations. It breaks down the recursive process into base cases and recursive cases, demonstrating how functions call themselves with modified parameters until a base condition is met. The script also touches on the concept of exponentiation as another example of recursion, guiding viewers through the mathematical and algorithmic understanding of these computational techniques.

Takeaways

  • 😀 The script introduces the concept of recursive algorithms, which the speaker considers one of the most challenging and beautiful parts of the study of algorithms.
  • 🧠 Recursive algorithms are defined as techniques that solve problems by containing the problem's definition within the solution itself, often implemented within a function that calls itself.
  • 🪄 The script uses the analogy of mirrors facing each other to illustrate the concept of recursion, where an image within a mirror reflects another image, and so on, infinitely.
  • 🔢 The script explains recursion with a mathematical example, the factorial function, which is calculated by multiplying a series of descending natural numbers down to 1.
  • 📚 The basis and recursion parts of a recursive function are defined: the basis provides a stopping condition, while the recursion part defines the function in terms of itself.
  • 💡 The script provides a step-by-step breakdown of how recursion works in the context of calculating factorials, emphasizing the self-referential nature of the process.
  • 📉 The script contrasts recursive solutions with iterative ones, highlighting that recursion does not require loops or explicit iteration constructs like 'for' or 'while'.
  • 📝 An algorithmic representation of a recursive function is provided, showing how the function is defined to handle base cases and recursive cases.
  • 🔄 The script describes the process of a recursive function call and how it 'unwinds' or backtracks through the function calls until it reaches the base case.
  • 💻 The speaker encourages viewers to implement recursive algorithms in programming languages and to explore more examples to gain a deeper understanding of recursion in algorithmic problem-solving.

Q & A

  • What is the main topic discussed in the script?

    -The main topic discussed in the script is the concept of recursion in algorithms, particularly in the context of computer programming.

  • How is recursion defined in the script?

    -Recursion is defined as a technique for solving a problem where the solution itself contains the problem's definition, often implemented within a function that calls itself.

  • What is the significance of recursion in algorithms?

    -Recursion is significant in algorithms as it allows for the elegant and efficient solution of problems that can be broken down into smaller, similar subproblems, such as calculating factorials or handling nested data structures.

  • Can you provide an example of recursion from the script?

    -An example of recursion from the script is the calculation of factorials, where the factorial of a number n is defined as n times the factorial of n-1, with the base case being that the factorial of 0 is 1.

  • What is the 'basis' in the context of recursive algorithms?

    -The 'basis' in recursive algorithms refers to the base case or the simplest instance of the problem that can be solved directly without further recursion, such as when n is 0 in the factorial example.

  • What is the 'recurrence' in the context of recursive algorithms?

    -The 'recurrence' in recursive algorithms refers to the part of the algorithm where the function calls itself with a modified argument, such as reducing the problem size in each recursive call until it reaches the base case.

  • How does the script illustrate the concept of recursion with mirrors?

    -The script uses the analogy of standing between two facing mirrors to illustrate recursion. As you look into one mirror, it reflects the other mirror, which in turn reflects you, creating an infinite sequence of reflections, similar to how a recursive function calls itself.

  • What is the practical application of recursion mentioned in the script?

    -The script mentions the practical application of recursion in calculating mathematical functions like factorials and powers, where the solution involves breaking down the problem into smaller instances of the same problem.

  • How does the script explain the process of a recursive function calling itself?

    -The script explains that a recursive function calls itself with a modified argument until it reaches the base case, at which point it starts returning values back up the call stack, ultimately solving the original problem.

  • What is the importance of the base case in recursion?

    -The base case is crucial in recursion as it defines the stopping condition for the recursive calls. Without a proper base case, the recursion could continue indefinitely, leading to a stack overflow or infinite loop.

Outlines

00:00

🧠 Introduction to Recursive Algorithms

The speaker begins by introducing the concept of recursive algorithms, which they consider one of the most challenging yet beautiful topics in the study of algorithms. They explain that recursion involves a function calling itself to solve a problem, and this can be visualized through the metaphor of standing between two mirrors facing each other, creating an infinite reflection. The speaker uses the example of factorial calculation to illustrate recursion, explaining how the factorial of a number is calculated by multiplying it by the factorial of the number minus one, down to the base case where the factorial of zero is defined as one. This sets up the foundation for understanding how recursive algorithms work and their practical applications.

05:00

🔍 Deep Dive into Recursive Factorials

This paragraph delves deeper into the recursive calculation of factorials, highlighting how each factorial calculation is dependent on the result of a smaller instance of the same problem. The speaker mathematically defines the factorial function, explaining that factorial 'n' is 'n' times factorial 'n-1', with the base case being factorial '0' which equals one. They emphasize the importance of understanding both the base case and the recursive case in a recursive function. The speaker also discusses how recursive functions are implemented in programming, using the factorial function as an example to demonstrate how the function calls itself with decremented arguments until it reaches the base case.

10:02

📚 Recursive Power Calculations

The speaker transitions into explaining how recursion can be applied to calculate powers. They clarify that any number raised to the power of zero equals one, and for any positive integer 'n', the power calculation involves multiplying the base number by the result of the base number raised to the power of 'n-1'. The base case for this recursive process is when 'n' equals zero. The speaker outlines the algorithm for calculating powers recursively, emphasizing that no loops or iterations are used in this process, unlike iterative methods. They provide a step-by-step explanation of how the recursive power function works, using the example of calculating 5 to the power of 3.

15:03

🚀 Practical Implementation of Recursion

In the final paragraph, the speaker discusses the practical implementation of recursive algorithms in programming languages. They provide a detailed walkthrough of how recursive functions for factorial and power calculations are translated into code. The speaker emphasizes the importance of understanding the recursive process, from the initial function call down to reaching the base case and then unwinding the stack to return the final result. They conclude by encouraging viewers to explore more examples and cases of recursive algorithms in programming, hinting at the depth and广泛应用 of this concept. The speaker also reminds viewers to subscribe for more content and ends the session with a farewell and blessings.

Mindmap

Keywords

💡Algorithm

An algorithm is a set of step-by-step instructions designed to accomplish a specific task or solve a particular problem. In the context of the video, algorithms are central to the theme as they are the building blocks of computer programming and problem-solving. The video discusses how algorithms can be implemented recursively, which is a key concept in programming and mathematics.

💡Recursive

Recursive refers to a method of solving problems where the solution depends on solutions to smaller instances of the same problem. The video explains that a recursive algorithm is one that calls itself to solve a problem, often simplifying complex tasks by breaking them down into more manageable sub-tasks. The script uses the example of calculating factorials and powers to illustrate the concept of recursion.

💡Factorial

Factorial, denoted by the symbol '!', is a mathematical operation that multiplies a number by every positive integer less than itself down to 1. The video uses factorial as an example to demonstrate recursion, showing how the factorial of a number can be calculated by multiplying it by the factorial of the number minus one, until reaching the base case of 0! which equals 1.

💡Base Case

In recursion, the base case is the condition that stops the recursive calls and provides a direct answer to the problem. The video explains that without a proper base case, a recursive algorithm could run indefinitely. For example, in calculating factorials, the base case is when the number reaches 0, at which point the function returns 1.

💡Recursive Case

The recursive case is the part of a recursive algorithm where the function calls itself with a modified argument. The video script describes how the recursive case in calculating factorials involves the function calling itself with the argument decremented by one until it reaches the base case. This is crucial for the algorithm to eventually terminate and return a result.

💡Procedure

A procedure, in programming, is a set of steps or a sequence of instructions that perform a specific task. The video mentions procedures in relation to functions, indicating that recursion can be implemented not only in functions but also in procedures. This highlights the versatility of recursive techniques in programming.

💡Mirror Image

The video uses the metaphor of mirror images to explain the concept of recursion. When you stand between two facing mirrors, you see an infinite number of reflections. This visual example helps to illustrate how a recursive function can call itself infinitely, much like the infinite reflections in the mirrors, until a base case is reached to stop the recursion.

💡Function

In programming, a function is a block of code designed to perform a specific task and can be reused throughout the program. The video emphasizes that functions are a common way to implement recursion, as they can call themselves to perform repetitive tasks or solve smaller instances of a problem.

💡Exponential

Exponential, in mathematics, refers to an expression of the form a^n, where 'a' is the base and 'n' is the exponent. The video extends the discussion of recursion to include calculating powers, showing how the concept of recursion can be applied to determine the value of an exponential expression by breaking it down into smaller powers.

💡Implementation

Implementation in programming refers to the act of putting a plan, design, or algorithm into effect. The video discusses the implementation of recursive algorithms, specifically how recursive functions are defined and called within the context of a programming language to solve problems like calculating factorials and powers.

Highlights

Introduction to the concept of recursive algorithms, which are considered both challenging and beautiful within the study of algorithms.

Definition of recursion as a technique for solving problems by including the problem's definition within the solution.

Explanation that recursion is implemented within a function that calls itself.

Discussion on the everyday example of recursion through the reflection of mirrors facing each other.

The mathematical representation of recursion in the context of factorial calculation.

Illustration of how factorial calculation inherently contains recursive properties.

Description of the base case in recursion, which defines when the recursive process should stop.

Explanation of the recursive case, where the function calls itself with a modified argument.

Coding example of a recursive function to calculate factorials.

Simulation of how the recursive factorial function works step by step.

Introduction to the concept of exponentiation and its recursive nature.

Explanation of the base case for exponentiation, where any number to the power of zero equals one.

Recursive formula for calculating powers, demonstrating the self-referential nature of the process.

Coding example of a recursive function to calculate powers.

Simulation of the recursive power function, showing the step-by-step calculation process.

Conclusion and summary of the basic understanding of recursion in algorithmic problem-solving.

Encouragement for viewers to explore more examples and implementations of recursive algorithms.

Transcripts

play00:00

e-cash Assalamualaikum warahmatullahi

play00:03

wabarakatuh teman-teman semua kita akan

play00:06

belajar satu buah materi yang saya pikir

play00:10

dalam mata pelajarannya atau dalam ilmu

play00:15

pelajaran algoritma ini adalah eh bagian

play00:21

yang menurut saya paling sulit itu ya

play00:23

Selama saya belajar algoritma namun ini

play00:27

adalah bagian paling indah dalam tanda

play00:29

kutip dari ei5 algoritma itu sendiri

play00:33

yaitu adalah rekursif ya algoritma

play00:37

rekursif ini eh 1 bab terakhir kalau

play00:41

kita mau belajar tentang agoritma

play00:45

menarik kursi itu apa Jadi secara

play00:49

definisi tekstual ya ini mohon maaf agak

play00:51

membumi membingungkan mungkinnya dari

play00:53

definisinya rekursif adalah teknik

play00:56

menyelesaikan persoalan dimana didalam

play01:00

nah di dalam menyelesaikan persoalan itu

play01:02

mengandung definisi persoalan itu

play01:04

sendiri ya eh atau dalam bentuk

play01:09

implementasinya nanti rekursif ini

play01:11

diimplementasikan dalam sebuah fungsi

play01:13

tentu Sebelumnya kan kita sudah belajar

play01:15

apa itu fungsi Apa itu prosedur yang

play01:18

tidak langsung si tersebut nanti

play01:20

memanggil fungsi itu sendiri gitu itu

play01:23

rekursif secara implementasi sebenarnya

play01:27

eh tidak hanya dalam sebuah fungsi sih

play01:29

dalam prosedur pun juga tentu nanti

play01:33

implementasinya bisa hanya lazimnya

play01:35

ekskursif ini diimplementasikan dalam

play01:37

sebuah fungsi na dalam contoh keseharian

play01:42

misalkan kita berdiri di satu lorong

play01:45

Gimana Di Dinding antar dua lorong itu

play01:49

ada cermin yang saling berhadapan Ketika

play01:53

kita melihat cermin itu maka cermin ini

play01:56

akan memantulkan cermin di dalam kita Ed

play02:00

sang Kita dimana di belakang di cermin

play02:02

di belakang kita itu ada kita dengan

play02:04

cermin yang di depan kita lagi kalau

play02:06

kemudian di cermin yang di depan kita

play02:08

ada kita lagi terus ini dan seterusnya

play02:11

ada di dalam satu buah cermin ada kita

play02:13

yang ada cerminnya lagi lalu kemudian

play02:16

dicerminkan ada kita lagi dengan cermin

play02:18

lagi dan seterusnya teman-teman kalau

play02:21

datang anak cowok misalkan nya pergi ke

play02:25

apa namanya babersop GTA twang cukur di

play02:29

depan wajah kita ada cermin di belakang

play02:31

kita ada cermin Maka kalau kita melihat

play02:35

cermin yang ada di belakang kita itu ada

play02:38

cermin kita lagi GTA tentu kalau

play02:40

cerminnya benar-benar berhadapan atau

play02:42

non bisa coba-coba hadapan dua buah

play02:44

cermin atau kalau kita misalkan ada di

play02:46

lift yang dimana live itu Sisinya adalah

play02:49

cermin pasti kita akan melihat Sisi

play02:52

cermin itu ada kita dan cermin lagi

play02:54

terus dan seterusnya Nah itu gambaran

play02:56

bagaimana rekursif di dalam dunia

play03:00

jadi dalam satu buah bingkai persoalan

play03:02

di dalamnya ada persoalan itu sendiri

play03:05

dan di dalamnya ada persoalan itu

play03:07

sendiri begitu ya Nah nanti kita coba

play03:10

lihat dalam konteks algoritma contoh

play03:13

misalkan kita punya persoalan perulangan

play03:16

faktorial ya faktorial se0 itu satu

play03:20

faktorial satu itu satu faktorial 2 itu

play03:23

satu kali dua faktorial tiga itu satu

play03:26

kali dua kali tiga faktorial 4 itu satu

play03:29

kali dua kali tiga kali empat dan faktor

play03:31

ya lima itu satu kali dua kali tiga kali

play03:33

empat kali lima nah ini contoh tentang

play03:36

faktorial ini sudah sering dibahas di

play03:38

video-video sebelumnya teman-teman

play03:41

silahkan cek video-video saya yang

play03:43

algoritma soal faktorial baik itu di

play03:46

Sumba perulangan ataupun F ungsi Kalau

play03:50

nggak salah ada ya Bisa cek lagi di sana

play03:52

Nah ternyata Wow proses melakukan

play03:57

faktorial ini ini juga sebenarnya

play03:59

memiliki

play04:00

sifat rekursif Kenapa karena kalau kita

play04:02

lihat Oke faktorial nol itu memang satu

play04:04

Ternyata faktorial satu itu adalah

play04:08

faktor yang nol dikali satu dan

play04:10

faktorial 2 itu adalah faktorial satu

play04:13

dikali faktorial 2 faktorial tiga itu

play04:17

adalah faktorial 2 dikali dengan tiga

play04:20

faktorial 4 itu adalah faktorial tiga

play04:23

dikali dengan 4G dan faktorial 5 itu

play04:26

adalah faktorial 4 dikali lima silakan

play04:30

teman-teman di paus video ini lalu Coba

play04:32

lihat antara kiri dan kanan lihat ya Ini

play04:35

satu adalah faktorial satu kali dua

play04:38

inhaled nih mulai tiga kelihatan Ya

play04:40

gimana tiga itu adalah faktorial 2

play04:43

sebenarnya satu kali dua itulah

play04:45

faktorial 2 jadi yang kanan ini adalah

play04:48

pola rekursif yang kiri perulangan ada

play04:53

biasanya Eh rekursif ini nanti kita

play04:56

menyelesaikan persoalan-persoalan yang

play04:58

bentuknya juga perlu

play05:00

dan ya cukup silakan di-pause dipandangi

play05:02

antara kiri dengan kanan oke kalau sudah

play05:06

di Paus sudah bisa dipahami dari contoh

play05:09

ini kita lanjut nah di dalam persoalan

play05:12

faktorial terdapat persoalan faktorial

play05:15

itu sendiri lihat di dalam faktor yang

play05:18

empat itu terdapat persoalan faktorial

play05:21

3gnya jadi dalam faktorial ada persoalan

play05:24

faktorial itu sendiri nah kalau kita

play05:27

Tuliskan dalam bentuk eh matematika

play05:31

faktorial dari n itu kan satu kali dua

play05:34

kali seterusnya sampai dengan n min1

play05:37

dikalikan dengan n ya jadi faktorial

play05:40

dari n itu adalah a n kurang satu

play05:43

faktorial dikalikan dengan seperti ini

play05:45

ya faktorial 4 itu adalah empat kurang

play05:50

satu faktorial yaitu tiga faktorial

play05:52

dikalikan dengan empat dia Jadi ini

play05:54

korelasinya dengan rumus yang ada di

play05:56

bawah sini ya

play06:00

begitu ya nah jadi kita lihat di sini n

play06:03

faktorial itu dia akan bernilai 1 jika

play06:10

n-nya itu adalah nol lalu kemudian dia

play06:17

akan bernilai n caliente in 1 faktorial

play06:21

yang ini dengan posisinya ditukar aja

play06:23

jadi nw-1 faktorialnya pindah ke kanan

play06:26

kalau NY itu lebih besar dari nol ya

play06:30

jadi dia akan bernilai 1 kalau NY itu

play06:33

nol sedangkan dia akan bernilai n * n

play06:37

faktorial kalau dia lebih besar dari nol

play06:40

itu kita pindahkan ke sini rumus yang

play06:44

barusan nah yang bagian atas ini ini

play06:47

disebut dengan basis-basis ini adalah

play06:50

bagian yang mendefinisikan secara

play06:52

eksplisit sebuah Nilai N kalo Omnya nol

play06:55

maka nilainya satu eksplisit kan dan

play06:58

basis in

play07:00

ini akan menyatakan berhentinya satu

play07:02

buah proses rekursif dan dalam rekursi

play07:04

itu fungsi memanggil fungsi-fungsi

play07:06

memanggil fungsi lagi ia memanggil

play07:08

dirinya sendiri nah kapan berhentinya

play07:10

Nah itu dinyatakan dengan basis ini

play07:13

basis ini menyatakan eh bagian

play07:16

berhentinya satu buah rekursif sedangkan

play07:18

yang bagian bawah ini disebut rekaren ya

play07:22

yang mendefinisikan dirinya itu sendiri

play07:24

lihat Let's ini n faktorial adalah Endi

play07:27

kali N1 faktorial jadi dalam faktorial

play07:29

itu ada faktorial itu sendiri bagaimana

play07:32

algoritmanya kita definisikan dalam

play07:34

sebuah fungsi kita tulis function

play07:37

faktorial an integer jadi dia menerima

play07:39

satu buah input nilai Jejer lalu

play07:43

mengembalikan lagi intezaar nah kita

play07:45

langsung ke bagian algoritmanya karena

play07:47

kita tidak perlu mendefinisikan dulu

play07:49

sesuatu Nah lihat di sini ih Anne

play07:53

Avantie sama dengan nol Den riten satu

play07:57

ya basis ini menyatakan berhenti

play08:00

Hai Jadi kalau Omnya nol yang paling

play08:02

atas ini kliennya nol Maka dia

play08:09

mengembalikan nilai satu ngaji kah Tidak

play08:14

maksudnya lebih besar dari nol maka

play08:16

repaint disini LED ya n dikalikan dengan

play08:19

N1 faktorial jadi dik dari sini jadinya

play08:24

kayak gini Endi kali dengan faktorial

play08:27

jadi memanggil fungsi faktorial lagi

play08:30

cuman inputnya adalah enmind satu ya

play08:33

jadi nn yang ini ms1 nah ini eh

play08:37

penulisan algoritma seperti ini jadi

play08:39

untuk menghitung faktorial kita lihat di

play08:41

sini enggak ada perulangan enggak ada

play08:43

Luffy gak ada voernya kau teman belajar

play08:46

video-video eh video sebelumnya tentang

play08:48

faktor yg akan ada perulangan kali ini

play08:50

ada perulangannya ia akan mengambil

play08:52

fungsi faktorial Um memanggil fungsi

play08:55

faktorial itu sendiri tapi dengan

play08:57

inputnya adalah

play08:58

[Musik]

play09:00

Hai nah Gambaran simulasinya seperti apa

play09:03

kau ini etnis dulu ya enif untuk menutup

play09:05

yang ini Oke jadi misalkan kita Panggil

play09:10

fungsi faktorial 3 ia akan masukkan ke

play09:13

lagi bagian algoritmanya jika cek dulu

play09:16

apakah 3 = 0 tentu Enggak kan maka masuk

play09:21

ke yang esnya ya tadi yang F saya elne

play09:25

itu adalah n kali faktorial min 1 jadi

play09:27

masuk ke f*** edisi fungsi faktorial ini

play09:30

akan memanggil faktorial yang lain elne

play09:33

akan tiga kali faktorial 22 ini dari

play09:35

mana tiga kurang satu memanggil ke

play09:38

fungsi faktorial 2 edit di bagian

play09:42

faktorial 2 ini di cek lagi apakah 2 = 0

play09:45

tentu tidak maka dia akan memanggil lagi

play09:47

fungsi faktorial dimana disini n-nya

play09:49

sekarang 2 dikali dengan faktorial 2 min

play09:53

1 Jadi dua di California le1 berarti

play09:57

memanggil fungsi faktorial 2 Ed

play10:00

hai eh sorry memanggil fungsi faktorial

play10:02

satu lalu cek lagi apakah 1 = 0 enggak

play10:06

maka dia manggil lagi faktorial diisi

play10:08

dengan satu karenanya satu dikali

play10:11

faktorial nol Ya karena ini satu kurang

play10:14

satu Kance tiap masuk fungsi faktorial

play10:16

itu didalamnya itu dikurangi dengan eh16

play10:22

maka disini memanggil faktor yang nol

play10:25

Apakah 0 = 0 betul maka dia merica meren

play10:30

ya return value faktorial satu maka

play10:32

fungsi yang ini dia merit nilai satu kau

play10:36

ini meneliti nilai satu maka dia akan

play10:38

merugikan ke fungsi Yang sebelumnya Yang

play10:40

ini abstrak disini ini adalah satu ya

play10:46

dikalikan dengan satu yang ini maka

play10:48

nilainya adalah 1 dan ini kan satu

play10:51

digali dengan faktorial 0eh di kalian 40

play10:55

40 itu satu ia mengambil kalian nilai

play10:57

satu yang nilai satu ini akan Mas

play11:00

fungsi sistem yang di atasnya yang ini

play11:02

kita lihat di sini dua dikali faktorial

play11:05

satu faktor yang satu tadi nilainya

play11:07

sudah satu pakai maka 2 dikali 1 = 22

play11:11

akan mengembalikan ke nilai faktorial

play11:14

yang diatasnya yang ini adalah tiga

play11:17

dikali dengan faktorial 2 faktorial 2

play11:20

itu dua berarti tiga dikalikan dengan

play11:22

dua jenis = 6 jadi kalau kita masukin

play11:26

faktorial 3 Maka hasilnya adalah nilai 6

play11:29

= kalau kita menggunakan faktor yang

play11:31

akan satu kali dua kali tiga itu enam

play11:33

satu kali dua kedua dua kali 36 nah ini

play11:37

acara berpikir bagaimana menghitung

play11:42

faktorial menggunakan rekursif oke itu

play11:47

satu contoh naskah kita contoh masuk ke

play11:50

kasus yang berikutnya ya ini setiap

play11:53

kasus saya langsung buat dan dalam share

play11:55

video biasanya saya pisah enggak papa

play11:57

videonya lebih panjang

play12:00

sedikit layak nyapres Sekarang kita akan

play12:02

masuk tentang pangkat Nah kita tahu

play12:05

bahwa apangkat n itu sama dengan adik

play12:09

Aliya kali dan seterusnya sebanyak n

play12:12

jadi kita bisa tahu bahwa Apa ngaten itu

play12:15

sebenarnya Aa dikalikan dengan apangkat

play12:18

enmind satu jadi Abang Kapten itu ia

play12:23

akan menghasilkan nilai satu jika enak

play12:25

0erusahaan misalkan 55 pangkat n ya ya

play12:30

pasti satu iya pasti satu kalau enyak

play12:33

nol karena berapapun dipangkatkan nol

play12:35

itu pasti nilainya satu tapi ia akan

play12:43

mendapatkan nilai yang lain kalau Angle

play12:46

lebih dari nol adalah akal ia pangkat

play12:50

min 1 ya Jadi yang ini adalah basisnya

play12:54

yang ini adalah rekannya itu ya

play13:00

eh sebentar contoh misalkan eh kita

play13:05

lihat ya bahwa dua pangkat nol itu kan

play13:08

satu ya karena berapapun dipangkatkan

play13:10

nol itu satu nah kalau dua pangkat-1 itu

play13:15

kan sebenarnya dua dikali dua pangkat

play13:17

nol ya dua pangkat satu Tekan dua

play13:19

berarti dua dikali dengan satu lalu

play13:21

kemudian dua pangkat dua itupun

play13:23

sebenarnya dua dikali dua ^ 12 pangkat

play13:27

dua itu empat dan bukannya 2 ^ 1 itu

play13:29

adalah dua lalu kemudian dua pangkat

play13:32

tiga itu adalah dua dikali dua pangkat

play13:35

dua dan dua pangkat 4 itu adalah dua

play13:39

dikali dua pangkat tiga jadi seperti ini

play13:41

ya jikalau dua pangkat lima itu berarti

play13:44

dua dikali dua pangkat 4 yang dimaksud

play13:47

orang satu nah ini dalam proses

play13:50

menghitung pangkat kita bisa melihat

play13:53

bahwa di sini ada proses rekursif jadi

play13:56

ada persoalan yang didalamnya ada

play13:58

persoalan itu sendiri

play14:00

Hai yang bagaimana kemudian eh

play14:02

implementasinya atau kita menuliskannya

play14:05

dalam notasi algoritma kita buat disini

play14:09

pungsi ^ ia menerima masukan a&n ini eh

play14:15

iphonenya integer dan merekam value

play14:17

typenya integer tadi sini Aini sebagai

play14:19

nilai n ini sebagai Sorry nilai angkanya

play14:23

ini sebagai pangkatnya jadi kalau kita

play14:26

menulis menghitung 5 ^ 2 berarti 5,2

play14:30

atau misalnya kita mencari dua pangkat 4

play14:32

berarti 2,4 jadi bagian algoritmanya

play14:36

kita langsung saja lihat disini event =

play14:38

0 y n ini adalah pangkatnya seperti tadi

play14:41

maka dia rhythm satu sebagai basisnya

play14:45

jika tidak jika n-nya tidak sama dengan

play14:48

nol lebih besar dari nol maka riten ak5

play14:52

ya ahli ^ a koma min 1 ya jadi baritana

play14:59

dikalikan dengan

play15:00

Mbak koma n pangkat min 1 enya berkurang

play15:02

tadi misalkan eh apa namanya kedua

play15:05

pangkat 3 masuk ke sini berarti dua

play15:08

pangkat dua anaknya berkurang lalu

play15:10

disini dengan enif ditutup udah selesai

play15:14

lihat di sini dalam proses pemangkatan

play15:16

itu kita tidak melakukan perulangan

play15:19

enggak ada luping di sini enggak ada for

play15:22

disini Bagaimana simulasinya gambaran

play15:26

simulasinya misalkan kita mau

play15:27

memangkatkan 5pangkat 35 pangkat tiga

play15:30

itu lima kali lima kali 55 kali 525 25

play15:35

kali lima itu 125 nah ketika kita

play15:43

memanggil fungsi pangkat 5,5 kita cek

play15:46

inikan entengnya itu yang di belakang

play15:48

ini apakah 3 = 0 tentu tidak maka disini

play15:53

^ ini ^ ya maksudnya ^ diisikan rhythm

play15:58

ya pangkat yang ini diisi dengan 5

play16:00

^ 5,2 karena disini min1 tadi kanannya

play16:03

awalnya tiga sekarang min1 Oke berarti

play16:06

manggil fungsi pangkat 5,2 ^ 5,2 cek

play16:09

lagi apakah 2 = 0 tidak maka masuk lagi

play16:13

ke lksnya lima kali ^ 5,1 karena 2-nya

play16:16

dikurangi satu maka cek lagi di sini

play16:19

Apakah n y = 0 1 tidak sama dengan nol

play16:22

tentu maka keels lagi ^ diisi dengan

play16:25

lima kali ^ 5,0 ya di sini NY sudah nol

play16:29

Apakah 0 = 0 betul maka disini ^

play16:33

mengembalikan return value nilainya satu

play16:36

maka ini mengambil mengembalikan nilai

play16:38

satu fungsi yang paling bawah ini

play16:40

mengembalikan nilai satu nilai satu ini

play16:43

akan masuk ke sini begitu masuk ke sini

play16:45

berarti lima kali Satukan 5pangkat 5,0

play16:50

itu kan satu berarti lima kali lima kali

play16:52

satu itu sama dengan 55 ini akan masuk

play16:56

lagi ke yang ini 5 dikali pangkat 5,15

play17:00

itukan 5 berarti lima kali lima itu

play17:03

adalah 25 lalu 25 itu akan masuk lagi ke

play17:07

sini balik kesini 5 eh ^ 5,2 itu adalah

play17:12

25 jadi lima kali 25 adalah 125 itu

play17:18

gambaran Bagaimana hasil atau proses

play17:23

running kalau sih algoritma angkat tadi

play17:26

dijalankan kalau kita masukin ^ 5,3 Maka

play17:29

hasilnya akan seperti ini ya prosesnya

play17:32

dia akan memanggil fungsi manggil fungsi

play17:34

manggil fungsi manggil fungsi sampai

play17:35

dibungkus yang terakhir ketemu basisnya

play17:37

di sini levisnya kan yang ini maka dia

play17:40

akan trackback kebelakang lalu kemudian

play17:43

mereka value 125 tentu nanti akan

play17:47

menarik kalau kita coba proses ini dalam

play17:51

bahasa pemograman Ok teman-teman sampai

play17:56

di sini penjelasan tentang rekursif tadi

play17:58

teman-teman akan

play18:00

the melihat contohnya dalam bahasa

play18:02

pemograman kita coba nanti

play18:03

implementasikan dipiten dan banyak

play18:06

sebenarnya kasus-kasus dalam konsep

play18:08

algoritma pemograman itu yang

play18:11

penyelesaian yaitu dengan rekursif Ya

play18:14

itu aja eh basic penjelasan rekursif

play18:18

tentu tidak akan cukup untuk membahas

play18:20

seluruh contohnya Semoga teman-teman

play18:23

bisa paham tentang bagian yang ini

play18:26

sampai ketemu lagi di video-video

play18:28

selanjutnya saridon Ilyas Jangan lupa

play18:31

untuk subscribe ya kalau belum subscribe

play18:33

Terima kasih salam alaikum

play18:35

warahmatullahi wabarakatuh

Rate This

5.0 / 5 (0 votes)

Связанные теги
Recursive AlgorithmsProgramming ConceptsEducational ContentMathematical ExamplesAlgorithm TutorialFactorial CalculationExponential PowerCoding TechniquesLearning ResourcesComputer Science
Вам нужно краткое изложение на английском?