[SER222] Analytical Analysis (1/5): Defining f(n)

Ruben Acuna
30 Aug 201713:23

Summary

TLDREl vídeo explica qué representa F de N en el análisis de crecimiento de funciones y cómo elegir el parámetro adecuado. Se discute la importancia de seleccionar una operación que ocurra con frecuencia y no dependa de condiciones lógicas para medir el comportamiento de un algoritmo con respecto al tamaño de la entrada. Se utiliza el ejemplo de la búsqueda binaria para ilustrar cómo elegir la operación correcta y se enfatiza la relevancia de las operaciones pesadas y su frecuencia en la función de crecimiento.

Takeaways

  • 🔍 La función F(N) representa la función de crecimiento que mide la cantidad de trabajo que se necesita para ejecutar un algoritmo en función del tamaño de la entrada.
  • 🕒 La notación T(N) se usó anteriormente para abreviar la cantidad de tiempo que se necesita para resolver un problema de tamaño N, pero F(N) busca ser más exacta.
  • 📈 Los algoritmos eficientes tienen funciones de crecimiento que se incrementan lentamente a medida que el tamaño del problema aumenta.
  • 💥 Los algoritmos poco eficientes tienen funciones de crecimiento que crecen rápidamente, lo que significa que el tiempo de ejecución aumenta dramáticamente con el tamaño de la entrada.
  • 🛠 Para definir F(N) con precisión, es necesario elegir qué tipo de operación se está contando, ya que esto afecta significativamente la forma de la función de crecimiento.
  • ⚖️ Es importante medir una operación que ocurra con frecuencia y no una que suceda solo una vez, ya que esto no nos daría una idea precisa del comportamiento del algoritmo.
  • 📉 Las operaciones de bajo peso, como una adición o un desplazamiento de bits, pueden no ser lo suficientemente significativas para medir en la función de crecimiento.
  • 🔄 En el análisis de algoritmos, se prefieren las operaciones que son parte del núcleo del algoritmo y que ocurran con regularidad.
  • ❌ Se deben evitar las líneas de código que solo ocurren una vez o que están condicionadas por una lógica que no se puede predecir con facilidad.
  • 🔍 Al analizar el código fuente de una búsqueda binaria, se debe considerar qué líneas son candidatas para medir en la función de crecimiento, teniendo en cuenta su frecuencia y relevancia en el algoritmo.

Q & A

  • ¿Qué representa F de N en el contexto del vídeo?

    -F de N representa una función de crecimiento que mide directamente o exactamente algo, como el número de operaciones necesarias para ejecutar un algoritmo en una entrada de ese tamaño.

  • ¿Cuál es la importancia de los análisis empíricos mencionados en el vídeo?

    -Los análisis empíricos se utilizan para entender cuánto tiempo se tarda en resolver un problema a medida que su tamaño aumenta, utilizando la notación T de N para representar esa cantidad de tiempo.

  • ¿Qué tipo de funciones crece muy lentamente según se describe en el vídeo?

    -Las funciones que crecen muy lentamente son aquellas en las que, a medida que el tamaño del problema aumenta, el valor de F de N no cambia mucho, lo que indica que el algoritmo es bastante eficiente.

  • ¿Cómo se determina si un algoritmo es eficiente según el vídeo?

    -Un algoritmo es eficiente si su función de crecimiento F de N no se dispara dramáticamente a medida que aumenta el tamaño del problema, lo que significa que no requiere un aumento desmedido de trabajo o tiempo para resolver el problema.

  • ¿Qué es lo que se debe medir según el vídeo para definir una función de crecimiento?

    -Se debe medir una operación que sea frecuentemente ocurriendo, no constante en tiempo y que no esté bajo una expresión lógica o condición que dificulte su medición.

  • ¿Por qué es importante elegir una operación pesada para medir según el vídeo?

    -Es importante elegir una operación pesada para medir porque si se está analizando la mayor parte del trabajo que se necesita hacer, entonces el análisis incluirá cualquier otra cosa que suceda en la función.

  • ¿Qué es lo que se debe tener en cuenta al analizar un código para determinar qué operación medir?

    -Al analizar un código, se debe tener en cuenta encontrar una operación que suceda con frecuencia, no sea de tiempo constante, y que no esté bajo una expresión lógica que dificulte su medición.

  • ¿Qué es lo que se debe evitar al medir una operación para la función de crecimiento en el código fuente del vídeo?

    -Se debe evitar medir operaciones que solo ocurran una vez, operaciones que tengan una dependencia de la entrada y operaciones que estén bajo condiciones lógicas que afecten su ejecución.

  • ¿Cómo se determina la complejidad de tiempo de un algoritmo según el vídeo?

    -La complejidad de tiempo de un algoritmo se determina al analizar la operación que se ejecuta con mayor frecuencia y peso en el algoritmo, y ver cómo esa operación se ve afectada por el tamaño de la entrada.

  • ¿Por qué es importante la elección de la operación correcta al medir la complejidad de un algoritmo?

    -La elección de la operación correcta es importante porque determina la precisión del análisis de la complejidad del algoritmo. Si se elige una operación que no se relacione directamente con el tamaño del problema o que no sea representativa del trabajo realizado por el algoritmo, el análisis podría ser incorrecto o no representativo.

Outlines

00:00

📊 Análisis de Funciones de Crecimiento en Algoritmos

El vídeo comienza explicando la importancia de las funciones de crecimiento (F de N) en la informática para entender cómo se comportan los algoritmos a medida que el tamaño del problema crece. Se menciona que en análisis empíricos, se usaba T de N para representar el tiempo que toma un algoritmo, pero ahora se busca una función más exacta que calcule directamente el número de operaciones necesarias para procesar un input de tamaño N. Se destaca que F de N puede variar mucho dependiendo del algoritmo; algunos crecen lentamente y son eficientes, mientras que otros crecen rápidamente y son menos eficientes. Además, se discute la necesidad de ser específico sobre qué operaciones se cuentan al analizar un algoritmo, ya que esto afecta directamente la forma de la función de crecimiento.

05:00

🔍 Cómo Seleccionar la Operación para Analizar en un Algoritmo

En este segundo párrafo, se profundiza en cómo elegir la operación adecuada para medir en un algoritmo. Se sugiere que se debe seleccionar una operación que ocurra con frecuencia y que no sea trivial, como una suma o un desplazamiento de bits, sino algo más complejo como intercambiar elementos en un array. Se enfatiza que aunque un algoritmo pueda tener muchas operaciones, lo importante es medir la que más peso tiene en el proceso general. Se utiliza el ejemplo del código fuente de una búsqueda binaria para ilustrar cómo se selecciona la operación a medir y cómo se evitan las que dependen de condiciones lógicas o que solo ocurren una vez.

10:03

🛠 Análisis Detallado del Código de Búsqueda Binaria

El tercer párrafo se centra en un análisis detallado del código de búsqueda binaria, identificando qué líneas son candidatas para medir en términos de su frecuencia y relevancia en el comportamiento del algoritmo. Se señala que las líneas que ocurren solo una vez o que están condicionadas por una lógica compleja deben evitarse. Se eligen para la medición las líneas que realizan comparaciones y cálculos dentro del bucle principal, ya que son operaciones que ocurren con frecuencia y están relacionadas con el tamaño del input. Se concluye con la importancia de ser cuidadoso al seleccionar las operaciones a medida para evitar complicaciones en el análisis de la eficiencia del algoritmo.

Mindmap

Keywords

💡F de N

F de N es una función de crecimiento que mide cómo cambia la cantidad de trabajo o tiempo necesario para ejecutar un algoritmo a medida que el tamaño del problema, representado por N, aumenta. En el video, se utiliza para analizar el rendimiento de algoritmos y determinar cuántas operaciones se requieren en función del tamaño del input.

💡Tamaño del problema

El tamaño del problema, representado por N, es una métrica clave que describe la cantidad de datos o la magnitud del input que un algoritmo debe procesar. En el video, se usa este concepto para explicar cómo varía el tiempo o las operaciones necesarias en un algoritmo, dependiendo de cuánto crezca el tamaño del problema.

💡Función de crecimiento

Una función de crecimiento calcula el número de operaciones necesarias para resolver un problema de cierto tamaño. Se utiliza para evaluar el comportamiento de un algoritmo a medida que aumenta la magnitud de los datos de entrada. En el video, las funciones de crecimiento son clave para comparar la eficiencia de diferentes algoritmos.

💡Análisis empírico

El análisis empírico es un método que evalúa el rendimiento de un algoritmo observando su comportamiento en la práctica, midiendo el tiempo o las operaciones necesarias en función del tamaño del problema. El video menciona este tipo de análisis como un punto de partida para discutir las funciones de crecimiento.

💡Operaciones

Las operaciones son las acciones básicas que un algoritmo realiza, como sumar, restar o comparar. En el video se explica que el tipo y número de operaciones influyen directamente en la función de crecimiento y, por lo tanto, en el tiempo de ejecución del algoritmo.

💡Algoritmo

Un algoritmo es un conjunto de instrucciones o pasos que se siguen para resolver un problema. En el contexto del video, se refiere a los procedimientos que se analizan utilizando funciones de crecimiento para determinar su eficiencia en función del tamaño del problema.

💡Big O

La notación Big O describe la eficiencia de un algoritmo en términos del peor de los casos, midiendo su comportamiento asintótico a medida que el tamaño del input crece. En el video se menciona que es crucial entender qué operaciones se están contando antes de determinar la notación Big O de un algoritmo.

💡Análisis del código

El análisis del código implica examinar el código fuente de un programa para identificar operaciones clave y su impacto en la eficiencia del algoritmo. En el video, se hace referencia a este análisis para identificar líneas de código que se deben considerar para medir su frecuencia y relevancia en el comportamiento del algoritmo.

💡Condicionales

Los condicionales, como las declaraciones if-else, son estructuras de control que determinan qué acciones tomar basándose en una condición. En el video, se explica que es difícil medir estas operaciones porque dependen del flujo del programa y no siempre ocurren, lo que afecta la precisión de las funciones de crecimiento.

💡Búsqueda binaria

La búsqueda binaria es un algoritmo eficiente que busca un elemento en una lista ordenada dividiendo repetidamente la lista en mitades. En el video, se utiliza como ejemplo de un algoritmo cuya función de crecimiento se puede analizar al contar operaciones clave como comparaciones y cálculos de índices medios.

Highlights

Discussing the concept of F of N and its representation of a growth function.

Explaining the empirical analysis and the use of T of N to represent time complexity.

Introducing the idea that growth functions aim to calculate something directly or exactly.

Growth functions take in problem size and return the number of operations needed for an algorithm.

The purpose of growth functions is to understand how work changes with increasing problem size.

Describing different growth functions and their implications for algorithm efficiency.

Highlighting that growth functions help determine how well an algorithm performs.

Explaining that growth functions are used to analyze operations needed to solve a given problem.

Discussing the need for precision in defining what F of N computes.

Pointing out that operations counted in growth functions should be frequently occurring and heavyweight.

Cautioning against counting operations that only happen once or are under conditional logic.

Stressing the importance of picking an operation that is indicative of the algorithm's overall complexity.

Providing an example of analyzing a binary search algorithm to determine which operations to count.

Explaining why certain lines of code in binary search are not suitable for growth function analysis.

Discussing the importance of understanding the dependency of operations on input size.

Concluding with a summary of how to select operations for growth function analysis in code.

Transcripts

play00:04

- In this video I want to discuss

play00:06

what exactly it is that F of N represents.

play00:09

And also what is the meaning of the parameter.

play00:12

All right, so in the previous section,

play00:13

we talked mainly about this idea of an empirical analysis

play00:16

where we had maybe N as being the size of a problem,

play00:19

and then we used the notation T of N to represent

play00:21

a function that abbreviated the amount of time.

play00:23

And that's fine, but now in this section

play00:25

what we really want to discuss

play00:26

is this more exact idea of a growth function.

play00:28

Now if you think back to the beginning,

play00:30

a while ago when we introduced

play00:31

some basic terminology of this section

play00:33

we said that growth functions are functions

play00:35

that are supposed to directly

play00:37

or exactly calculate something.

play00:38

Typically they calculate something like,

play00:40

they take in basically a problem size,

play00:42

for example the size of an array

play00:43

and return how many operations are needed

play00:45

in order to run that algorithm on that sized input.

play00:49

The purpose of the growth function

play00:50

is really is to basically say,

play00:57

okay as a problem gets bigger and bigger and bigger

play01:00

how does the amount of work I need to do

play01:02

on that function change?

play01:03

So some growth functions maybe look something like this,

play01:09

where this is basically our N over here,

play01:13

F of N is over here.

play01:16

Sometimes it'll look like this, which is actually very nice

play01:19

because as the problem size gets bigger,

play01:22

really I'm not having to spend all that much more time

play01:24

or work to solve that problem.

play01:26

My F of N value doesn't change all that much,

play01:29

that's very nice.

play01:30

That's a function that grows very slowly

play01:32

and it represents an algorithm that is pretty efficient.

play01:35

For an example, we have a growth function

play01:37

that looks like this.

play01:39

This is kind of the opposite case, where as N gets bigger,

play01:41

all of a sudden, F of N basically explodes

play01:43

and gives a very high value.

play01:46

All of a sudden your algorithm takes all this time to run

play01:49

and needs to do all this work

play01:51

in order to solve this particular problem.

play01:52

So that's something we don't wanna see.

play01:55

So growth functions basically give us a way

play01:56

to tell how well this algorithm acts.

play02:00

How much work is it gonna need to do?

play02:01

How many operations is it gonna need to execute

play02:04

in order to analyze and solve the problem that it was given.

play02:07

When I say problem that was given,

play02:08

really I'm saying is okay, we were given this input,

play02:10

size in, our problem is to do something like sort it

play02:13

and so what is it that it costs us,

play02:15

in order to solve that problem of sorting that input array.

play02:17

That's what I'm talking about.

play02:20

Okay, so what we need to really do here,

play02:23

to make our definition more precise,

play02:24

is say what exactly it is F of N is computing.

play02:28

So it's really not enough for it to say

play02:30

the number of operations.

play02:31

Because what does that even mean?

play02:33

I mean, there are a thousand operations,

play02:34

is an operation adding?

play02:35

Is it subtracting?

play02:37

Multiplying? Is it a bit shift?

play02:39

Is it a logical operation?

play02:40

Is it downloading a file?

play02:42

It could be a thousand things.

play02:43

And there's also the issue in there

play02:45

of what level of abstraction are we talking about.

play02:47

Are our operations something huge like downloading a file,

play02:51

are they even larger?

play02:51

Maybe they're like, sending a project to a development team.

play02:56

We could have any sort of operation happening on

play03:00

that right-hand side of a F of N thing.

play03:04

So we need to pick what operation

play03:07

is being counted, basically.

play03:08

A lot of times, you won't see this, though.

play03:10

If somebody ever asks you to do a big O on a function,

play03:13

that question really even in itself,

play03:14

doesn't really make sense.

play03:15

To write a big O for function,

play03:17

or to write a big F of N for function,

play03:19

if you don't know what you're counting up,

play03:21

right, because you could be counting anything.

play03:22

Code isn't simple.

play03:23

There's a thousand things happening in there,

play03:25

how are you supposed to know what to actually measure?

play03:27

What you measure has kind of, strong implications

play03:30

for what that growth function will look like.

play03:32

If I pick one thing, I get F of N equal one,

play03:34

and the odds are then equal two,

play03:36

another thing F of N equal N squared plus three.

play03:39

And that's kind of an issue,

play03:40

so I need to be very kind of specific

play03:43

and know what exactly it is that I'm counting up.

play03:45

What type of operation do I wanna look at.

play03:47

I'll do some examples there,

play03:48

to kind of illustrate the process of doing that.

play03:51

In general, what you wanna do,

play03:52

is you wanna pick an operation

play03:53

that is very frequently occurring.

play03:56

So we don't want you writing a growth function

play03:58

for an operation that only happens once.

play04:00

In that case, we basically don't have any knowledge

play04:03

of how the input size relates to that growth function.

play04:06

Because that growth function is measuring something

play04:07

that only happens once, it's just very kind of,

play04:11

well it's a constant.

play04:12

It's just not interesting to us.

play04:14

Second thing we look at is measuring something

play04:16

that's very kind of heavy weight.

play04:18

So, some operations are very, very quick,

play04:21

for example, just an addition or a bit shift,

play04:23

maybe it's not worth writing a big O for that,

play04:25

or writing a growth function for it,

play04:27

because it's something that happens very quickly.

play04:29

But if we have something like,

play04:30

maybe inside of a sorting function,

play04:32

for example, maybe one of the things it does

play04:34

is not just increment X or whatever,

play04:37

but also calls a function to swap two elements in an array,

play04:40

well that call to swap or exchange, or whatever you have,

play04:43

that would be in and of itself something worth measuring.

play04:46

Because that's a little bit more of a complex operation,

play04:49

it's something that the algorithm is expressed in terms

play04:51

of comparisons and exchanges and so it's worth it for us

play04:56

to measure those exchanges and those comparisons.

play04:58

Because that's kind of a basic operation

play05:00

that takes a little bit of time in an algorithm.

play05:02

And of course, we have the bonus there of,

play05:03

oh those are things that happen reasonably frequently.

play05:07

So that's what we wanna look at,

play05:08

we wanna look for something like that.

play05:10

Generally speaking, picking a specific thing to measure,

play05:13

isn't gonna hold us back.

play05:14

Sometimes people look at a huge function

play05:15

and they get told to just analyze it

play05:18

with respect to one line,

play05:19

and they feel like, oh hey,

play05:20

I'm gonna miss a bunch of things.

play05:21

But that's not really true.

play05:23

As long as you're picking what is basically,

play05:25

the heavier duty work that needs to be done,

play05:28

then your analysis is basically going to cover anything else

play05:32

that happens in that function.

play05:33

Even though there may be other things going on,

play05:34

may be having other function calls in there,

play05:37

other loops that are running.

play05:39

If we have that, well then, as long as our analysis

play05:43

is looking at the most heavy weight thing,

play05:44

it's going to encompass, it's going to exceed anything else

play05:47

that's happening in that function.

play05:48

So it should be good for us to just stick with that

play05:50

and not have to worry about everything else that's in there.

play05:52

So as our first example, let's jump across

play05:54

to the source code for binary search.

play05:56

And let's just try and figure out,

play05:58

what type of operation we might want to count up.

play06:01

So overall, the process for doing our analysis here,

play06:04

would be that we first start with some code,

play06:06

then we pick an operation to count up,

play06:08

then we write a growth function

play06:09

that counts those operations based on the size as the input.

play06:12

Then we have our big O and then from that big O,

play06:14

maybe we can compute a tilde or a big O expression

play06:18

from the growth function that we've recovered

play06:20

from the bit of code.

play06:21

That would be our general process.

play06:23

So pick our operation, write a growth function,

play06:26

then figure out big O or tilde.

play06:27

So I'd just do the first part here,

play06:29

and then later on we'll talk about how to do the rest of it.

play06:32

So here we have binary search and the question is,

play06:37

which line do we want to measure for our growth function?

play06:40

Now let's go over these one by one.

play06:42

So initially we have this sign over here,

play06:44

int lo equals zero.

play06:46

This line, just happens once.

play06:49

So in that case, it's not really fair to use

play06:52

that for our analysis, because it doesn't happen a lot.

play06:55

We notice later on that there is a loop.

play06:57

If there's a loop that's happening,

play06:59

then that loop probably has some dependency

play07:01

on how big the input is, right, how big is N?

play07:04

But this first time I'm looking at it, it only happens once,

play07:06

so there is no dependency there.

play07:08

Well in that case, I probably don't want to measure it,

play07:10

because it's not going to show me,

play07:12

kind of the full behavior of this method.

play07:14

I want to know how this method acts with respect

play07:17

to how it's input size changes.

play07:19

And this particular line, if I were to measure it,

play07:21

I just don't have that.

play07:22

This line will always happen, it'll happen exactly once.

play07:25

So I'll skip it, not good.

play07:27

This one over here, this line is also kind

play07:32

of falling under the same idea,

play07:33

in that it happens exactly once

play07:35

and it's not impacted by the size of the input data.

play07:38

So this is another one I would basically skip over.

play07:41

One kind of quick note slash caveat here,

play07:44

is that this little bit here

play07:45

is actually important, pool dot length.

play07:47

This part here is what's important to me.

play07:50

This is basically just accessing a variable inside

play07:52

of a object, arrays are objects in Java.

play07:56

Now, if I just did the dot, I'm getting just a value.

play08:00

That's fine, I'm not invoking a function.

play08:02

If I had parentheses over here,

play08:03

if I had length parenthesis parenthesis,

play08:05

then I would be invoking a function.

play08:07

And that would give me pause if I was doing analysis

play08:09

of this program, because then I have to start to wonder,

play08:11

what is the big O of that function?

play08:14

Right, because maybe length, if it was a function,

play08:17

what happens if that thing is big O of N cubed,

play08:21

or F of N of N cubed?

play08:23

All of a sudden, that kind of impacts my analysis

play08:26

for this overall program here.

play08:28

Right, so if I call functions,

play08:29

I need to be a little bit careful.

play08:31

So we just keep that in mind,

play08:32

here's just a remember variable,

play08:33

so we don't have to worry about it.

play08:36

So we get to the next line, well,

play08:38

so in here I'd probably don't wanna measure while.

play08:40

While is just a statement

play08:41

to show what's happening in the program.

play08:44

what's happening over here though,

play08:45

the operation, is this less than or equal to.

play08:47

Where I check this lo and the hi variables.

play08:50

This is actually going to be a good candidate for us,

play08:52

because this while loop is basically going to run

play08:55

until this condition is false,

play08:58

but that's going to be for later on,

play09:00

basically linked to the size of the input data.

play09:05

More input data we have, the more time this loop will run.

play09:08

So it would be a good idea potentially,

play09:11

to look at that line there.

play09:12

So I'm gonna put a check mark there

play09:14

and over here I'll put in X's for these two lines

play09:16

that didn't quite work out for us.

play09:18

That one will be okay, we would measure our less than

play09:20

or equal to, because it's going to basically depend

play09:22

on how many times I need to compare something in my input.

play09:26

Inside, I can see the actual math,

play09:28

basically for adjusting hi and lo

play09:29

and also a variable called mid.

play09:32

Okay, so looking inside, what else do I have here?

play09:36

My int and mid, this is another line

play09:38

that probably would be okay for me to analyze

play09:40

because nested right inside of the while loop,

play09:42

every time the while loop runs, this line will run as well.

play09:45

And the operation in there, I could measure the plus,

play09:47

the minus, the divide, it's all the same thing.

play09:50

These two lines are going to be the same.

play09:54

They'll run effectively the same number of times.

play09:57

The top one will run one more time because it needs to check

play10:00

for the exit condition, but they're effectively the same.

play10:03

I could pick each of those for analysis.

play10:05

Looking down, the first if statement,

play10:07

the operation there is a less than,

play10:09

that'll actually also happen the same number

play10:11

of times now that I'm thinking about it.

play10:12

So let's add that in there, those are all the same.

play10:14

So that'd be another kind of fair thing to analyze.

play10:16

What that's checking basically is to see okay,

play10:18

the target that I'm looking up is that gonna be less

play10:23

than what I'm currently using as my mid point?

play10:25

So I need to go and explore the left side,

play10:26

versus I'd need to go explore the right side.

play10:28

Remember this is binary search.

play10:30

So that would be a fair thing to compare it as well.

play10:33

Now we get down to this line here,

play10:34

hi equal mid minus one.

play10:35

This is a little bit problematic.

play10:37

This line here, is happening under an if statement.

play10:40

So there's some conditional logic

play10:42

that must occur in order for us to run that line.

play10:44

And the problem is, we don't really know,

play10:47

will that line run or not?

play10:48

Will hi equal mid run?

play10:50

For the if statement, we know that's always gonna run,

play10:52

right, cause it has to check that condition.

play10:54

Regardless of whether it's true or false,

play10:55

it still has to check it.

play10:56

But inside of it, it has to be true in order for us

play10:58

to actually run that inner line here.

play11:00

It has to be true in order for us to do this stuff here.

play11:03

So this has a dependency

play11:04

and I would avoid analyzing that if I could.

play11:08

And so the same thing actually applies

play11:10

to the rest of the stuff in here.

play11:12

So we're gonna have that else if, that else if code,

play11:14

that's only running if that first if values to false.

play11:17

So again, there's a dependency between whether this line

play11:20

is run and what is the true value for the earlier thing.

play11:23

So again, this is a line that I would not use.

play11:25

The same thing will also apply to the last return

play11:27

because again, it's like, what did that if of value do,

play11:29

true or false, will it get here or not?

play11:31

So those lines are all things that I would avoid.

play11:37

So yeah, I can measure either my loop exit,

play11:41

which is checking to see whether my bounds collide

play11:44

or when I compute the mid point.

play11:45

Either of those would be fair.

play11:47

The last thing here, is this return false,

play11:49

this return false is actually going to fall under

play11:51

the category of these, in that they only happen once.

play11:55

So if I get to the very end and I don't find the element,

play11:59

I just run that statement once.

play12:01

So actually there's two things

play12:03

that are actually happening there.

play12:04

One is that I don't wanna use it

play12:06

because it only happens once.

play12:07

Second thing is I don't wanna use it

play12:08

because I don't know when it'll occur,

play12:10

unless I know more about the data.

play12:11

So there's an additional dependency there.

play12:13

And we'll talk about, in a later video,

play12:14

data dependencies in more detail.

play12:17

So let's go over here and let's say,

play12:23

let me fill this in.

play12:24

So these, we kind of don't wanna use

play12:26

because they take a constant amount of time,

play12:27

these first two lines.

play12:29

These second two were good,

play12:30

because they have some core logic that happens,

play12:32

and it happens regularly.

play12:34

These five lines in here, we don't wanna use

play12:37

because they all have an input dependence,

play12:39

so I'll just call this an ID.

play12:42

And then that last line is both constant time

play12:46

and has instant input dependence.

play12:49

So again, example of something we don't wanna use.

play12:52

Okay so that's kind of a review of this particular function,

play12:57

again, think in terms of, when I wanna want

play12:59

to find a operation measure,

play13:00

I wanna find something that's happens relatively frequently,

play13:03

right, not constant time,

play13:05

hopefully it's a relatively heavyweight operation.

play13:07

Here we don't really have that notion

play13:08

because everything's just kind of arithmetic,

play13:10

so it's all kind of the same.

play13:11

And then also maybe we want to be careful

play13:13

that we pick things that aren't under logical expressions,

play13:16

because then we'll have a hard time measuring them.

play13:18

So keep those things in mind when you're analyzing code,

play13:20

we'll do some more examples later.

Rate This

5.0 / 5 (0 votes)

Ähnliche Tags
Análisis EmpíricoFunción de CrecimientoAlgoritmosEficienciaTiempo de EjecuciónOptimizaciónProgramaciónBinary SearchNotación AsintóticaAnálisis de Código
Benötigen Sie eine Zusammenfassung auf Englisch?