I know what is the difference between unshift()
and push()
methods in JavaScript, but I'm wondering what is the difference in time complexity?
I suppose for push()
method is O(1) because you're just adding an item to the end of array, but I'm not sure for unshift()
method, because, I suppose you must "move" all the other existing elements forward and I suppose that is O(log n) or O(n)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…