Counting Sort optimization

Abierto
#498 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
30/100
Tipo de issue
Refactorización
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
javascript
Área
data

Línea de trabajo

Start by locating the Counting Sort implementation and comparing it with the linked TypeScript example. Before changing it, establish whether the proposed one-pass lookup optimization preserves sorting behavior and define tests or measurements that demonstrate correctness and the claimed memory and performance improvement.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Hi devs!
On the very beginning I want to appreciate your work here, I think it is fantastic and gives a lot of addition to developers knowledge!

But this ticket I want to open to point potential optimization of Counting Sort algorithm.

In the implementation there are is loop by all array elements to find smallest and biggest.
Next step is creating counting array of size dependent on smallest and biggest.
And in next step there is one more iteration by all elements to set up counting array.

I am wondering if there could be optimization applied and make all of those in just 1 iteration, moreover there could be used lookup instead of array.

Lets consider this example of array to be sorted:
const arrayToSort = [1, 1, 10000, 1, 1, 10000, 10000, 1, 1];
When switched to lookup object instead of array we will have small object:
{"1": 6, "10000": 3}
When using array it will be bigger:
[0, 6, 0, 0, 0, 0, ....(a lot of zeros), 10000]

So finally we could find biggest, smallest and set lookup values in 1 iteration and having lesser memory used.

I prepared example of that:
*The next difference is that I am preparing algorithm which is mutating original array, but it can be applied here too:
example

Please reply if this make sense to you, I would be more than happy to make MR to your great work!

Lenguaje dominante
JavaScript
Estrellas
197k
Forks
31k
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de trekhleb/javascript-algorithms

Todos los issues de trekhleb/javascript-algorithms

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.