Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

287
Visualizações
Javascript Array: what is a Big O of performing sort and then map right after on it?
arr.sort((a, b) => a - b).map(num => num ** 2);

What would be a Big O of the following operation?

As I understand Big O of imbedded sort function in JS is O(Nlog(N)) and Big O of map is O(N), therefore Big O is O(Nlog(N))?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The complexity of your function f, for arr of size n. We'll assume:

arr.sort ∈ O(nlogn)
arr.map ∈ O(n),

We can just sum these terms, since these operations are done serially (one after the other. Thus,

f(n) ∈ O(nlogn + n)

Note that the nlogn term will grow slowly, but eventually:

as n -> infinity, nlogn >> n
thus, as n -> infinity, nlogn + n -> nlogn

So we can simplify to just O(nlogn) for sufficiently large n.

All of this is to say, yep, you got it.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda