Ir al contenido

Recurso · Guía o artículo

Counting Sort

El counting sort para claves enteras pequeñas, incluido por qué esquiva la cota inferior de los ordenamientos por comparación y cómo se relaciona con el radix sort y el bucket sort.

Revisado

Abrir el original: Counting Sort (abre el sitio original en una pestaña nueva)

Añadir a una hoja de ruta

Guarda este recurso junto a una hoja de ruta que sigues. Aparece como un recurso extra tuyo; los pasos de la hoja de ruta no cambian y no cuenta para tus pasos registrados.

Contenido de la fuente: inglés

In computer science, counting sort is an algorithm for sorting a collection of objects according to keys that are small integers; that is, it is an integer sorting algorithm. It operates by counting the number of objects that have each distinct key value, and using arithmetic on those counts to determine the positions of each key value in the output sequence. Its running time is linear in the number of items and the difference between the maximum and minimum key values, so it is only suitable for direct use in situations where the variation in keys is not significantly greater than the number of items. However, it is often used as a subroutine in another sorting algorithm, radix sort, that can handle larger keys more efficiently. Because counting sort uses key values as indexes into an array, it is not a comparison sort, and the Ω(n log n) lower bound for comparison sorting does not apply to it. Bucket sort may be used for many of the same tasks as counting sort, with a similar time analysis; however, compared to counting sort, bucket sort requires linked lists, dynamic arrays or a large amount of preallocated memory to hold the sets of items within each bucket, whereas counting…

Resumen de PrepKit

El equipo editorial de PrepKit redactó y revisó este resumen a partir del repositorio de origen. No es texto del propio recurso.

Adecuado para
La fuente no indica un nivel
Formato
Referencia

Qué cubre

  • Por qué no es un ordenamiento por comparación y cuándo el rango de claves lo hace adecuado.
  • Tres pasos: contar apariciones, construir los recuentos acumulados y colocar los elementos en el array de salida.
  • Tabla de complejidad: n + r de tiempo y memoria, estable, siendo r el número más grande.

Cómo usarlo

Consejo de estudio de PrepKit, no una afirmación de la fuente.

Ordena a mano [4, 2, 2, 8, 3, 3, 1] pasando por los tres pasos, luego prográmalo manteniéndolo estable.

Alcance y limitaciones

Las ilustraciones de los pasos son imágenes alojadas en un blog externo. No trata los números negativos ni incluye ejercicios. Enlaza una versión en portugués.

Acceso y formato

README gratuito en inglés en GitHub, en trekhleb/javascript-algorithms (licencia MIT).

Revisado por PrepKit el 2 oct 2026. Commit de la fuente del recurso: 85293e3e2b88

Evidencias de este resumen
  • src/algorithms/sorting/counting-sort/README.md

Páginas que lo incluyen

Recibe el boletín de PrepKit

Opcional. No lo necesitas para usar PrepKit.

Cómo tratamos tu correo