O(klogk) time algorithm to find kth smallest element from a binary heap

Well, your intuition was right that we need extra data structure to achieve O(klogk) because if we simply perform operations on the original heap, the term logn will remain in the resulting complexity. Guessing from the targeted complexity O(klogk), I feel like creating and maintaining a heap of size k to help me achieve the … Read more

Why not use hashing/hash tables for everything?

Hash tables, on average, do have excellent time complexity for insertion, retrieval, and deletion. BUT: Big-O complexity isn’t everything. The constant factor is also very important. You could use hashtables in place of arrays, with the array indexes as hash keys. In either case, the time complexity of retrieving an item is O(1). But the … Read more

Why do we use linear probing in hash tables when there is separate chaining linked with lists?

I’m surprised that you saw chained hashing to be faster than linear probing – in practice, linear probing is typically significantly faster than chaining. This is primarily due to locality of reference, since the accesses performed in linear probing tend to be closer in memory than the accesses performed in chained hashing. There are other … Read more

tech