java - ArrayList vs. Queue time complexity -
if trying remove first element (index 0), more time efficient list.remove(0) <- removes index 0 or use queue , queue.dequeue(). know delete arraylist o(n), still hold true if provide index remove from? new java , algorithms, please bear me if dumb question
yes, arraylist fast adding , removing close end. takes o(n) time add or remove @ or near beginning if provide in index.
if need queue, use arraydeque. it's fast @ both ends.
Comments
Post a Comment