ArrayList vs LinkedList from memory allocation perspective

LinkedList might allocate fewer entries, but those entries are astronomically more expensive than they’d be for ArrayList — enough that even the worst-case ArrayList is cheaper as far as memory is concerned. (FYI, I think you’ve got it wrong; ArrayList grows by 1.5x when it’s full, not 2x.) See e.g. https://github.com/DimitrisAndreou/memory-measurer/blob/master/ElementCostInDataStructures.txt : LinkedList consumes 24 … Read more

How to apply binary search O(log n) on a sorted linked list?

It is certainly not possible with a plain singly-linked list. Sketch proof: to examine the last node of a singly-linked list, we must perform n-1 operations of following a “next” pointer [proof by induction on the fact that there is only one reference to the k+1th node, and it is in the kth node, and … Read more