Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

277
Vistas
What is the Space complexity of storing a string in JavaScript?

Are storing strings O(1) space? I am really confused about this since a mix of people saying its O(1) and O(n) at the same time.... Could someone help me on this one? I really need it for practicing for my interviews. Thank you!!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

O(1) would make sense only for complexity and not space since the size of the memory allocated for a string depends on how big it is.

As for complexity:

Depending on how the language implements it (stack or heap) it would be O(1) for stack or non-deterministic for heap, because heap allocation is handled by the OS (but as a rule of thumb, its generally O(1) if the strings are not huge).

O(n) would be for space:

When you store a string, basically what you are doing is storing an array of characters.

This would be the size of the string, since it grows linearly with the size of the string (Every character = 1 byte in a ASCII(8-bit) string).

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda