one2free
BAN USER- 0of 0 votes
AnswersWhat is name hiding?
- one2free| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer C - 0of 0 votes
AnswerWrite a smart_ptr class
- one2free| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Coding
1) map: no need to have a hash function, don't need to handle collision, O (log N) insert and lookup, insert key/data in sorted order. If you need to find a max/min element, use map instead of hash table.
hash table: transforms a key into position within a table. O(1) lookup and insert in most cases, doesn't insert hashed key/data in sorted order
2) You need a good hash function (i.e. % prime #) to ensure the hash values are uniformly distributed. If collision occurs, you use separate chaining method (Good for full table), which is a linked list that chains element in the same slot, or use the probing method, which increases the position by some amount until an empty position is found (good for sparse table)
When the # of elements to table size ratio is greater than a threshold, then the hash table needs to be resized. You need to transfer the entries from old table to new table by recomputing their positions using the new hash function
3) Use a map, which also stores key/data pair, but doesn't need to statically allocate a huge hash table with many empty slots
Template is good if you want to use your container for multiple class
- one2free December 06, 2007template <class T>
class List{
};
class contact{
};
list<contact> agenda;
Inheritance is good when you want to restrict your container to store only this class of object
class Agenda : public List <contact>