Menerapkan Konsep Rekursi - Berpikir Komputasional - Rekursi

Sinau Maning
22 Aug 202317:11

Summary

TLDRThis video focuses on computational thinking and recursion strategies in algorithmic programming. It presents two problems: the first involves determining how many ways tiles can be arranged on a 2xN floor using recursion. For N = 8, there are 34 ways, following a Fibonacci-like sequence. The second problem discusses stacking pancakes of varying sizes and moving them between plates according to specific rules. The recursive solution finds the minimal steps required to move six pancakes, resulting in 63 moves. The video demonstrates these concepts through step-by-step examples.

Takeaways

  • 🧱 The problem involves placing tiles on a 2xN floor using 1x2 tiles, which can be placed either horizontally or vertically.
  • 🔢 For N=8, the number of ways to place the tiles can be calculated using a recursive relation.
  • 🔄 The recursive formula is based on the two previous terms: K(n) = K(n-1) + K(n-2).
  • 📊 Example calculations: K(1) = 1, K(2) = 2, K(3) = 3, K(4) = 5, K(5) = 8, K(6) = 13, K(7) = 21, K(8) = 34.
  • 🎯 The final answer for N=8 is 34 ways to arrange the tiles.
  • 🥞 The second problem involves moving a stack of pancakes from one plate to another, following a size-order rule.
  • 💡 The pancake problem is similar to the Tower of Hanoi problem, requiring a helper plate to transfer pancakes while maintaining the size-order.
  • ⏳ The minimum steps to transfer pancakes follow a recursive pattern: P(n) = 2 * P(n-1) + 1.
  • 📈 For example, 1 pancake takes 1 step, 2 pancakes take 3 steps, 3 pancakes take 7 steps, and 6 pancakes require 63 steps.
  • 🚀 Both problems showcase the power of recursive thinking in solving algorithmic challenges.

Q & A

  • What is the first problem described in the script?

    -The first problem is about tiling a 2xN floor with N tiles, where each tile is of size 1x2. The tiles can be placed either horizontally or vertically, and the task is to determine how many different ways the tiles can be arranged on the floor for N=8.

  • How does the script explain the solution to the tile placement problem?

    -The script explains that for N=1, there is 1 way to place the tile (vertically), and for N=2, there are 2 ways (either both vertical or both horizontal). For higher values of N, the number of ways is calculated using a recursive relation: K(n) = K(n-1) + K(n-2), where K(n) represents the number of ways to tile the floor. This relation is similar to the Fibonacci sequence.

  • What is the recursive formula provided to solve the tile placement problem?

    -The recursive formula is K(n) = K(n-1) + K(n-2), with base cases K(1) = 1 and K(2) = 2. This allows for calculating the number of ways to place tiles for any value of N.

  • How many ways can the tiles be arranged for N=8?

    -For N=8, the number of ways to arrange the tiles is 34, as calculated by the recursive formula using the previously computed values for smaller N.

  • What is the second problem described in the script?

    -The second problem is about moving a stack of pancakes from one plate to another. The largest pancake must always be at the bottom, and only one pancake can be moved at a time. Budi, the person in the problem, wants to know the minimum number of steps required to move 6 pancakes while following these rules.

  • What is the minimum number of steps required to move 6 pancakes?

    -The minimum number of steps required to move 6 pancakes is 63, as derived from a recursive relation similar to the Tower of Hanoi problem.

  • How does the recursive relation for the pancake problem work?

    -The recursive relation is P(n) = 2 * P(n-1) + 1, where P(n) is the minimum number of steps required to move n pancakes. The base case is P(1) = 1.

  • How many steps are required to move 3 pancakes?

    -To move 3 pancakes, the minimum number of steps required is 7, following the recursive process described in the script.

  • What is the general strategy for solving the pancake problem?

    -The strategy is to move the smallest pancake first, then progressively move larger pancakes while using an auxiliary plate to temporarily hold pancakes during the process. The recursive solution builds on smaller subproblems, similar to the Tower of Hanoi.

  • What are the key concepts covered in the script related to recursion?

    -The key concepts covered include recursive problem-solving techniques, the use of base cases, and recursive relations. The tile placement problem uses a Fibonacci-like sequence, while the pancake problem uses a Tower of Hanoi-like approach.

Outlines

00:00

📚 Recursive Tile Arrangement Problem

The speaker introduces a problem where tiles need to be arranged on a 2xN floor using N tiles, each measuring 1x2. The challenge is to find the number of ways to arrange the tiles either horizontally or vertically. Examples with different values of N are given, including an illustration for N=4, where five distinct ways of arranging the tiles are possible. A formula for calculating the number of tile arrangements for larger values of N is outlined.

05:02

🔢 Recursive Solution for Tile Arrangements

This section provides further explanation on how the recursive relation works for calculating the number of tile arrangements. The base cases, K1=1 and K2=2, are presented, followed by the recursive relation that combines the two previous values to calculate the number of arrangements for larger N. The speaker demonstrates how this recursive relation is applied to calculate K8, which results in 34 ways to arrange tiles.

10:02

🥞 Pancake Stacking Problem

The speaker introduces the second problem about moving a stack of pancakes from one plate to another. The key rule is that larger pancakes must always remain beneath smaller ones. The example involves moving two pancakes with three steps, and the problem scales up to six pancakes. A step-by-step breakdown is provided for moving three pancakes, showing how the pancakes are transferred between plates.

15:05

⚙️ Recursive Formula for Pancake Moving

In this final section, a recursive relation for the number of steps required to move pancakes is introduced. The formula PN = 2*P(N-1) + 1 is derived, explaining how the process scales as more pancakes are added. The example progresses through 1, 2, 3, and 4 pancakes, where the steps increase to 63 for six pancakes. The speaker concludes with a motivational note for learners, encouraging them to continue practicing recursion.

Mindmap

Keywords

💡Recursion

Recursion is a computational concept where a problem is solved by breaking it down into smaller instances of the same problem. In the video, recursion is applied to solve problems like arranging tiles or moving pancakes. Each solution builds on the previous ones, with each step depending on the results of smaller cases.

💡Algorithmic strategy

An algorithmic strategy refers to a step-by-step approach for solving a problem efficiently. In the video, the strategy is demonstrated through recursive methods to determine the number of ways to arrange tiles or the number of steps to move pancakes, showing the importance of clear logical steps.

💡Tile arrangement problem

This problem involves arranging tiles on a 2xN floor, where each tile is 1x2 and can be placed either horizontally or vertically. The video shows how recursion is used to find the number of ways to arrange the tiles, with the solution based on smaller floor sizes (n-1 and n-2).

💡Base case

The base case is the simplest instance of a recursive problem, which provides the foundation for the recursion. In the video, for the tile problem, the base cases are when N=1 (1 way) and N=2 (2 ways). These are used to build the solution for larger N values.

💡Recursive relation

A recursive relation is an equation that defines each term in a sequence as a function of the preceding terms. For the tile arrangement problem, the recursive relation is KN = K(N-1) + K(N-2), which helps calculate the number of ways to arrange the tiles for larger values of N.

💡Pancake stacking problem

The pancake stacking problem involves moving a stack of pancakes from one plate to another, with the rule that a larger pancake must always be under a smaller one. The video shows how recursion is applied to find the minimum number of moves required for different numbers of pancakes.

💡Tower of Hanoi

The Tower of Hanoi is a classic recursive puzzle similar to the pancake stacking problem. It involves moving disks from one peg to another with the restriction that larger disks cannot be placed on top of smaller ones. In the video, the pancake problem is modeled similarly, where each step builds on the previous ones.

💡PN recursive formula

The PN recursive formula is used to calculate the number of steps needed to move N pancakes. The formula is PN = 2 * P(N-1) + 1, which shows how the number of steps doubles with each additional pancake. This is crucial in determining the total steps required in the pancake problem.

💡Computational thinking

Computational thinking is a problem-solving process that involves breaking down complex problems into manageable parts and creating algorithms to solve them. In the video, the focus is on recursion as a key element of computational thinking, applied to both tile arrangement and pancake stacking.

💡Fibonacci sequence

The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. In the tile arrangement problem, the number of ways to arrange tiles follows a Fibonacci-like pattern, with the sequence starting from K1 = 1 and K2 = 2, then progressing with the sum of the previous two terms.

Highlights

Introduction to solving problems using recursion with computational thinking and algorithmic strategies.

Explanation of the first problem: Tiling a 2xN floor with 1x2 tiles, emphasizing the recursive approach.

Illustration of tile placement: Horizontal and vertical arrangements for different values of N.

For N=4, five distinct ways to arrange the tiles are demonstrated.

A recursive formula is derived for determining the number of ways to tile a 2xN floor, where KN = K(N-1) + K(N-2).

Base cases are defined: K1 = 1 and K2 = 2 for N = 1 and N = 2 respectively.

For N=8, the recursive approach gives 34 ways to tile the floor, illustrating the growth in complexity.

Transition to the second problem: Moving pancakes between plates while maintaining the order based on size.

The pancake stacking problem introduces three plates (A, B, and C) and the rule that larger pancakes must always be below smaller ones.

A recursive strategy is used to determine the minimal number of moves required to transfer all pancakes between plates.

For 3 pancakes, the minimum number of moves is 7, and for 4 pancakes, it is 15.

The recursive formula for the pancake problem is PN = 2 * P(N-1) + 1, where P1 = 1.

For 6 pancakes, the total number of moves required is 63, following the recursive solution.

Both problems showcase the power of recursion in breaking down complex tasks into simpler, repeatable steps.

The session concludes with a reinforcement of computational thinking concepts through recursive problem-solving.

Transcripts

play00:00

[Musik]

play00:08

Assalamualaikum warahmatullahi

play00:09

wabarakatuh kita lanjutkan latihan soal

play00:13

terkait tentang rekursi berpikir

play00:16

komputasional strategi algoritmik dan

play00:20

pemrograman

play00:21

[Musik]

play00:23

aktivitas individu yaitu menerapkan

play00:26

konsep rekursi dengan deskripsi tugas

play00:30

sebagai berikut

play00:31

selesaikanlah dua problem berikut dengan

play00:34

menerapkan konsep rekursi yang telah

play00:37

kalian pelajari

play00:39

permasalahan pertama

play00:41

yaitu tentang memasang keramik terdapat

play00:45

sebuah lantai yang berukuran dua kali n

play00:50

pada lantai tersebut ingin dipasang n

play00:53

buah keramik yang masing-masing

play00:55

berukuran satu kali dua

play01:00

seperti ini ilustrasinya

play01:04

ada keramik dan lantai

play01:07

[Musik]

play01:09

setiap keramik dapat dipasang secara

play01:11

mendatar atau horizontal maupun secara

play01:15

tegak atau vertikal sebagai contoh jika

play01:19

n adalah 4 maka akan ada lima buah cara

play01:24

berbeda memasang 4 keramik

play01:28

yaitu cara pertama

play01:31

semua keramik dipasang secara horizontal

play01:39

cara kedua

play01:42

semua keramik dipasang secara vertikal

play01:48

Ya seperti ini

play01:51

kemudian

play01:52

cara yang ketiga

play01:55

paling kiri ada dua keramik vertikal

play01:59

dan yang kanan Sisanya adalah horizontal

play02:04

Ya seperti ini

play02:08

kemudian Cara yang keempat

play02:11

paling kiri ada dua keramik horizontal

play02:15

dan Sisanya adalah vertikal

play02:21

cara yang kelima paling kiri dan paling

play02:25

kanan vertikal dan sisanya horizontal

play02:32

[Musik]

play02:39

pertanyaannya adalah Tentukan Ada berapa

play02:42

cara memasang keramik untuk n = 8

play02:48

jawabannya seperti ini untuk N1 yaitu

play02:51

ada satu cara yaitu keramik dipasang

play02:55

secara vertikal kemudian N2

play02:59

ada dua cara

play03:02

semua keramik dipasang secara vertikal

play03:05

atau semua keramik dipasang secara

play03:09

horizontal untuk N2 ada dua cara

play03:13

Kemudian untuk N3 itu ada tiga cara

play03:19

yang pertama semua keramik dipasang

play03:21

secara vertikal

play03:23

kemudian cara yang kedua paling kiri ada

play03:26

dua keramik horizontal dan satu vertikal

play03:30

kemudian cara yang ketiga paling kiri

play03:34

ada satu keramik vertikal dan sisanya

play03:37

dua horizontal

play03:40

Kemudian untuk N = 4 itu ada 5 cara dan

play03:44

n = 5 ada 8 cara

play03:49

Cara yang pertama

play03:52

[Musik]

play03:57

Cara yang pertama semua keramik dipasang

play04:00

vertikal

play04:01

kelima keramik dipasang secara vertikal

play04:05

Kemudian untuk cara yang kedua

play04:10

yaitu

play04:11

horizontal horizontal dan terakhir

play04:14

vertikal

play04:18

untuk cara yang ketiga horizontal

play04:22

vertikal kemudian horizontal

play04:28

selanjutnya Cara yang keempat

play04:32

dari 5 keramik

play04:34

untuk n = 5 yaitu

play04:38

vertikal horizontal vertikal vertikal

play04:46

cara yang kelima

play04:47

vertikal horizontal horizontal

play04:51

[Musik]

play04:53

selanjutnya cara yang keenam vertikal

play04:56

vertikal horizontal vertikal

play05:01

cara yang ketujuh vertikal vertikal

play05:05

vertikal 3 kemudian sisanya horizontal

play05:12

cara selanjutnya cara yang ke-8 kita

play05:15

bisa

play05:16

dengan cara horizontal vertikal vertikal

play05:20

vertikal

play05:22

kemudian

play05:25

itu tadi 8 cara untuk n = 5 terakhir

play05:29

kita harus menentukan nilai basis dari

play05:32

referensi ini karena relasi referensi di

play05:37

atas melibatkan dua suku sebelumnya

play05:39

yaitu kn-1 dan k n -2

play05:44

kita harus menentukan dua nilai pertama

play05:47

dari barisan KN yaitu K1 dan K2 untuk N1

play05:52

jelas bahwa hanya ada satu cara memasang

play05:55

keramik pada lantai ukuran 2x1 yaitu

play06:00

secara vertikal saja untuk n-nya sama

play06:04

dengan 2 terdapat dua cara memasang

play06:07

keramik yaitu keduanya secara horizontal

play06:13

atau keduanya secara vertikal jadi kita

play06:17

simpulkan bahwa

play06:18

K1 = 1 dan K2 = 2

play06:28

kesimpulannya seperti ini N = 1 ada satu

play06:31

cara kemudian n = 2 ada dua cara

play06:35

selanjutnya n = 3 ada 3 cara n = 4 ada 5

play06:42

cara kemudian n = 5 ada 8 cara

play06:49

sehingga untuk

play06:51

an nya

play06:54

pada

play06:55

relasi referensi ini sama dengan 1 untuk

play06:59

n-nya 1 dan untuk n-nya yang lebih dari

play07:03

satu adalah KN -1 + k n - 2

play07:10

sehingga

play07:11

n6 adalah N4 + n5 ada 13 cara kemudian

play07:19

n7 adalah n5 + n6 yaitu ada 21 cara

play07:25

sedangkan N8 yaitu n6 + n7 13 + 21 yaitu

play07:32

ada 34 cara

play07:36

dari hasil perumusan secara rekursif

play07:40

barisan KN di atas kita dapat menghitung

play07:43

k8 dengan lebih mudah Yaitu dimulai

play07:46

dengan nilai K1 yaitu sama dengan 1 dan

play07:51

K2 = 2

play07:54

setiap suku berikutnya didapat dengan

play07:56

cara menjumlahkan dua suku terakhir jadi

play08:00

barisan KN yang didapat adalah sebagai

play08:03

berikut 1

play08:06

2 3

play08:09

5

play08:10

8

play08:11

13

play08:13

21

play08:15

34 dan seterusnya sehingga jawaban yang

play08:20

diinginkan untuk k8 adalah 34

play08:28

kita lanjutkan permasalahan kedua

play08:31

menumpuk pancake

play08:35

Budi memiliki setumpuk pancake yang

play08:38

memiliki ukuran dari besar sampai kecil

play08:43

pendek tersebut ditumpuk di atas sebuah

play08:46

piring

play08:48

dengan aturan bahwa pancake yang besar

play08:50

harus berada di bawah pancake yang lebih

play08:54

kecil

play08:57

Budi ingin memindahkan bangkit ini dari

play09:00

satu piring ke piring lainnya namun

play09:03

dalam prosesnya Ia tetap ingin mengikuti

play09:06

aturan bahwa pancake yang besar harus

play09:09

selalu berada di bawah pancake yang

play09:12

lebih kecil

play09:14

Selain itu Budi juga hanya boleh

play09:18

memindahkan satu buah pancake saja pada

play09:21

satu waktu tertentu dari satu piring ke

play09:25

piring lainnya

play09:29

Budi menyadari bahwa ia memerlukan

play09:31

sebuah piring tambahan untuk dapat

play09:34

melakukan perpindahan ini

play09:37

jika piring Asal pancake diberi nama a

play09:40

kemudian piring tujuan diberi nama C

play09:44

maka Budi akan menyiapkan sebuah piring

play09:47

bantuan sebagai tempat sementara yang

play09:50

diberi nama piring B

play09:55

Budi ingin mengetahui Berapa banyak

play09:58

Langkah pemindahan pancake yang harus ia

play10:01

lakukan untuk dapat memindahkan semua

play10:04

pancake yang dimilikinya dari piring a

play10:07

ke piring C

play10:11

dengan mungkin menggunakan piring B

play10:14

sebagai tempat sementara

play10:17

misalnya 3 Budi memiliki dua buah

play10:20

pancake saja kita beri nama pancake 1

play10:24

dan dimana teknik 1 berukuran lebih

play10:28

kecil dari pancake 2 maka ia membutuhkan

play10:31

minimal 3 langkah pemindahan

play10:37

yang pertama pindahkan pancake satu dari

play10:40

piring a ke piring B kemudian pindahkan

play10:44

Pengki dua dari piring a ke piring c dan

play10:47

selanjutnya langkah yang ketiga adalah

play10:49

pindahkan page 1 dari piring B ke piring

play10:54

C

play10:55

sekarang pertanyaannya Berapakah jumlah

play10:58

langkah minimal yang diperlukan apabila

play11:01

Budi memiliki 6 buah pancake

play11:10

dari pancake 3

play11:13

kita ilustrasikan seperti ini

play11:18

langkah yang pertama

play11:21

paling atas pancake berwarna biru

play11:23

kemudian

play11:26

warna kuning dan warna orange

play11:30

pancake yang berwarna biru dipindahkan

play11:32

ke piring

play11:34

[Musik]

play11:36

kemudian Langkah kedua pancake yang

play11:39

kuning dipindahkan ke piring B

play11:44

selanjutnya Langkah ketiga

play11:47

dan biru dipindahkan ke piring B di

play11:52

atasnya pendek kuning

play11:56

selanjutnya

play11:58

pancake yang ada di piring a yang

play12:00

berwarna orange dipindahkan ke piring C

play12:07

dan langkah yang kelima

play12:11

pancake yang ada di piring B pending

play12:14

biru dipindahkan ke piring a

play12:19

langkah yang keenam pancake kuning

play12:22

dipindahkan ke

play12:25

piring C diatas pancake orange

play12:32

kemudian

play12:34

langkah yang ketujuh

play12:38

biru dipindahkan

play12:41

ke piring C di atas pancake kuning

play12:48

sehingga untuk 3 pancake membutuhkan 7

play12:54

langkah

play12:57

sekarang kita cari Berapa langkah untuk

play13:01

tempat pancake

play13:05

kita tinggal melanjutkan dari 3 pancake

play13:09

sebelumnya

play13:10

yaitu 7 langkah

play13:13

[Musik]

play13:14

kita lanjutkan yaitu langkah yang ke-8

play13:20

pancake yang ada di piring a yang

play13:23

berwarna merah dipindahkan ke

play13:26

piring C

play13:31

kemudian pancake yang berwarna biru yang

play13:33

ada di piring B dipindahkan ke piring C

play13:38

diatas pancake merah

play13:42

selanjutnya langkah yang ke-10 pancake

play13:46

kuning dari piring B pindah ke piring a

play13:51

langkah yang ke-11

play13:53

pancake biru yang ada di piring C

play13:56

dipindahkan ke piring a di atas teknik

play14:01

kuning

play14:03

langkah yang ke-12

play14:08

dari piring B dipindahkan ke piring C

play14:13

kemudian langkah 13

play14:18

dipindahkan dari piring a ke piring B

play14:25

langkah yang ke-14

play14:28

pancake kuning dari piring a dipindahkan

play14:31

ke piring C

play14:35

kemudian Langkah terakhir dari 4 pancake

play14:39

yaitu langkah 15

play14:42

pancake biru dari piring B dipindahkan

play14:44

ke piring C

play14:48

ya itu tadi dari 4 pancake berarti

play14:52

membutuhkan 15 langkah

play14:56

[Musik]

play15:01

dari satu pancake itu ada satu langkah

play15:04

kemudian 2 pancake 3 langkah 3 pancake 7

play15:10

langkah 4 pancake 15 langkah

play15:14

Oleh karena itu kita dapat menyimpulkan

play15:17

bahwa

play15:18

PN dapat didefinisikan secara rekursif

play15:22

dengan menggunakan relasi rekursif

play15:25

sebagai berikut

play15:26

PN = P N -1 + 1 + pn-1 sehingga PN

play15:36

adalah

play15:37

sama dengan dua kali pn-1 + 1

play15:45

[Musik]

play15:46

sebagai basis dari referensi jelas bahwa

play15:50

P1 adalah 1

play15:53

dari sini kita dapat menghitung barisan

play15:55

PN sebagai berikut

play15:58

1 3

play16:01

7 15 31

play16:07

63 dan seterusnya sehingga jawaban yang

play16:12

diinginkan adalah

play16:14

untuk P6 adalah 63

play16:22

[Musik]

play16:26

demikian Tadi latihan soal menerapkan

play16:28

konsep rekursi pada materi berpikir

play16:31

komputasional bagian rekursi pada topik

play16:35

strategi algoritmik dan pemrograman

play16:39

Terima kasih semoga bermanfaat Selamat

play16:42

belajar dan tetap semangat

play16:46

[Musik]

Rate This

5.0 / 5 (0 votes)

関連タグ
Computational ThinkingRecursive Problem-SolvingTiling ChallengesPancake StackingAlgorithmic StrategiesProgramming ConceptsStep-by-Step GuideMathematical RecursionProblem SolvingLearning Algorithms
英語で要約が必要ですか?