Projeto e Análise de Algoritmos - Aula 10 - Ordenação em tempo linear

UNIVESP
22 Sept 201721:12

Summary

TLDRThis video script delves into the realm of linear time complexity sorting algorithms. It introduces and explains three specific algorithms: Counting Sort, Radix Sort, and Bucket Sort. The script discusses the prerequisites for each algorithm, such as the range of input values and the nature of the data. It provides step-by-step explanations of how each algorithm functions, including the use of auxiliary arrays and accumulation techniques. The video also touches on the stability of sorting algorithms and the time complexity considerations for each method, offering insights into their practical applications and efficiency.

Takeaways

  • 📚 The lecture introduces linear time complexity algorithms, focusing on Counting Sort, Radix Sort, and Bucket Sort.
  • 🔢 Counting Sort is based on the assumption that the input elements are integers within a known range, allowing for a direct placement of elements in the sorted array.
  • 📈 Radix Sort is highlighted for sorting numbers based on their individual digits, starting from the least significant digit to the most significant.
  • 📝 Bucket Sort is explained as a method suitable for uniformly distributed data within a specific range, dividing the data into 'buckets' and then sorting each bucket individually.
  • 💡 Counting Sort uses a counting array to determine the position of each element, ensuring that elements with the same value maintain their original order, making it a stable sorting algorithm.
  • 📊 Radix Sort involves multiple passes, sorting by each digit in sequence, and requires a stable sorting algorithm for each pass to maintain the original order of equal elements.
  • 🗂️ Bucket Sort divides the range [0, 1] into 'n' buckets and uses insertion sort to order elements within each bucket, which is efficient when the distribution of elements is uniform.
  • 🕒 The time complexity of Counting Sort is O(n+k), where 'n' is the number of elements and 'k' is the range of input values.
  • 🔄 The time complexity for Radix Sort depends on the number of digits 'd' and the time complexity of the stable sorting algorithm used in each pass, typically O(d*n).
  • 🌐 The efficiency of Bucket Sort is contingent upon the uniformity of data distribution; if the data is uniformly distributed, the expected time complexity is linear, O(n+k).
  • 🔑 The script emphasizes the importance of understanding the nature of the data (e.g., range, distribution) when selecting an appropriate sorting algorithm for optimal performance.

Q & A

  • What is the main topic of the video script?

    -The main topic of the video script is linear time complexity sorting algorithms, specifically counting sort, radix sort, and bucket sort.

  • What is the time complexity of comparison-based sorting algorithms?

    -The time complexity of comparison-based sorting algorithms is Ω(n log n), where n is the number of elements to be sorted.

  • What is counting sort and how does it work?

    -Counting sort is a non-comparison-based sorting algorithm that works by counting the number of objects that have a distinct key value and using arithmetic to determine the positions of each key in the output sequence.

  • What is the precondition for using counting sort?

    -The precondition for using counting sort is that the input consists of integers in a small range, and you know the range of possible values beforehand.

  • How does radix sort differ from counting sort?

    -Radix sort differs from counting sort in that it processes the input numbers digit by digit, starting from the least significant digit to the most significant, using a stable sort for each digit.

  • What is bucket sort and how does it operate?

    -Bucket sort operates by distributing elements into several 'buckets' and then sorting these buckets individually, often using insertion sort, before concatenating the buckets to get the final sorted list.

  • What is the significance of the term 'stable' in sorting algorithms?

    -A 'stable' sorting algorithm is one that maintains the relative order of records with equal keys (i.e., values) as they appeared in the input.

  • What is the time complexity of bucket sort if the elements are uniformly distributed?

    -If the elements are uniformly distributed, the expected time complexity of bucket sort is O(n + k), where n is the number of elements and k is the number of buckets.

  • How does the script mention the use of an auxiliary array in counting sort?

    -The script mentions the use of an auxiliary array to count the occurrences of each element and to determine the position where each element should be placed in the final sorted array.

  • What is the importance of maintaining the original order in stable sorting algorithms?

    -Maintaining the original order in stable sorting algorithms is important when the same elements appear multiple times in the input, ensuring that their relative order is preserved in the sorted output.

  • What is the script's stance on the efficiency of sorting algorithms?

    -The script suggests that the efficiency of sorting algorithms can be determined by their time complexity, with linear time complexity algorithms being particularly advantageous for large datasets.

Outlines

00:00

📚 Introduction to Linear Sorting Algorithms

This paragraph introduces the topic of linear sorting algorithms, focusing on those that operate in linear time complexity. It mentions several linear sorting algorithms, including counting sort, radix sort, and bucket sort, and highlights their unique characteristics. The speaker explains that these algorithms utilize operations other than comparison to determine the sorted sequence, which is a departure from traditional comparison-based sorting algorithms. The paragraph also sets the stage for a detailed explanation of each algorithm in subsequent sections.

05:02

🔢 Detailed Explanation of Counting Sort

The second paragraph delves into the specifics of counting sort, an algorithm that assumes the input consists of integers within a small range. The process involves counting the occurrences of each element and using this information to determine the sorted order. The speaker provides a step-by-step walkthrough of how counting sort works, including the use of auxiliary arrays to count occurrences and to place elements in their correct positions. The paragraph also discusses the time complexity of counting sort, emphasizing its linear performance with respect to the number of elements being sorted.

10:04

🔡 Radix Sort and its Iterative Digit-by-Digit Approach

This paragraph discusses radix sort, an algorithm that sorts numbers based on their individual digits. The explanation begins with the assumption that the numbers have a fixed length, such as a certain number of digits. The process involves sorting the numbers by each digit, starting from the least significant to the most significant, while maintaining the previous order from the previous digit's sort. The speaker illustrates how radix sort can be implemented using a stable sorting algorithm for each digit, and the importance of using a stable sort to preserve the original order of equal elements.

15:05

📊 Bucket Sort and Its Uniform Random Distribution Assumption

The fourth paragraph introduces bucket sort, which is based on the assumption that the input elements are uniformly distributed within a specific range. The algorithm divides the range into several 'buckets' and distributes the elements among these buckets. It then sorts the elements within each bucket using insertion sort and finally concatenates the sorted elements from all buckets to produce the final sorted list. The speaker explains the process with an example and discusses the expected time complexity, which depends on the uniform distribution of elements among the buckets.

20:08

🎓 Conclusion of Linear Sorting Algorithms Lecture

The final paragraph wraps up the lecture on linear sorting algorithms. It summarizes the key points covered in the lecture and expresses hope that the audience found the content engaging and informative. The paragraph ends with a musical note, signifying the conclusion of the session.

Mindmap

Keywords

💡Linear Time Algorithm

A linear time algorithm is one that has a time complexity of O(n), where 'n' is the size of the input. It means the time it takes to process the input scales linearly with the input size. In the context of the video, linear time algorithms are discussed in relation to sorting algorithms that can potentially sort data in a time proportional to the number of elements being sorted, which is a highly desirable property for efficiency.

💡Counting Sort

Counting sort is a linear time sorting algorithm used when the range of input data is known and not significantly larger than the number of objects to be sorted. It operates by counting the number of objects that have each distinct key value and using arithmetic to determine the positions of each key. In the video, counting sort is mentioned as the method used to sort elements in linear time, given the preconditions are met.

💡Bucket Sort

Bucket sort, also known as bin sort, is a distribution sort that works by partitioning an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm or by recursively applying the bucket sorting algorithm. The video script discusses bucket sort as an algorithm that divides the range [0, 1] into 'n' buckets and sorts the numbers within each bucket using insertion sort.

💡Insertion Sort

Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. However, it provides a good example of a stable sort, and in the video, it is used as a secondary sorting method within each bucket in the bucket sort algorithm.

💡Stable Sort

A stable sort is an algorithm that maintains the relative order of records with equal keys (values). In the context of the video, stability is important when sorting numbers by their digits because it ensures that the original order of equal elements is preserved. The script mentions that bucket sort and counting sort are stable sorts, which is crucial for maintaining the order of elements with the same value.

💡Digit by Digit Sorting

Digit by digit sorting is a technique used in sorting algorithms to sort numbers based on each digit, starting from the least significant digit to the most significant. This method is used in radix sort, and the video script refers to a similar approach where numbers are sorted by their individual digits, ensuring that the order of numbers with the same leading digits is maintained.

💡Comparison-Based Sorting

Comparison-based sorting algorithms determine the order of elements by comparing them to one another. The video script mentions that any comparison-based sorting algorithm must perform at least Omega(n log n) comparisons in the average and worst cases, highlighting the lower bound for comparison sorts.

💡O(n) Notation

O(n) notation, also known as linear notation, describes an algorithm's performance in terms of the number of basic operations it performs in relation to the input size 'n'. In the video, O(n) is used to describe the time complexity of certain sorting algorithms that can operate in linear time, which is an optimal performance for sorting large datasets.

💡Asymptotic Behavior

Asymptotic behavior refers to the behavior of a function as its argument approaches infinity or negative infinity. In the context of the video, the term is used to describe the performance of sorting algorithms, specifically how their efficiency scales with the size of the input data. Algorithms that are asymptotically optimal, such as those with O(n log n) complexity, are desirable for large datasets.

💡Radix Sort

Radix sort is an integer sorting algorithm that sorts data with integer keys by grouping the keys by the individual digits which share the same significant position and value. The video script discusses a variant of radix sort, known as 'adic short', which sorts numbers based on their digits, starting from the least significant to the most significant.

💡Bucketing

Bucketing is the process of distributing elements into different buckets or groups based on certain criteria. In the context of bucket sort, the video script describes bucketing as the initial step where numbers are distributed into buckets based on their value ranges, which is a critical step before applying insertion sort to each bucket.

Highlights

Introduction to linear time algorithms.

Discussion on comparison-based sorting algorithms and their lower bound of Omega(n log n) comparisons.

Introduction to Counting Sort, a linear time algorithm used for sorting integers within a certain range.

Explanation of how Counting Sort works when elements are known to be within a specific interval.

Use of an auxiliary array in Counting Sort to count the occurrences of each element.

The process of placing elements in their correct position using the count array in Counting Sort.

Maintenance of the original order in Counting Sort for elements with the same value.

Analysis of the time complexity of Counting Sort, which is linear, O(n).

Introduction to Radix Sort, another linear time algorithm suitable for sorting numbers with known digits.

Description of how Radix Sort works by sorting numbers digit by digit, starting from the least significant digit.

The importance of using a stable sorting algorithm for the intermediate steps in Radix Sort.

The process of sorting numbers by the most significant digit after sorting by the least significant in Radix Sort.

Analysis of the time complexity of Radix Sort, which depends on the number of digits and the intermediate sorting algorithm used.

Introduction to Bucket Sort, suitable for sorting randomly distributed numbers within a uniform range.

Explanation of how Bucket Sort divides the range into buckets and distributes elements accordingly.

The use of Insertion Sort on each bucket in Bucket Sort to sort individual elements within the buckets.

Analysis of the expected time complexity of Bucket Sort, which is linear if the distribution is uniform.

Conclusion of the lecture with a summary of the discussed linear time sorting algorithms.

Transcripts

play00:00

[Música]

play00:02

i

play00:05

[Música]

play00:15

hola pesos sean vendidos a nosa aula

play00:18

número de 'aces' de proyecto y análisis

play00:20

de algoritmos esta ola es sobre

play00:22

ordenanza o en tiempo lineal

play00:26

primero vamos a tener una introducción

play00:27

vamos a hablar un poco sobre varios

play00:30

algoritmos que son lineales entre las

play00:33

ordenación por contagio adic short y

play00:35

baquet soft

play00:38

vimos las aulas anteriores varios

play00:40

algoritmos de ordenación cualquier

play00:43

algoritmo basado en comparaciones debe

play00:45

efectuar omega de en el lobby de n

play00:47

comparaciones núcleo el caso y ya vimos

play00:50

que eso implica en que omer shatz sort

play00:53

son asintóticamente o chinos

play00:59

de mesa o la vamos a presentar algunos

play01:02

algoritmos que son lineales entre el iso

play01:06

algoritmo de ordenación por contagien ya

play01:08

dixon y baguette son estos algoritmos

play01:11

utilizan otras operaciones diferentes de

play01:13

operación de comparación para determinar

play01:15

la secuencia ordenada la verdad y

play01:17

ellison goya de algunas características

play01:18

los dados de entrada luego un límite

play01:21

inferior que omega de en el lobby de n

play01:24

no se aplica para el is

play01:30

pensamos un nuestro primero algoritmo

play01:32

lineal o algoritmo ordenación por

play01:34

contagio supone que sabemos que usa

play01:36

elementos que desechamos ordenadas son

play01:38

enteros un intervalo de cero acá

play01:42

en ese caso si sabemos sus valores los

play01:45

elementos de un osote store aunque que

play01:48

podemos hacer aunque podemos hacer es

play01:51

determinar para cada elemento si su

play01:53

vector un número de elementos menores

play01:55

que él y esa información podría ser

play01:59

usada depois para y cero elementos y

play02:02

directamente en un lugar ser tanto por

play02:05

ejemplo supone que posee

play02:08

sabe que elementos son menores

play02:11

que sis en todo haití ya sabe dónde

play02:14

colocar o si somos colocar en la

play02:16

posición 21

play02:20

el tronco que ha entrado algoritmo

play02:21

ordenación por contagio

play02:24

el ítem como entrada un vector a esa

play02:27

posición una posición n iv ac y de un

play02:29

vector b la posición u otra posición n

play02:33

con los elementos de a en orden

play02:36

creciente 60 empezamos aquí un ejemplo

play02:39

directora s de aquí un osote héctor a

play02:43

el ítem los elementos 4 3 4 3 10 36

play02:48

aunque aquí sabemos que los elementos

play02:50

están entre 0 y 4 seres humanos o cada 4

play02:55

en este caso y vemos que existen varios

play02:59

elementos repetidos por ejemplo 4 parece

play03:02

aquí aparece aquí ustedes aparece aquí

play03:05

aparece aquí y aparece aquí esto coloca

play03:08

sus números en diferente color apenas

play03:11

para indicar que la primera vez que

play03:13

aparece 3 está en blanco la segunda en

play03:15

amarelo la tercera en verme yo mismo

play03:18

pero 4 por ejemplo

play03:20

ese algoritmo de ordenación por contagio

play03:24

el uso un vector auxiliar se para contar

play03:27

cuántos números tengo de cada uno

play03:30

y para determinar la posición en que o

play03:33

elemento debe ser colocado tanto vamos a

play03:36

hacer un otro vector se ese vector se va

play03:39

a ser de tamaño

play03:42

5 la verdad es en ese caso porque va

play03:44

desde cero ática

play03:47

se atentó al ivai ter tamaño camisón

play03:50

porque aquí está nuestro algoritmo de

play03:53

ordenación por contagio

play03:55

el rcd es un vector a cantidad y

play03:58

elementos su gestor que n unca que sería

play04:02

l mensual desde un valor cero ante un

play04:05

valor acá y v que va a ser un vector con

play04:09

hielo y va a colocar sus elementos

play04:12

ordenados

play04:15

aquí tenemos unos ejemplo no sólo esto

play04:17

que queremos ordenar lo primero que

play04:19

vamos a hacer

play04:22

pegar un huso vector entonces de equihua

play04:24

no sólo esto se inicializar una línea

play04:28

unidos y somos inicializar ese vector

play04:30

con ceros porque es el vector va a

play04:33

servir para contar cuántas veces aparece

play04:35

4 cuántas veces apareció tres cuántas

play04:37

desaparece uno y así porque al ser la

play04:40

línea 3 a la línea 4 five hacer

play04:42

exactamente eso para contar cuántas

play04:44

veces aparece cada elemento en todo ese

play04:46

vector se va a ser usado en esas esas

play04:49

líneas aquí para servir como un contador

play04:53

por ejemplo aquí vamos a ir a apareció 4

play04:57

ok

play04:58

tengo un 4

play05:01

después avanzamos para siguiente

play05:04

posición de moscú trace tengo tengo un 3

play05:08

book contando cuántas veces aparece

play05:10

vamos para posición 3

play05:12

tengo un valor 4 y tengo dos elementos 4

play05:16

fue para sinchi posición tengo más un

play05:18

300 ahora tengo dos elementos 3

play05:22

tengo un elemento próximo ok tenga un

play05:25

elemento

play05:29

el próximo año más un elemento con valor

play05:32

3 en todas ahora tengo tres elementos 3

play05:38

en tomate aquí hacia la línea 4 sabemos

play05:41

que se ve y contiene un número de

play05:44

elementos de entrada y huawei

play05:48

después lo que vamos a hacer vamos a

play05:50

acumular sus números en cee y de esa

play05:53

forma en cd y vamos tener un número de

play05:56

elementos de entrada que son menores o

play05:58

iguales que está tomamos a acumular ese

play06:02

vector sea aquí eso va a hacer falta una

play06:04

línea 5 y 6 exactamente estamos

play06:06

acumulando los valores aquí botero la

play06:09

posición 1 tengo un elemento menor a 0

play06:14

tengo dos elementos menores iguales a 1

play06:21

después tenemos dos elementos menores

play06:23

iguales a 2

play06:25

cinco elementos menores iguales a tres y

play06:28

seis elementos menores iguales a cuatro

play06:30

simplemente estamos haciendo acumular

play06:32

los valores aquí una vez se hizo ahora

play06:36

ya sabemos oye colocar cada uno de los

play06:40

elementos no vectores aída que un vector

play06:43

b

play06:44

comenzamos de final si sabes qué

play06:48

comenzamos aquí 23 sabemos

play06:52

ahora sabemos dónde colocar ese elemento

play06:55

3 como que sabemos si se halla y sabe

play06:58

que existen 5 elementos menores iguales

play07:02

a trace se al tanto debo colocar ese 3

play07:06

la posición 5

play07:09

que no posee un 5 ok

play07:12

y después ahora tenemos vamos a

play07:15

disminuir la cantidad de elementos

play07:17

menores o iguales a 3 a core 4

play07:21

y continuamos ahora vamos por la

play07:23

posición original vector 6

play07:26

vamos aquí la posición 6 aparece un 0

play07:30

hoy equivoco lo conocerá una posición

play07:33

vamos para 5 ago 25

play07:38

la posición 5 o el elemento 18 que fue

play07:41

colocar o elemento 1 o joaquino vector

play07:44

se debe estar la posición 2 o colocar

play07:47

aquí en la posición 2 y continuamos

play07:50

ahora un

play07:52

[Música]

play07:53

trace oye que hubo colocar un elemento

play07:56

38 aquí en esa posición en cuatro

play07:59

elementos menores iguales a tres el

play08:01

tiempo coloca una posición 4

play08:05

el hombre en que esos valores en cáncer

play08:07

disminuyó sabores se va a mudar para 3

play08:11

y ahí continuamos coleando en un sector

play08:14

inicial vamos aquí nos vemos su 411 cómo

play08:18

colocar ese 4 óleo aquí el líder está en

play08:20

la posición fecha ok

play08:22

aquí

play08:24

oye que vamos a colocar ahora o elemento

play08:28

un elemento que está en la posición 23

play08:31

vamos aquí o trace el líder está en la

play08:34

posición 3 de aquí

play08:38

y finalmente 11 que vamos a colocar

play08:42

4 vayamos aquí 4 se realizan a posición

play08:46

6 colocamos el y la posición 6 bryant

play08:49

que no final tenemos unos o vector

play08:51

ordenado

play08:52

una cosa importante de ver también qué

play08:57

la orden original fue mantenida primero

play09:01

estado 3

play09:02

de color blanco 3 de color amarillo y

play09:04

después 13 korver medio blanco amarillo

play09:07

medio

play09:11

o algoritmo estado porque los números

play09:14

con un mismo valor aparece en el vector

play09:16

de salida en la misma orden en que

play09:17

aparece en el vector de entrada una

play09:20

desventaja de ese algoritmo de kelly

play09:22

precisa de un otro vector no si no se

play09:24

soldaron entrada a marcel impreciso de

play09:27

un vector de un vector de para mostrar a

play09:30

seguir en todo el noa emplace

play09:36

ahora analicemos cualquier consumo de

play09:39

tiempo de algoritmo línea uy línea 2 en

play09:41

fort que va desde cero ateca en todo el

play09:43

jet eta de acá la línea 3 y 4 byte de

play09:47

una tiene en tonelli

play09:50

de adn a línea 5 y 6 va de una teca

play09:54

entonces de tádic a la línea 68 y no vi

play09:58

el ifai desde en atv entonces

play10:04

fácil la suma de todos él es verdad que

play10:07

está de más ser

play10:12

cuando usamos su algoritmo de ordenación

play10:15

por por contagio cuando cae igual

play10:18

adn en este caso consumo de tiempo de

play10:22

ordenación por contagio va a ser de adn

play10:26

que en todo aquí sí forcall igual ordene

play10:29

acción sustituir por n va a darte tarde

play10:36

pasemos para un uso segundo algoritmo de

play10:38

ordenación línea exterior adic short

play10:42

ahora tenemos una u otra característica

play10:44

sabemos una otra característica no sus

play10:47

elementos supone que sabemos que usa

play10:49

elementos que decíamos ordenar ten de

play10:52

dígitos

play10:54

si sabemos que tendré dígitos ahora y va

play10:57

a ser ordenar en función de seis dígitos

play11:00

usar esa información

play11:02

como que vais a efecto hizo vamos a

play11:04

ordenar en función dos dígitos

play11:06

considerando uno de cada vez cosas

play11:08

comenzando pelo dígito menos

play11:11

significativo

play11:12

de ese modo

play11:15

si vamos comenzar un dígito menos

play11:17

significativas en kuwait el que pase va

play11:19

a ser apenas de pasajes de la lista de

play11:23

elementos para poder ordenar esa lista

play11:28

dada entonces ya hemos aquí un ejemplo

play11:31

supone que bo set en un siguiente

play11:33

elementos todos esos de aquí 491 348 736

play11:39

etcétera etcétera cuantos dígitos estén

play11:42

todos esos números el existen tres

play11:45

dígitos en cómo llamar a cantidad

play11:47

dígitos de chihuahua 3 cuántos números

play11:50

del peñón esa lista

play11:52

enseñó oit o números en eua white aunque

play11:56

que vais fasero algoritmo haddix short

play11:58

el barrio ya los dígitos comenzando pelo

play12:01

dígito menos significativo en trabajamos

play12:04

un dígito menos significativo de qué

play12:07

vamos a hacer vamos a ordenar por ese

play12:08

dígito menos significativo entonces está

play12:11

primero primero va a estar s después va

play12:14

a estar ese después ese

play12:17

después es de aquí después sus tres

play12:20

hijos que vamos a ver aquí son primero 1

play12:23

2 3 5 6 y 8 ya no son para un dígito

play12:27

menos significativo una vez que fue

play12:30

feita es ordenación hago lo llamamos

play12:33

para un segundo dígito menos

play12:36

significativo que se ayude un medio ahí

play12:38

vamos a hacer un mes no vamos a comenzar

play12:40

a ordenar los elementos de acuerdo con

play12:42

ese dígito por él vamos mantener a orden

play12:46

inicial que fue fecha antes aquí sin

play12:49

perder esa orden 70 vamos a ver aquí

play12:53

tenemos a xente vai ter coloca primero

play12:55

ese 1

play12:59

y después no tenemos dos después tenemos

play13:03

su trace lo que primero vamos a colocar

play13:05

ese 3 de aquí porque estaba sin nada una

play13:09

ordenación anterior y después vamos a

play13:11

colocar ese elemento que tenga ese

play13:13

dígito 3 número que desde aquí

play13:16

y así por ians después eeuu 4 714 y un

play13:22

resultado va a ser este de aquí

play13:26

ok

play13:30

y ahí continuamos ahora vamos a hacer un

play13:32

mismo con un 3º dígito vamos a ordenar

play13:36

pero tercero dígito y enojo mantén la

play13:40

ordenación anterior talento que dígitos

play13:43

tenemos aquí tenemos un 2 tanto primero

play13:45

va a estar ese dígito ese es el elemento

play13:48

que tengo primero dígito sería ese

play13:51

primero va a estar los 111 después va a

play13:55

estar

play13:56

[Música]

play14:00

231 de puesto que tengo dígito 3 que

play14:04

sería este de aquí después que tengo un

play14:06

dígito 4 tendones que están visitó 4 el

play14:09

embrión que está gente que mantenga

play14:10

orden original se halla primero tienen

play14:12

que decir 1 491 y después o 492 eso de

play14:17

ahí importante precisamos para facer esa

play14:20

ordenación de un algoritmo estable tanto

play14:23

para facer ordenación por distintos

play14:25

préstamos de un algoritmo estado y

play14:26

acabamos de ver en esa misma aula qué

play14:30

algoritmo de ordenación por contagio en

play14:32

un algoritmo estado entró podríamos usar

play14:34

el zoom junto con un algoritmo

play14:37

secundario para facer la ordenación por

play14:39

handy short como resultado final va a

play14:42

ser este de aquí es en que usa elementos

play14:44

mágicamente fueron ordenados

play14:48

aquí está un peso del código de

play14:50

algoritmo haddix ortelli recibe un

play14:52

vector a la cantidad ya elemento cn a

play14:55

cantidad 7 dígitos de todos esos

play14:58

elementos eleva a un dígito menos

play15:00

significativo a tu dígito más

play15:02

significativo y vaya ordenando el vector

play15:05

pelo dígito y

play15:11

importante fallar si no hubo que ese

play15:14

algoritmo usado aquí en la ordenación

play15:15

debe ser un algoritmo estado el consumo

play15:18

de tiempo de ese algoritmo va a depender

play15:21

del consumo de tiempo de ese algoritmo

play15:23

intermediario que usado en la línea 2

play15:28

si cada dígito está en intervalo de 0

play15:30

acá menos 1 y acá no es muy grande

play15:34

podemos usar ordenación por contagio por

play15:36

ejemplo si tenemos un números que son

play15:39

decimales agentes y sabes que los

play15:41

dígitos van de 0 en off y no podemos

play15:43

usar la ordenación por contagio en este

play15:46

caso es un constante

play15:49

sería days ok si fuésemos en todo

play15:53

análisis y algoritmo considerando que

play15:54

fue usado o algoritmo de ordenación por

play15:56

contagio para usted la línea 1 by de una

play16:00

tv por tanto el dt de la línea 2 el bay

play16:05

usar un algoritmo de ordenación

play16:06

secundario y él está dentro de la zone

play16:09

entonces por estar dentro de un lazo de

play16:12

lazo de línea 1 en la etiqueta de veces

play16:15

consumo de tiempo lo algoritmo

play16:17

secundario que en ese caso si fuese

play16:19

ordenación por contagio va a ser n más

play16:22

acá fue haciendo asoma para usted que

play16:25

nos algoritmo teta de de veces en el más

play16:29

acá

play16:31

si de una constante y qaeda orden n

play16:34

entra un handy short en línea

play16:37

y pasemos ahora no su último algoritmo

play16:39

baquet sort ahora vamos a ver una u otra

play16:42

característica de nuestros elementos

play16:44

supone que sabemos que los elementos que

play16:46

decíamos ordenar fueron generados de

play16:48

manera aleatoria de forma uniforme no

play16:51

intervalo y el issste a un intervalo de

play16:53

0 a 1 la idea básica de ese algoritmo el

play16:56

primero dividir un intervalo que va de 0

play16:59

a 1 en n baquets después distribuir un n

play17:03

números entre s n baquets y después

play17:06

ordenar los números en cada uno de eses

play17:09

baquets usando ordenación por inserción

play17:11

1 final de todo ese proceso vamos tener

play17:14

todos los elementos ordenados

play17:18

aquí tenemos un ejemplo verán que todos

play17:21

sus números están entre 0 y 1 y tenemos

play17:23

seis elementos lo primero que vamos a

play17:26

hacer es crear n baquets que son days en

play17:30

ese caso entrante no deis baquet cada

play17:32

vázquez baytelman lista ligada

play17:35

11 y vamos a estar dos elementos por

play17:38

ejemplo aquí no primero vamos a estar

play17:39

todos los elementos que están entre 0 y

play17:41

0 vírgula 11 segundos van a estar todos

play17:44

los elementos que están entre 0 vincula

play17:46

10 vinculados y así por ians tanto

play17:49

comenzamos a ver unos elementos y vamos

play17:52

colocar el is aquí en cada uno 2 baquets

play17:55

lo primero va a estar si logramos aquí 1

play17:58

055 faisanes selva que está aquí

play18:00

continuamos con 1 033 bcn se va que 2

play18:03

042 va a estar los bucks 4 después nos

play18:08

va que 25 y después su 0 39 va a estar

play18:12

en ese paquete 1 073 están ese 10 11

play18:17

están en 1 019 va a estar en ese paquete

play18:21

0 65 desde aquí 031 aquí y 0 22 aquí ok

play18:27

entonces hemos en este caso days baquets

play18:30

cada un tema lista de elementos secreto

play18:34

y hago lo que vamos a hacer

play18:36

en cada una de esas listas aplicar

play18:38

ordenación princesa aplicamos ordenación

play18:41

princesa aquí está ordenado aquí son

play18:43

elementos ordenado no decide aquí

play18:45

precisamos ordenar que tengan elementos

play18:47

ordenada etcétera etcétera si aplicamos

play18:49

ordenación por interesa tenemos como

play18:51

resultado esto de aquí

play18:55

ok y por último lo único que precisamos

play18:58

hacer es simplemente por todos

play19:00

estos elementos y ya tenemos unos a

play19:02

lista ordenada dejan aquí 0 círculo 11

play19:05

019 y después 0 22 se lo vincula 33-31

play19:09

disculpen 0 circula 33 0 39 42 55 65 73

play19:14

está ordenado

play19:17

análisis uva que son es un poco más

play19:20

complicada porque la va a depender la

play19:22

distribución de los números nos baquets

play19:24

la gente vio que los números son

play19:26

distribuidos de manera uniforme ser si

play19:31

consideramos hizo los números son

play19:33

distribuidos de manera uniforme he

play19:36

esperado que un número de elementos en

play19:38

cada uno de ses barques ella trata de un

play19:41

pose ya que en cada paquete exista plena

play19:43

su mundo es ella más constante

play19:48

una constante y de la misma cantidad y

play19:51

constante de elementos

play19:53

luego el consumo de tiempo esperado por

play19:55

ordenar cada baqueta también va a ser

play19:58

detalle

play20:01

y si consideramos se hizo entonces como

play20:04

tenemos n baquets un consumo de té budva

play20:07

que solvay ser de tves cn queda de eta

play20:12

de un algoritmo lineal

play20:15

con esa fui a nosa aula número de este

play20:19

análisis del proyecto y análisis de

play20:21

algoritmos sobre ordenación lineal

play20:23

espero que ustedes tengan gusta

play20:26

[Música]

play20:44

2

play20:45

[Música]

play20:51

ah

play20:54

[Música]

play21:00

ah

play21:03

[Música]

Rate This

5.0 / 5 (0 votes)

関連タグ
Sorting AlgorithmsCounting SortRadix SortBucket SortLinear TimeAlgorithm AnalysisEfficiency StudyData StructuresComputer ScienceProgramming TechniquesEducational Content
英語で要約が必要ですか?