If I have a javascript array1 containing 10 000 items
what is the running time of:
var array2=new array();
array2.push(array1);
and what is the running time of
var object={};
object['array2']=array1;
are both O(n) ? thanks for explanation.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They should both be amortized O(1) operations.
This (obviously) depends on the browser’s JS implementation, but any sane one should use an arraylist-like implentation for
[]s, and a hashtable-like{}. Arraylists and hashtables both have amortized O(1)insertruntime.