[SER222] Recurrences (6/7): Proving f(n)

Ruben Acuna
22 Sept 201715:26

Summary

TLDREl video explica cómo la recurrencia descubierta en la solución de las Torres de Hanoi es equivalente a la fórmula cerrada propuesta (2^n - 1). Se destaca que la recurrencia es menos útil, ya que requiere muchos pasos recursivos para evaluar, mientras que la fórmula cerrada permite calcular directamente el número de movimientos. A través de la inducción matemática, se demuestra que ambas fórmulas coinciden para cualquier tamaño de torre. Además, se realiza un análisis de la complejidad Big-O, que resulta ser exponencial (O(2^n)), lo que implica que el algoritmo es ineficiente para valores grandes de n.

Takeaways

  • 📊 El problema trata de comparar una recurrencia con una fórmula cerrada para la solución del problema de las Torres de Hanoi.
  • 🔄 La recurrencia no es útil para cálculos rápidos, ya que requiere pasos recursivos hacia atrás, por lo que se busca una fórmula cerrada.
  • 🔢 La fórmula cerrada que se sugiere es 2^n - 1, lo que permite calcular directamente el número de movimientos necesarios para cualquier n.
  • 🧮 La recurrencia tiene dos partes: f(1) = 1 (un solo disco requiere un solo movimiento) y f(n) = 2 * f(n-1) - 1 para n discos.
  • 🔍 El objetivo es demostrar mediante inducción que la fórmula cerrada y la recurrencia coinciden para cualquier valor de n.
  • 📐 La inducción tiene dos pasos: primero, mostrar que la base (f(1)) es verdadera, y luego mostrar que si se cumple para k, se cumple para k+1.
  • 🧩 Se asume que la fórmula es verdadera para k, y luego se demuestra que también es válida para k+1 utilizando la recurrencia.
  • 📈 Al final, se demuestra que la fórmula cerrada es válida para todos los números naturales mediante inducción.
  • 💡 La fórmula final para f(k+1) es 2^(k+1) - 1, lo que coincide con la fórmula general que se quería demostrar.
  • ⚙️ El crecimiento de la función es exponencial (O(2^n)), lo que implica que el algoritmo toma mucho tiempo para valores grandes de n.

Q & A

  • ¿Qué es lo que se quiere demostrar en el video?

    -Se quiere demostrar que la recurrencia obtenida del problema de las Torres de Hanoi es equivalente a la fórmula cerrada que se conjeturó para el número de movimientos.

  • ¿Por qué no es útil la recurrencia para evaluar el número de movimientos?

    -Porque para evaluar la recurrencia en un valor específico de n, se requieren muchos pasos recursivos, lo que la hace ineficiente. Es más útil tener una solución cerrada que permita calcular directamente el número de movimientos para un valor de n.

  • ¿Cuál es la recurrencia y la fórmula cerrada propuestas para el problema de las Torres de Hanoi?

    -La recurrencia es f(n) = 2f(n-1) - 1, y la fórmula cerrada conjeturada es f(n) = 2^n - 1.

  • ¿Cómo se puede demostrar que ambas fórmulas son equivalentes?

    -Se puede demostrar utilizando inducción matemática. El objetivo es probar que ambas fórmulas son iguales para cualquier valor de n.

  • ¿Cuáles son los pasos clave de la inducción matemática mencionados en el video?

    -Primero se debe establecer un caso base, en este caso n = 1, y luego realizar un paso inductivo, que demuestra que si la propiedad es cierta para un valor k, entonces también lo será para k + 1.

  • ¿Cuál es el caso base utilizado en la demostración?

    -El caso base es n = 1, donde se demuestra que ambas fórmulas, f(1) = 1 y 2^1 - 1 = 1, son iguales.

  • ¿Cómo se realiza el paso inductivo?

    -En el paso inductivo se asume que la fórmula es válida para n = k y se utiliza la recurrencia para demostrar que también es válida para n = k + 1.

  • ¿Cómo se expande algebraicamente la fórmula durante el paso inductivo?

    -Se sustituye la expresión f(k) en la recurrencia y se simplifica para obtener que f(k + 1) = 2^(k + 1) - 1, mostrando que la fórmula es válida para k + 1.

  • ¿Qué significa que la solución sea de tiempo exponencial?

    -Significa que el número de movimientos necesarios crece exponencialmente con el número de discos. Esto implica que el tiempo de cálculo aumenta rápidamente, haciéndolo impracticable para valores grandes de n.

  • ¿Cuál es el orden de complejidad Big-Oh de la solución?

    -El orden de complejidad Big-Oh es O(2^n), indicando que el número de movimientos crece de manera exponencial con el número de discos.

Outlines

00:00

🔍 Introducción y análisis del problema de Torres de Hanoi

El autor presenta el problema de las Torres de Hanoi y menciona que el objetivo es mostrar que la recurrencia obtenida es equivalente a la solución en forma cerrada. Explica que la recurrencia no es práctica para evaluar el número de movimientos requeridos para un tamaño específico de n, y por lo tanto es mejor una solución cerrada. Se detalla la recurrencia de f(1) = 1 para un disco y la de f(n) = 2f(n-1) - 1 para n discos. Finalmente, se plantea que la solución cerrada propuesta es 2^n - 1, y el objetivo es probar que ambas fórmulas son equivalentes para cualquier n usando inducción.

05:00

🔄 Comparación entre fórmulas mediante inducción

Se introduce la idea de la inducción matemática como herramienta para probar que las dos fórmulas (la recurrente y la cerrada) son equivalentes para todos los tamaños de torres. Se explica el proceso de inducción, comenzando con un caso base (n = 1) donde ambas fórmulas son iguales. El propósito de la inducción es demostrar que si la propiedad es cierta para un valor k, entonces también lo será para k+1, lo que permite cubrir todos los números naturales. En el caso base, se sustituye n = 1 en ambas fórmulas y se concluye que son iguales, estableciendo que la propiedad es cierta para n = 1.

10:03

📏 El paso inductivo y su importancia

El autor explica el paso inductivo, donde se asume que la propiedad es cierta para un valor k y se debe demostrar que también es válida para k+1. Se muestra cómo esta suposición inductiva ayuda a construir la solución para el caso siguiente. Utilizando la recurrencia original y la suposición inductiva, se deriva la fórmula para f(k+1). El objetivo es llegar a la forma cerrada f(k+1) = 2^(k+1) - 1, lo que demostraría que la propiedad se mantiene al avanzar un paso en la secuencia.

15:04

🔑 Resolviendo algebraicamente la relación de recurrencia

En este párrafo, se realiza un desarrollo algebraico para demostrar que la fórmula para f(k+1) es equivalente a 2^(k+1) - 1. Se parte de la fórmula original y se utiliza la suposición inductiva para avanzar de k a k+1. Se destaca que el resultado debe coincidir exactamente con la forma cerrada deseada. Tras expandir y simplificar las expresiones, se llega a la fórmula correcta para f(k+1), demostrando así que la suposición inductiva es válida y que ambas fórmulas son equivalentes para todos los valores de k.

📊 Conclusión sobre la equivalencia de las fórmulas

El autor concluye que, dado que se ha demostrado que las fórmulas coinciden para el caso base y para el paso inductivo, esto implica que las dos fórmulas son equivalentes para cualquier valor de n. Así, se ha probado que la solución cerrada 2^n - 1 es correcta. También reflexiona sobre las implicaciones de tener una solución cerrada, destacando que es mucho más eficiente que una recurrencia para calcular el número de movimientos requeridos.

📉 Análisis de la complejidad temporal de la solución

Finalmente, el autor analiza la complejidad temporal de la solución cerrada. La función de crecimiento f(n) = 2^n - 1 se clasifica como una función de tiempo exponencial con una complejidad de O(2^n), lo que significa que el tiempo requerido para resolver el problema crece muy rápidamente a medida que aumenta n. Se menciona que esto es problemático para valores grandes de n, ya que el tiempo de cómputo sería ineficiente. También se calcula el valor tilde de la función, que es igualmente 2^n, destacando que esta es una función de crecimiento considerable.

Mindmap

Keywords

💡Recurrencia

Una recurrencia es una ecuación que define una secuencia de valores en términos de valores anteriores de esa secuencia. En el video, la recurrencia es usada para describir cómo calcular el número de movimientos necesarios para resolver el problema de las Torres de Hanói de forma recursiva, es decir, calculando el número de movimientos para una torre de tamaño n en función de n-1.

💡Solución cerrada

Una solución cerrada es una fórmula matemática que permite calcular el resultado de un problema sin necesidad de recurrencia o pasos iterativos. En el video, el objetivo es encontrar la fórmula cerrada que permita calcular directamente el número de movimientos necesarios para cualquier número de discos en las Torres de Hanói, lo cual resulta en la fórmula 2^n - 1.

💡Inducción matemática

La inducción matemática es un método de prueba que demuestra que una afirmación es verdadera para todos los números naturales. En el video, se usa inducción para probar que la fórmula cerrada (2^n - 1) es correcta para todos los tamaños de torres, comenzando por un caso base y luego demostrando que si es verdadera para un valor k, también lo es para k+1.

💡Caso base

El caso base es el punto inicial de una prueba por inducción, donde se verifica que una afirmación es verdadera para el valor más pequeño posible. En el video, el caso base se establece cuando n es igual a 1, mostrando que tanto la fórmula recursiva como la solución cerrada coinciden para una torre con un solo disco.

💡Paso inductivo

El paso inductivo es el segundo componente de una prueba por inducción, que demuestra que si una afirmación es verdadera para un valor k, también lo es para k+1. En el video, se utiliza el paso inductivo para demostrar que si la fórmula cerrada es válida para un número de discos k, también será válida para k+1, consolidando así la validez de la fórmula para cualquier n.

💡Torres de Hanói

Las Torres de Hanói son un problema matemático donde se deben mover discos de diferentes tamaños entre tres postes siguiendo ciertas reglas. En el video, se utiliza este problema para ilustrar la recurrencia y la fórmula cerrada que calcula el número mínimo de movimientos necesarios para resolver el problema dependiendo del número de discos.

💡O grande (Big-O)

El O grande es una notación utilizada para describir la complejidad algorítmica en términos de crecimiento respecto al tamaño de la entrada. En el video, se menciona que la complejidad del algoritmo de las Torres de Hanói es O(2^n), lo que indica un crecimiento exponencial en el número de movimientos necesarios a medida que aumenta el número de discos.

💡Algoritmo exponencial

Un algoritmo exponencial es aquel cuya cantidad de pasos necesarios para completarse crece de forma exponencial con el tamaño de la entrada. En el video, se explica que el problema de las Torres de Hanói tiene una complejidad exponencial, lo que implica que el número de movimientos necesarios se duplica con cada disco adicional, haciéndolo ineficiente para valores grandes de n.

💡Función de crecimiento

Una función de crecimiento describe cómo varía el número de operaciones de un algoritmo en función del tamaño de su entrada. En el video, la función de crecimiento de las Torres de Hanói es 2^n - 1, lo que significa que el número de movimientos crece exponencialmente con el número de discos.

💡Hipótesis inductiva

La hipótesis inductiva es el supuesto en una prueba por inducción de que la afirmación es verdadera para algún valor k. En el video, esta hipótesis se utiliza como parte del paso inductivo para asumir que la fórmula cerrada es válida para k discos y luego demostrar que también lo es para k+1 discos.

Highlights

The recurrence for the Towers of Hanoi solution is expressed as f(n) = 2f(n-1) - 1.

A closed-form solution is preferred over the recurrence because it allows for direct computation of the number of moves.

The closed-form solution for the Towers of Hanoi problem is f(n) = 2^n - 1.

Induction is used to prove that the recurrence formula and the closed-form solution are equivalent for all values of n.

The base case for induction starts with n = 1, where f(1) = 1, and the formulas are verified to be equal.

The inductive step assumes the property holds for some k and proves it holds for k + 1.

The recurrence relation f(n) = 2f(n-1) - 1 is used to transition from f(k) to f(k+1) in the inductive step.

Algebraic manipulation shows that the closed-form solution holds after expanding and simplifying the recurrence.

The final form of the solution is f(k+1) = 2^(k+1) - 1, proving the inductive step is valid.

The overall proof shows that the recurrence and the closed-form solution are equivalent for all natural numbers n.

The algorithm for solving the Towers of Hanoi problem has a time complexity of O(2^n), indicating exponential growth.

The exponential time complexity means the problem becomes computationally infeasible for large values of n.

The tilde notation for the growth rate is also 2^n, providing a more precise representation.

Exponential growth is highlighted as a key challenge in the Towers of Hanoi problem, making it hard to solve for large inputs.

The analysis concludes with a detailed understanding of the algorithm's behavior and performance limitations.

Transcripts

play00:05

- So in this video, I wanna show that our recurrence

play00:07

that we basically had come up with

play00:09

from looking at the solution to Towers of Hanoi

play00:11

is actually the same thing as our guess

play00:13

for what is the closed form version of it.

play00:15

Again, right, the recurrence isn't very useful to us,

play00:18

because basically whenever you wanna evaluate

play00:20

for specific n,

play00:21

we have to basically do all these kinda recursive steps

play00:23

where you go backwards, backwards, backwards, backwards,

play00:25

really what's more useful

play00:25

is for us to have a closed solution

play00:27

that we can basically put in our value of n

play00:28

and directly compute

play00:30

what is the number of moves that are required.

play00:31

So stuff we've basically discovered already

play00:34

is this stuff over here.

play00:35

So this is basically our known truth.

play00:38

This little bubble over here with "Ahem" over there

play00:41

as kind of a side note,

play00:44

we're kind of just taking this to be true, right?

play00:46

If there was an issue in the way we analyze our code,

play00:48

maybe this won't be true,

play00:49

but we're just going to basically assume

play00:51

that our initial analysis

play00:52

or our initial occurrence is accurate.

play00:54

So there's two parts to the recurrence.

play00:55

First of all f of one equal one.

play00:57

So basically for the very small tower

play00:59

containing just one disc,

play01:00

if I wanna move it,

play01:01

well that takes just one move, so pretty simple.

play01:04

Second thing there was more complicated is the f of n,

play01:07

the general step.

play01:08

So f of n equal two f of n minus one minus one.

play01:11

So this is the recursive part where the number of moves

play01:15

required to move a tower of size n

play01:17

is based on the number of moves required

play01:19

to move two smaller towers,

play01:21

two size n minus one towers.

play01:23

Okay, so that's what we have

play01:24

and then based on our guesses that we made before,

play01:26

we think that the closed loop solution

play01:29

looks something like this,

play01:31

two to the n minus one.

play01:34

And so our goal basically is to show

play01:35

that for any n, right, any size tower,

play01:38

these two things will always be the same.

play01:40

An issue, right, we know that these are the same

play01:42

in terms of just what we plotted out.

play01:44

So if you think back,

play01:45

we had basically this graph,

play01:47

we started at zero,

play01:48

we went up to something like 16

play01:48

and we just evaluated these two functions

play01:50

for each of those values of n

play01:52

and they looked the same,

play01:54

but the problem is how do I make sure

play01:56

that they're always the same, right?

play01:57

Forever that they will match up.

play01:59

Well, we can do that using induction, right?

play02:02

So the idea of induction again, right,

play02:03

is to show that some property holds true

play02:05

for every value of n, right.

play02:07

Basically, we're asserting that something is true

play02:09

for every element of a set.

play02:10

Here, the set that we're looking at

play02:11

is the set of natural numbers.

play02:13

Well, we're starting at zero basically

play02:15

and going up by one

play02:17

and we wanna show basically,

play02:17

for any possible tower, right,

play02:19

that's maybe our set, is tower sizes,

play02:21

that this property holds,

play02:22

that these two things match up.

play02:24

That's what we wanna assert

play02:25

and we wanna assert it

play02:26

that for basically any size of tower,

play02:28

these things will hold,

play02:29

not just the size of towers

play02:30

that we have listed in our table,

play02:33

we wanna assert it for everything.

play02:35

Okay, so how do we get there?

play02:37

Well, first thing we gotta do

play02:38

and induction generally has two parts,

play02:40

first of all we need to decide what n is bound to

play02:42

and so we're bounding n to starting at one

play02:44

and going upwards

play02:46

and then, well, we could also started at zero,

play02:49

but it doesn't really make sense to move an empty tower,

play02:51

so we'll start at one, so we'll use natural numbers.

play02:55

Well, we need to basically decide what variable

play02:57

we're iterating over, if you would.

play02:58

What is the set that we're going to prove things from?

play03:02

So, that here is just natural numbers.

play03:03

I'll make a note that this variable, n,

play03:05

basically the size of towers is coming from that set,

play03:07

it's a natural number.

play03:08

Now, for induction, there are basically two parts.

play03:10

First of all, we need to start with the inductive case,

play03:12

which is basically like what is the simplest thing

play03:13

I can show to be true, right, a starting place

play03:15

and then if I have that,

play03:17

then what I wanna do is go look at the inductive step,

play03:19

which is going to say, okay,

play03:21

given that a particular,

play03:25

that this property holds for k, right,

play03:27

for some tower size,

play03:28

that it'll also hold for some larger tower, right?

play03:30

Tower size plus one, k plus one.

play03:32

That's the inductive step.

play03:33

That lets us basically grow

play03:35

and eventually touch each of the natural numbers, right,

play03:37

because if my property can be shown true

play03:39

for some number like 10,

play03:40

then that will let me show it true for 11

play03:42

and if it's true for 11,

play03:43

then it's also true for 10 by using that same rule.

play03:46

So that rule, right, that inductive step,

play03:48

basically lets us span all the natural numbers

play03:49

and assert that our property holds for everything.

play03:52

This is rather nice

play03:53

because if you think about it,

play03:54

well, natural numbers,

play03:54

there's a countably infinite number of them, right?

play03:58

And we're gonna basically show

play03:59

that this property holds for all them,

play04:01

even though we're just doing it in this one case,

play04:02

it'll work for all of them.

play04:04

All right, so looking at our two steps,

play04:05

first thing we need to talk about is the base case.

play04:07

So in terms of the base case,

play04:08

basically what I wanna do

play04:08

is I wanna show that

play04:11

what I'm trying to prove

play04:12

basically holds true at some starting place

play04:15

and the starting place I'll go with

play04:16

is actually n equal one.

play04:17

All right, and so n equal one be my base case

play04:19

and what I would do is basically put that value for n

play04:22

into my formulas.

play04:25

So I know of course, right, that f of one equal one,

play04:27

so over here basically I can write this stuff here,

play04:29

f of one equal one

play04:30

and then I'm trying to assert, right,

play04:32

that that'll be equal to the other formula,

play04:33

the formula that I guessed,

play04:34

so that's this formula here.

play04:36

So this basically comes down over here

play04:39

and I've basically just set n equal to one.

play04:44

So there's two parts here, right,

play04:45

so this stuff over here comes from this.

play04:50

This stuff over here comes from the one above

play04:52

and if I evaluate those, right,

play04:53

I'll find out that I get one and one, right?

play04:56

This is obviously true,

play04:57

so at least for that base case of n equal one,

play05:00

the property holds, right?

play05:01

Those two things are the same.

play05:02

So when I say property,

play05:03

I really mean here those two formulas are equal.

play05:06

Right, we could be asserting many facts, right,

play05:07

we could be asserting something like,

play05:09

oh, the number of discs in the tower is odd or even

play05:11

or something like that,

play05:12

but the property we want to investigate

play05:14

is just to check to see whether those two things are equal,

play05:15

whether my guessed formula

play05:17

and my formula that I came up with based on the code

play05:22

give me the same result.

play05:23

So for here, right now,

play05:24

I've basically shown that to be true.

play05:25

Okay, so let's now take a look at the inductive step.

play05:27

So the inductive step,

play05:29

basically my job is to say, okay,

play05:30

this property holds for some k

play05:33

and that will imply that it holds for some k plus one,

play05:35

and that property being of course

play05:37

that those two things are equal.

play05:39

So here I get a little bit of somehow, of magic,

play05:42

so I'm actually allowed to assume

play05:44

that case k is true.

play05:46

So this little bit here.

play05:49

So this is basically coming from our guess, right,

play05:52

our guess was over here up top

play05:53

for our original f of n.

play05:55

Now, we're saying is that inductively,

play05:57

well, in terms of induction,

play05:58

what we'll assume, basically,

play05:59

is that this holds, right,

play06:01

so we're going to be given that case k holds, right?

play06:03

So we're given this as true.

play06:05

Even though we haven't really done anything,

play06:06

we're just going to assume it.

play06:09

That's something there that's basically available

play06:10

for us to use algebraically.

play06:12

Okay, and really the only difference, right,

play06:15

is I've substituted in k for n

play06:16

to basically represent

play06:17

that this is kind of your inductive hypothesis, right?

play06:19

This is what you're allowed to assume.

play06:22

So, using that kind of fact, right,

play06:24

we wanna build from that,

play06:25

we wanna show that this is valid as well.

play06:29

Basically we want a way to derive f of k plus one

play06:32

from f of k, right?

play06:33

We wanna link those two things up, right?

play06:35

Get the ability to basically step forward

play06:37

and say if this is true,

play06:38

this other thing is true as well.

play06:40

So how can we get there?

play06:42

And actually, maybe before I get there,

play06:43

what is our end goal?

play06:44

Our end goal is really something like this.

play06:46

We wanna recover the following formula.

play06:49

We wanna recover f of k plus one

play06:54

equals two k plus one minus one, right?

play07:01

That's what we wanna recover.

play07:02

So we wanna get from this initial f of k

play07:06

to f of k plus one, right?

play07:08

We wanna move between those algebraically,

play07:10

not kinda make any assumptions

play07:12

and just using the information that we have.

play07:14

So that's kind of our goal.

play07:16

So we start with f of k,

play07:16

so what can we do?

play07:18

First thing we can do is actually think about

play07:19

using our, basically our original formula,

play07:24

the recursive one, the recurrence

play07:27

to write an expression

play07:28

that basically computes f of k plus one, right?

play07:31

Because our initial recurrence stuff up top, right,

play07:33

those two ways to compute f of one, f of n,

play07:36

notice the recurrence,

play07:37

those are gonna be valid no matter what.

play07:38

We already took that to be true.

play07:40

That is our stuff we get basically forever, right?

play07:42

It's free for us to use.

play07:44

So what I could do is I could think about writing

play07:47

the expression for f of k in terms of that original rule.

play07:50

And so that's basically what we've done here.

play07:52

We have basically a few things going on.

play07:55

I'm shifting a little bit, right?

play07:56

The original rule is written in terms of f of n,

play07:59

now we're basically saying n equals k plus one,

play08:01

so we're doing a substitution in a couple of places here

play08:03

and we end up with this thing here.

play08:05

So this is basically my formula for f of k plus one

play08:09

in terms of that original formula

play08:11

and then what I have, right,

play08:12

is I have that reoccurrence going on

play08:13

and that recurrence is normally referring back

play08:16

to a smaller value of the function, right?

play08:20

So here it's referring back to f of k, right?

play08:21

So f of k plus one is computed from f of k.

play08:25

But here, right, this isn't really what I want, right?

play08:27

Again, think of my goal, right?

play08:28

My goal is to get to this thing over here,

play08:29

where my expression, that's a closed form expression

play08:32

that doesn't have any functions being called

play08:34

or referred to.

play08:37

So actually, I'm not bound

play08:38

to the line that I'm manipulating,

play08:40

this f of k, what I can actually do

play08:42

is I can actually substitute in this over here, right,

play08:46

so I'm substituting in what I assume to be true.

play08:50

So that brings me, basically, to this line right over here.

play08:53

So in a sense, what's happened between these two lines

play08:56

is I said, okay, I wanna get from k to k plus one.

play08:59

I'll actually start with the thing

play09:00

that I'm allowed to assume, right,

play09:02

that my formula or my property holds for f of k

play09:04

and then I'm somehow gonna grow it, right?

play09:06

I'm gonna move it forward using my original formula,

play09:09

because for sure that original formula will work, right?

play09:11

And the whole purpose of that formula, right,

play09:13

the actual line up here,

play09:14

this thing, right, really, mechanically,

play09:17

what it's doing is it's evaluating some value

play09:21

for a tower based on a smaller tower,

play09:24

so it's linking together, right,

play09:26

a tower of size n with a tower of size n minus one

play09:28

and so what I'm doing over here, right,

play09:29

is I'm trying to at the bottom

play09:31

prove that the case k implies the case k plus one

play09:33

and so that original function I have,

play09:36

basically that's the mechanic I have to do that, right?

play09:39

To jump from k to k plus one

play09:40

because I don't have anything else

play09:41

that can get me between those two points,

play09:43

so I start with what I assume, right,

play09:44

I assume that that property, that expression, right,

play09:46

holds for f of k

play09:49

and I use my original known good formula to move up by one.

play09:53

So we're kind of combining two things here.

play09:54

We're combining our assumption

play09:55

with basically the way we stepped forward

play09:57

in the original recurrence.

play09:59

So that gives me this line down here

play10:02

and this line down here,

play10:04

all of a sudden I've eliminated f of n,

play10:06

and so I have this f of k plus one

play10:13

being equal to two of the k minus one plus one,

play10:17

so I have that.

play10:18

The problem is I'm not really done yet.

play10:20

So that's kind of a full expression there,

play10:22

but it doesn't look just like that, right?

play10:25

This thing over, right, our goal.

play10:26

Really, what we want, is you want that exactly.

play10:30

And the reason why we want that exactly

play10:31

is because this over here, this stuff,

play10:33

looks exactly like what we're allowed to assume,

play10:35

that f of k equal to k plus two to the, excuse me,

play10:38

f of k equal to the k minus one, right?

play10:41

These two things look exactly the same,

play10:43

this f of k and this f of k plus one.

play10:45

The only difference, right,

play10:45

is that there's a plus one basically, where the k is, right?

play10:48

So whatever it is, the expression that we produced

play10:50

should look exactly the same

play10:51

except for that plus one being added on to there, right?

play10:54

If there's still other kind of things

play10:55

to algebraically manipulate, we gotta take care of 'em.

play10:57

We can't just leave this be

play10:58

and say, oh hey, I wrote f of k plus one

play11:01

with stuff that's not a recurrence, right?

play11:03

There's no f of n on the right hand side,

play11:04

I can't stop there.

play11:06

Algebraically, I need to carry through

play11:07

and make sure that I match my goal, right?

play11:09

My goal is to basically regenerate this f of k,

play11:12

but with the plus one added to that k.

play11:15

Okay, so from this point, it's just algebra.

play11:17

So I have here, right,

play11:19

my two times two to the k minus one plus one

play11:22

so I expand basically the coefficient,

play11:25

so I multiply it in.

play11:27

That gets me basically two to the k plus one minus two,

play11:30

right, so just imagine you're distributing, right, in there,

play11:33

so your minus one is times two, gets you minus two

play11:36

and then you're doing basically two times two to the k,

play11:38

well, what happens is that power, right,

play11:40

because the coefficient matches what your power's on,

play11:42

the power will absorb the coefficient out front,

play11:45

so we now have a two to the k plus one.

play11:49

Almost done there, right,

play11:50

then we just basically do the addition,

play11:52

add that one to the negative two

play11:54

and we over here, two to the k plus one minus one.

play11:57

So in this case, right,

play11:58

here we've basically managed to carry through

play12:00

and we've recreated the original formula

play12:02

that I started with,

play12:03

but with basically that plus one now in there.

play12:07

So that's it, we're done, right?

play12:10

Idea there, right, is basically where we're recovering

play12:12

that f of k, right?

play12:13

We wanna show that starting with the assumption

play12:14

that f of k is valid, right,

play12:16

that that expression holds,

play12:18

then we can show the case k plus one will hold

play12:21

and we would do that basically

play12:22

by recovering the original formula,

play12:23

but with that slight alteration of that plus one.

play12:26

And the way we got there, right,

play12:27

the way we got there from f of k to f of k plus one

play12:29

is basically by using my original formula,

play12:31

my original recurrence

play12:32

to do that little step forward, right,

play12:33

to basically do the work

play12:35

of making a prediction, right, for a tower that's one bigger

play12:38

and that's a legit step for us, right,

play12:40

because we know that recurrence is our assumed truth, right,

play12:42

and so we can use that to basically take a step, right,

play12:46

and say okay, the k plus one step is also true.

play12:50

So putting this together, basically, what we have, right,

play12:51

is we have our base case and our inductive case, excuse me.

play12:55

We have our base case and our inductive step,

play12:56

so base case says hey, these two formulas match up

play12:59

for k equals zero, great.

play13:01

Then we have our inductive step which says okay,

play13:03

if those formulas hold, right,

play13:05

if the property holds for k,

play13:08

then it'll hold for k plus one.

play13:10

Well, there you go, done, right?

play13:11

So we start at zero, plus one it, get to one,

play13:14

plus one that, get to two,

play13:15

plus one that, get to three,

play13:16

plus one get to four

play13:17

and so on, right?

play13:18

So putting this together,

play13:19

basically every single value of n, right,

play13:21

all the natural numbers,

play13:23

these two things will be the same, right?

play13:25

We proved that,

play13:26

and so now we know that our two formulas, right,

play13:28

our guess and the reoccurrence we got from the code

play13:31

are the same thing, right?

play13:32

So that is accurate guess, right?

play13:34

We've proved that they're the same,

play13:35

so now we're good to go.

play13:37

Some final remarks here about the f of n.

play13:41

So basically what we've done, right,

play13:42

is we've verified that we have a closed solution.

play13:44

We had a solution before,

play13:45

but the problem was it was recursive, right?

play13:47

It was a recurrence,

play13:48

so it was expressed in terms of itself.

play13:49

It's very hard to evaluate,

play13:50

but now we have what we want,

play13:51

which is a closed form

play13:52

or a closed loop solution to it.

play13:56

Given that we have f of n, right,

play13:57

which is a growth function, right,

play13:58

it's gonna exactly compute for us

play14:00

the number of moves we require,

play14:01

we can actually now think about maybe computing

play14:03

the Big-Oh or even the tilde of it,

play14:05

or whatever we want of it.

play14:07

So maybe think for a second.

play14:09

Given this function here,

play14:10

this f of n equal two to the n minus one,

play14:14

what would be the Big-Oh order of that

play14:15

and then what will be the tilde of that?

play14:17

So maybe think for one second.

play14:20

Okay, so Big-Oh for that is going to be,

play14:23

it'll be Big-Oh of two to the n,

play14:27

which is actually something

play14:28

that we haven't really seen before.

play14:29

Before, we've seen things like O of n or O of n squared,

play14:32

but here this is O of two to the n,

play14:34

so this an exponential time algorithm.

play14:36

The problem with exponential time algorithm

play14:38

is it's that'll basically take forever, right?

play14:40

So as I increase n, right, the number of discs,

play14:43

this will grow very, very, very, very quickly, right?

play14:45

It'll grow exponentially quicker

play14:47

just going from 10 to 11 for our size of n

play14:51

all of a sudden doubles the number of moves

play14:53

that are required.

play14:55

And this is very bad, right?

play14:56

This is something basically

play14:58

for any reasonably large number of n,

play14:59

we're just not gonna be able to compute.

play15:01

It'll simply take too long.

play15:03

Then what about tilde?

play15:04

Tilde for this is going to be also two to the n.

play15:08

So remember the difference between Big-Oh and tilde

play15:10

was that Big-Oh doesn't drop the coefficient in front.

play15:13

Instead we just leave it there

play15:14

in order to be more accurate.

play15:16

Okay, so that's kind of our growth function right up top.

play15:19

Those are our Big-Oh and tilde analysis of it.

play15:22

So pretty good, we now have this idea

play15:24

of how this algorithm will work.

Rate This

5.0 / 5 (0 votes)

Связанные теги
MatemáticasInducciónRecurrenciaFórmulas cerradasTorre de HanoiAlgoritmosBig-OhExponencialResolución de problemasAnálisis de complejidad
Вам нужно краткое изложение на английском?