worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%." Donald Knuth Problems with early optimization
1. You can't tell where a program is going to spend its time. Don’t try a speed hack until you've proven that's where the bottleneck is. Rule 2. Measure. Don't tune for speed until you've measured. Rule 3. Fancy algorithms are slow when n is small, and n is usually small. Only use fancy algorithms when you are sure n is big.
4. Fancy algorithms are buggier than simple ones, and they're much harder to implement. Use simple algorithms as well as simple data structures. Rule 5. Data structures, not algorithms, are central to programming. Algorithms are self-evident when you choose the right data structure.
to know the size beforehand Cons: ➔ Costly random access ➔ Requires more space than arrays Used in: Implementation of stacks and queues, also buckets from hash maps. Linked List
consumed than a linked list Cons: ➔ Slow inserts and deletes (memcpy and memmove are linear) ➔ Memory allocation on heap is slow Used in: Python lists, Golang slices, Clojure vectors, Rust vectors... Vector
➔ Good when order doesn’t matter (random access) Cons: ➔ Becomes inefficient with a high number of collisions ➔ Inserts can be slow if reallocation is needed Used in: Database indexing, caching, sets... Hash Map
Good for searching Cons: ➔ Becomes inefficient when unbalanced ➔ Too much memory copying when the tree is tall Used in: Heaps, sorting, encoding... Binary Tree
check set membership Cons: ➔ Too many false positives when the bitarray is small Used in: Web crawlers, weak password checks, malicious URLs on chrome Bloom Filters
is close to a vector (depending on branching factor) ➔ Efficient space complexity Cons: ➔ Updates require copying Used in: Clojure’s immutable data structures, Immutable.js, Pyrsistent... Persistent Vector