[SER222] Characterizing Algorithms (2/5): Perspectives on Algorithm Analysis

Ruben Acuna
15 Aug 201708:31

Summary

TLDREn este video, se exploran dos perspectivas sobre el análisis de algoritmos: la teórica y la de ingeniería de software. Desde el enfoque teórico, se analiza la complejidad temporal y espacial, y se cuestiona cuál es el algoritmo más eficiente o si un problema puede ser resuelto. Por otro lado, desde la ingeniería de software, el análisis de algoritmos ayuda a los ingenieros a seleccionar el más adecuado para cada situación, permitiendo una mejor comunicación y garantizando que las soluciones sean prácticas y eficientes en tiempo y espacio.

Takeaways

  • 🧠 El análisis de algoritmos es útil tanto desde la perspectiva teórica como desde la de ingeniería de software.
  • 🕒 La complejidad temporal mide el tiempo que toma un algoritmo para ejecutarse, mientras que la complejidad espacial mide el espacio que utiliza.
  • 📚 Los teóricos clasifican los algoritmos en clases de complejidad, como aquellos que terminan en un tiempo finito o aquellos que podrían no terminar nunca.
  • 💡 Una pregunta clave es: ¿Cuál es el mejor algoritmo posible para resolver un problema? Los teóricos investigan la estructura del problema para determinarlo.
  • 🚫 Existen problemas que no se pueden resolver con ningún algoritmo; están en una clase de complejidad llamada 'intratables'.
  • 🔍 Los ingenieros de software se enfocan en comparar algoritmos y seleccionar el más adecuado según el contexto y los recursos disponibles.
  • 📏 El análisis de algoritmos permite una mejor comunicación sobre el rendimiento, ayudando a describir qué tan rápido o eficiente es un programa.
  • 🛠️ Elegir el algoritmo correcto es crucial para evitar comportamientos inesperados que podrían afectar negativamente el rendimiento en producción.
  • 🚀 El análisis de algoritmos garantiza que los programas funcionen de manera predecible dentro de un límite de tiempo aceptable, lo que es vital para aplicaciones en tiempo real.
  • ⏳ Un algoritmo que tarda demasiado en ejecutarse, incluso si es perfecto, no es práctico; la eficiencia es clave en la aplicabilidad de una solución.

Q & A

  • ¿Qué perspectivas diferentes menciona el video para analizar algoritmos?

    -El video menciona dos perspectivas para analizar algoritmos: la teórica y la de ingeniería de software.

  • ¿Por qué es útil el análisis de algoritmos desde un punto de vista teórico?

    -Desde la perspectiva teórica, el análisis de algoritmos permite entender la complejidad temporal y espacial de un algoritmo, así como clasificar los problemas en clases de complejidad.

  • ¿Qué es la complejidad temporal de un algoritmo?

    -La complejidad temporal se refiere al tiempo que toma un algoritmo en ejecutarse, es decir, cuánto tiempo tarda en devolver una solución.

  • ¿Qué pregunta interesante sobre algoritmos se plantean los teóricos?

    -Una de las preguntas que se plantean los teóricos es: ¿Cuál es el algoritmo más rápido posible que puede existir para resolver un problema dado?

  • ¿Qué es una clase de complejidad?

    -Una clase de complejidad es un grupo de algoritmos que comparten características similares en cuanto a su eficiencia temporal o espacial.

  • ¿Cuáles son las tres categorías de problemas según su resolución?

    -Los problemas se dividen en tres categorías: problemas que se pueden resolver de manera eficiente, problemas que se pueden resolver pero sin eficiencia, y problemas que no se pueden resolver en absoluto.

  • ¿Qué busca un ingeniero de software al analizar un algoritmo?

    -Un ingeniero de software busca determinar cuál es el algoritmo más adecuado para una situación específica, considerando su rendimiento en diferentes circunstancias.

  • ¿Por qué es importante la comunicación en el análisis de algoritmos?

    -Es importante para poder explicar claramente a otros, como compañeros o accionistas, si un algoritmo es eficiente en términos de tiempo y espacio, y si cumplirá con los requisitos del proyecto.

  • ¿Qué permite la categorización de algoritmos en 'buckets' o grupos?

    -La categorización permite identificar rápidamente qué algoritmos son más eficientes en comparación con otros, sin tener que analizar cada uno individualmente en detalle.

  • ¿Cuál es el valor de la garantía de comportamiento en los algoritmos?

    -La garantía de comportamiento asegura que un algoritmo actuará dentro de los límites esperados, evitando comportamientos inesperados que podrían perjudicar el rendimiento de un sistema.

Outlines

00:00

🔍 Introducción al análisis de algoritmos

En este párrafo, se presentan dos perspectivas sobre el análisis de algoritmos: la teórica y la de la ingeniería de software. Aunque los estudiantes son ingenieros de software, el análisis de algoritmos es útil no solo para ellos, sino también para matemáticos y científicos de la computación. Se introducen conceptos como la complejidad temporal y espacial, que permiten clasificar algoritmos en diferentes 'cubos' según su rendimiento.

05:01

⏳ Complejidad temporal y espacial

Aquí se explica cómo los teóricos analizan los algoritmos desde la perspectiva de la complejidad temporal y espacial, y cómo esto permite clasificar algoritmos en categorías más precisas que simples 'cubos'. Se menciona el uso de clases de complejidad y se aclara que el enfoque de la clase estará en problemas que se puedan resolver en un tiempo finito, excluyendo problemas que podrían tardar eternamente en ejecutarse.

🚀 La búsqueda del mejor algoritmo

Este párrafo trata sobre la búsqueda de los algoritmos más eficientes. Los teóricos se preguntan cuál es el algoritmo más rápido posible para un problema, aunque no siempre lo construyen. Exploran la estructura del problema para inferir cuál podría ser el mejor enfoque, incluso sin tener una solución específica.

❓ ¿Se puede resolver el problema?

Se aborda la cuestión de si un problema puede resolverse en absoluto. Se menciona que existen problemas sin solución algorítmica y se presentan tres categorías de problemas: aquellos que se pueden resolver eficientemente, los que se pueden resolver pero no de manera eficiente, y los que son intratables, es decir, imposibles de resolver.

🔧 Perspectiva de la ingeniería de software en el análisis de algoritmos

Se introduce la visión de los ingenieros de software sobre el análisis de algoritmos. A menudo, tienen múltiples opciones para resolver un problema, y el análisis de algoritmos les permite comparar diferentes métodos (como ordenamiento por inserción o selección) para elegir el más adecuado según las circunstancias específicas.

👨‍💻 Evaluación y comparación de algoritmos

Aquí se profundiza en cómo los ingenieros de software utilizan el análisis de algoritmos para evaluar y comparar diferentes métodos. El objetivo es entender cómo actúan los algoritmos, más allá de simplemente observar el código, y utilizar expresiones matemáticas para describir y comunicar su rendimiento.

📊 Clasificación y simplificación de la toma de decisiones

Se discute cómo clasificar los algoritmos en 'cubos' basados en su rendimiento en términos de tiempo y espacio. Este enfoque facilita la toma de decisiones, permitiendo a los ingenieros elegir algoritmos de grupos que ya se sabe que son más eficientes sin tener que analizar cada uno individualmente.

⚠️ Comportamiento inesperado de los algoritmos

Este párrafo advierte sobre la posibilidad de que algunos algoritmos tengan un comportamiento inesperado bajo ciertas condiciones, lo que podría ser perjudicial en entornos donde se requiere un rendimiento constante. El análisis de algoritmos ayuda a garantizar un comportamiento predecible y evitar sorpresas en producción.

⏱️ Garantía de rendimiento y comunicación con partes interesadas

Finalmente, se resalta la importancia de garantizar que un algoritmo pueda completarse dentro de un tiempo razonable. Esto es crucial tanto para el funcionamiento del software como para la comunicación con los clientes o accionistas, asegurando que los resultados lleguen a tiempo y evitando algoritmos que, aunque correctos, tarden demasiado en ejecutarse.

Mindmap

Keywords

💡Análisis de algoritmos

El análisis de algoritmos es el proceso de estudiar y evaluar el rendimiento de un algoritmo, particularmente en términos de tiempo y espacio. En el video, se menciona desde dos perspectivas: teórica y de ingeniería de software, para determinar si un algoritmo es eficiente o práctico.

💡Complejidad temporal

La complejidad temporal se refiere al tiempo que un algoritmo tarda en ejecutarse, lo que depende del tamaño de la entrada. En el video, se presenta como una forma de clasificar algoritmos en 'cubos' que representan cuánto tiempo tardan en ejecutarse en situaciones similares.

💡Complejidad espacial

La complejidad espacial mide la cantidad de memoria que un algoritmo utiliza durante su ejecución. Al igual que con la complejidad temporal, los algoritmos se agrupan en 'cubos' según cuánto espacio consumen, ayudando a comparar su eficiencia.

💡Clases de complejidad

Las clases de complejidad agrupan algoritmos y problemas según la cantidad de recursos que requieren, como tiempo o espacio. El video menciona que los teóricos clasifican algoritmos en estas clases, incluyendo aquellos que no pueden ser resueltos en un tiempo finito.

💡Teórico

Un teórico en ciencias de la computación investiga la naturaleza fundamental de los algoritmos, preguntándose cuestiones como '¿Cuál es el mejor algoritmo posible?' o '¿Es este problema resoluble?'. En el video, el enfoque teórico se contrasta con el práctico de los ingenieros de software.

💡Problema intratable

Un problema intratable es aquel para el cual no existe un algoritmo que pueda resolverlo en un tiempo razonable, o no puede ser resuelto en absoluto. El video menciona problemas de este tipo como ejemplos de límites en la resolución de problemas por parte de los algoritmos.

💡Ingeniería de software

La ingeniería de software se refiere a la aplicación práctica de principios de diseño y análisis para crear programas eficientes. En el video, se destaca cómo los ingenieros de software usan el análisis de algoritmos para elegir el más adecuado en función de las necesidades del proyecto.

💡Eficiencia

La eficiencia de un algoritmo se mide por la cantidad de tiempo o espacio que consume en relación con el tamaño del problema que resuelve. En el video, se enfatiza la importancia de elegir algoritmos eficientes que resuelvan problemas en un tiempo razonable.

💡Comparación de algoritmos

La comparación de algoritmos implica analizar múltiples algoritmos para un mismo problema y determinar cuál es el más eficiente o adecuado para una situación específica. El video discute cómo los ingenieros de software usan este análisis para seleccionar el algoritmo correcto.

💡Garantía de comportamiento

Una garantía de comportamiento es una previsión de cómo un algoritmo se comportará en términos de tiempo o espacio en cualquier circunstancia. En el video, se menciona que el análisis de algoritmos permite garantizar que un algoritmo no tendrá un rendimiento inesperadamente lento en producción.

Highlights

Algorithm analysis is important from both theoretical and software engineering perspectives.

Theoretical perspective focuses on time and space complexity, categorizing algorithms based on how long they take to run and how much memory they use.

Theorists often explore the idea of 'complexity classes,' categorizing problems and algorithms into various types of complexity.

Some problems can be solved efficiently, some are solvable but not efficient, and some are unsolvable.

The theorist’s goal is often to find the best algorithm for a problem, determining which algorithm runs the fastest or uses the least resources.

Some problems are intractable, meaning no algorithm can solve them, such as the famous 'Halting Problem.'

Software engineers care about algorithm analysis because it helps them decide which algorithm is best suited for a particular problem in real-world applications.

In practice, algorithms with similar performance are grouped into 'buckets,' helping engineers quickly choose the right one.

Software engineers also look at how algorithms behave in specific contexts, ensuring they are appropriate for expected use cases.

Comparing algorithms helps to avoid writing inefficient code that might take significantly longer to run or use excessive resources.

Algorithm analysis also ensures that algorithms provide predictable performance, crucial in real-time or safety-critical systems.

Efficient algorithms are crucial in ensuring that programs provide results within a reasonable timeframe.

Engineers use mathematical expressions to summarize the behavior of algorithms, allowing for easier comparison.

Communicating how fast an algorithm runs or how much space it uses is essential for justifying solutions to stakeholders.

Ultimately, algorithm analysis helps ensure that programs will complete within the necessary time frame, providing realistic, applicable solutions.

Transcripts

play00:05

- In this video, I wanna introduce some ideas

play00:07

about why algorithm analysis is interesting

play00:09

from two different perspectives.

play00:11

One is the theoretical perspective,

play00:13

the second is the software engineering perspective.

play00:16

So, you guys in this class are software engineers,

play00:19

but algorithm analysis isn't just for software engineers,

play00:21

it's not just for people in the industry,

play00:22

for developers, for programmers,

play00:24

it's also for mathematicians,

play00:26

it's for computer scientists.

play00:27

It's useful from a lot of different standpoints.

play00:30

So, let's talk about the theorist's viewpoint first,

play00:32

because that's maybe a little bit new to you guys.

play00:35

So, a theorist might look at an algorithm

play00:36

and ask themselves the following question:

play00:38

What is the time complexity of it?

play00:39

Or, what is the space complexity?

play00:41

This is actually going back to the buckets analogy

play00:43

from the previous video.

play00:44

When we say time complexity, we're basically saying is,

play00:47

what is the,

play00:48

basically the amount of time this algorithm takes?

play00:50

It takes this long, right?

play00:52

And you can imagine you have a bunch of algorithms

play00:53

that are all going to the same bucket.

play00:54

They all have the same time complexity.

play00:56

Or they all go into another bucket.

play00:58

For space complexity.

play00:59

They all act roughly the same.

play01:01

So, time complexity and space complexity

play01:03

are actually the more formal terms

play01:05

for these things that we're gonna be looking at.

play01:07

That's what theorists always understand.

play01:09

What is the complexity of an algorithm?

play01:10

And then there's this idea of complexity classes, right?

play01:13

That's more precise than buckets.

play01:15

We'll be using, basically,

play01:17

a subset of the complexity classes

play01:19

that theorists talk about.

play01:20

We'll be talking about the classes of complexity,

play01:22

the classes of space,

play01:24

that are trackable,

play01:25

that are things that we can actually hope to,

play01:28

that we can actually hope will terminate

play01:30

in a finite amount of time.

play01:31

Meaning I can run my algorithm,

play01:32

and I get the answer back.

play01:33

Theorists now talk about algorithms that are practical,

play01:36

and I can run them, I can get a result back,

play01:38

but theorists also like talking about algorithms

play01:39

that are basically things that maybe take forever to run.

play01:43

That's actually a complexity class.

play01:46

There's all sorts of things

play01:47

that theorists look at,

play01:48

just from the standpoint of "Oh, such a thing exists."

play01:51

For us though, we'll be constrained

play01:52

to the realm of problems that we can actually solve.

play01:56

Another question that theorists like thinking about

play01:58

is this idea of "What is the best algorithm I can have?"

play02:02

So, for some problem, let's say,

play02:04

what is the best algorithm out there

play02:05

that I could have?

play02:06

Maybe I have this algorithm that takes you an hour

play02:08

and another algorithm that takes half an hour.

play02:09

Well, is there anything that could take 15 minutes?

play02:11

What is the fastest possible algorithm

play02:13

that could be constructed?

play02:13

This is another very interesting question for theorists.

play02:16

And know here, that I'm saying,

play02:17

"What is the fastest algorithm that can be constructed?"

play02:19

That doesn't mean that they don't

play02:20

actually create an algorithm that is super fast, right?

play02:22

They're actually going to do some research

play02:24

on the structure of the problem itself

play02:26

and try to figure out

play02:27

what is the fastest algorithm,

play02:30

or, the fastest algorithm that could solve this problem,

play02:32

what does it look like?

play02:34

Even without having that algorithm,

play02:35

they can still make some guesses on what it could look like.

play02:39

So, very, very interesting, it is for me.

play02:41

My background is maybe a little bit more in theory

play02:42

than other people.

play02:44

All right, so last idea here

play02:46

is the idea of "Can a problem be solved at all?"

play02:47

So, this is an overarching question.

play02:50

So, a theorist might ask the following:

play02:53

For this question,

play02:54

for this problem that's been solved,

play02:55

been posed,

play02:56

can it be solved at all?

play02:57

Because there are actually problems

play02:58

that can't be solved.

play02:59

There are problems for which no algorithm exists.

play03:03

There's kind of three classes.

play03:04

We say,

play03:05

there's algorithms such problems

play03:07

that can be solved efficiently,

play03:08

meaning I can run a program.

play03:09

I can run an algorithm for it.

play03:10

I can run it and that algorithm

play03:11

will terminate in a decent amount of time.

play03:13

And then there's problems that I can solve,

play03:14

but I cancel efficiency.

play03:15

That's things that I can write an algorithm for.

play03:17

I can run it.

play03:18

I know it would just take forever to run.

play03:19

And then the third category is

play03:21

simply things that are intractable,

play03:22

things that cannot be solved whatsoever.

play03:24

So there problems basically

play03:26

beyond the scope of any algorithm.

play03:28

Which might seem odd.

play03:30

That's actually also a very bold claim to make,

play03:32

to say that no one will ever be able to solve this problem.

play03:35

But there's certainly something we can do.

play03:37

Usually it's along the lines of,

play03:39

there's a specific example people always use,

play03:41

it's the healthy machine.

play03:42

You can go search for more information, if you want.

play03:44

That's a pretty good problem

play03:45

that's intractable, not completely unsolvable,

play03:48

because, basically, an existence of an algorithm

play03:51

to solve that problem would contradict

play03:54

the existence of an algorithm to solve that problem.

play03:56

So, you can't solve it,

play03:57

because if you could solve it, you can't solve it.

play03:59

So, there are some very odd things

play04:02

that happen in these higher complexity classes

play04:03

and get to really hard problems.

play04:05

But again, we won't really worry about that here.

play04:06

Really, we're gonna talk about

play04:07

problems that can be solved efficiently,

play04:09

and how do we analyze the algorithms that can address them.

play04:12

So, moving forward,

play04:13

let's talk about the software engineering perspective on it.

play04:16

A lot of times when we're designing a solution to something,

play04:19

we'll have different choices.

play04:21

So, think about story.

play04:22

There's a whole bunch of different

play04:23

sort of algorithms that you could apply to that problem.

play04:26

For example, in 200, you probably learned about

play04:28

insertion store, or selection store.

play04:29

So, you have two algorithms

play04:30

that basically can give you the same thing back out.

play04:32

A stored output.

play04:33

How do we know which one is appropriate for us?

play04:37

That's what a software engineer cares about

play04:39

checking in terms of algorithm analysis.

play04:41

They want a way to look at those two algorithms

play04:43

and figure out, okay,

play04:45

this one works better in this circumstance,

play04:47

this other one works better in that circumstance,

play04:49

and this is the standard use case I expect to have,

play04:52

so this is what I'm going to go with.

play04:54

But, again, we need basically

play04:56

a way to understand our algorithms.

play04:57

Because otherwise

play04:58

basically what we have is a hundred lines of code

play05:00

and the question is,

play05:01

what does this do?

play05:02

How does it act, based on how I use it?

play05:04

And just looking at code, it's very hard to judge.

play05:07

How do these two things perform?

play05:09

I can't really tell, just by looking at code.

play05:10

Or I want some sort of nice summary,

play05:12

mathematical expression,

play05:14

that'll tell me how these things act.

play05:15

And then hopefully I can compare those expressions

play05:17

and figure out which one is the best one for me.

play05:21

So, thinking again about algorithm analysis,

play05:23

the result is,

play05:24

we're gonna be able to characterize things,

play05:25

to categorize them.

play05:27

Big motivation there,

play05:29

in addition to stuff we already talked about,

play05:30

is simply communication, right?

play05:31

It's nice to be able to tell someone,

play05:32

"Oh, my algorithm is this fast or this slow."

play05:35

Otherwise we just come to say basically,

play05:37

"Oh yeah, I solved your problem."

play05:39

But you're not really telling them much, right?

play05:41

Because, does your program take days to run

play05:42

or does it take seconds to run?

play05:44

You want a way to communicate

play05:45

how efficient your program is,

play05:47

either in time or in space.

play05:50

Okay, so let's say we have

play05:51

a bunch of different algorithms out there.

play05:53

They all maybe haven't sorted these little buckets

play05:55

that say, this is how fast they are,

play05:57

this how much space they use.

play05:58

Once we have that,

play06:00

we can basically look at those buckets

play06:01

and rank them,

play06:02

and say, "Okay, all algorithms in this bucket

play06:03

"are better than everything else."

play06:05

So, rather than having to evaluate everything,

play06:07

we're basically narrowing our scope

play06:08

and saying, okay, this one grouping,

play06:10

these algorithms in the first bucket,

play06:11

those are the ones that all perform roughly the same,

play06:13

and so I can just grab one of those.

play06:15

I don't have to worry too much

play06:16

about all those other algorithms.

play06:17

I don't need to spend hours

play06:17

investigating a hundred lines of code

play06:19

or reading documentation, or whatever, right?

play06:21

We fell into a different bucket.

play06:22

That bucket ranks lower than the one in front,

play06:23

so I don't even care about it.

play06:24

I just take from the bucket in front.

play06:27

The last idea is this:

play06:29

Our analysis also gives us a way to discover

play06:34

behavior that somehow may hurt us.

play06:35

So, a lot of times you'll have algorithms

play06:37

that are maybe are in an environment

play06:38

where you need to know that for sure

play06:39

it's gonna take so long to execute.

play06:41

Maybe you have some embedded hardware,

play06:42

or you have some live algorithm

play06:44

where you need to make sure that this is,

play06:46

checking the safety status,

play06:47

you know, a hundred times a second.

play06:49

Well, what happens if,

play06:51

in your little piece of code,

play06:52

there's something in there

play06:53

that balloons that upright to take

play06:55

a full second, instead of a hundredth of a second,

play06:56

or something like that.

play06:59

That would be very bad,

play07:00

because maybe it doesn't show up in testing,

play07:02

you get down into production,

play07:03

and all of a sudden you have this little blip,

play07:05

where things just go very wrong.

play07:07

Well, with algorithm analysis,

play07:09

we'll end up having,

play07:10

that when we sort these things,

play07:11

we'll have a guarantee of how they act.

play07:13

So, if an algorithm goes in that first bucket,

play07:15

it's gonna act like everything else in that bucket.

play07:17

It's gonna take this amount of time.

play07:18

It's never gonna spike, you know,

play07:20

and take way, way, way longer.

play07:23

We have this guarantee of how long it'll take.

play07:26

This can also be useful sometimes

play07:27

with dealing with your shareholders,

play07:29

and basically arguing, okay,

play07:30

for sure, my solution is going to get your answer back,

play07:33

in the appropriate amount of time.

play07:34

There's not a chance that

play07:36

it could take all weekend to run.

play07:37

No, it's gonna take a short amount of time.

play07:39

It's gonna be good to go.

play07:41

So, that kinda ties back into

play07:42

the first point about communication.

play07:44

It's a way to talk to people

play07:45

about the solution that you've created.

play07:47

And then the last thing there,

play07:48

that's kind of the ultimate question,

play07:49

which is, simply put,

play07:52

is the program that I've written,

play07:54

is it going to complete fast enough

play07:57

that I get back a solution when I need it?

play07:59

Is it not gonna take all weekend?

play08:00

Is it gonna be there when I want it?

play08:01

That's all they really care about, right?

play08:03

We care about actually being able to apply our algorithms

play08:05

and get an answer from them.

play08:07

Because running an algorithm,

play08:08

I mean, running algorithms is very nice.

play08:10

It gives us a potential solution to your problem,

play08:11

but if that solution basically takes forever,

play08:14

it could be perfect.

play08:15

It could give you the best answer to the problem

play08:17

that could possibly be found,

play08:19

but if that problem takes forever to be solved,

play08:21

it's no good.

play08:23

So, we kind of care about what algorithms are realistic,

play08:27

and will give us our answer in a reasonable amount of time.

Rate This

5.0 / 5 (0 votes)

関連タグ
Análisis de algoritmosComplejidad temporalIngeniería de softwareTeoría computacionalEficiencia algorítmicaDesarrollo de softwareAlgoritmos prácticosOptimización de códigoSolución de problemasRendimiento de programas
英語で要約が必要ですか?