5 ms·
I think there are several reasons: 1. Name array strongly implies that it has an underlying continuous memory location associated with it. All of modern script
by TrainedMonkey 12y ago
I think there are several reasons:
1. Name array strongly implies that it has an underlying continuous memory location associated with it. All of modern scripting languages have some form of dictionary, map, set, or hashtable which is implemented using insert/update friendly approach.
1a. Typical workload for array is to iterate over it doing something with each element, B-Tree is strictly worse in iterating over all elements compared to static array.
2. Most instantiated dynamic arrays rarely perform deletes. Most common operation that could change size of array is push_back, and amortized cost for inserts is probably way less than chasing pointers in B-Tree.
3. B-Trees were created and optimized for HDD performance. With current SSD and memory trends, there are simply better data structures to use.
4. Pointer chasing got a lot more expensive relative to continuous memory scanning. This is mostly due to majority of memory performance increases coming from increased throughput as opposed to lower latency.
This does not mean B-Trees are bad, in fact they are still heavily utilized in databases because they scale extraordinarily well with data size. They are commonly used for indexes because membership testing (single value lookup) and range lookups are O(1), and updates/deletes are generally very fast as well.
- crucini 12y agoI think this is a really good answer. However I slightly differ on #1. Python calls the default sequence container a list. If you took that literally, it implies O(1) inserts.