kakitayuri
BAN USER1. HashMap is Java's version of a Hash Table based on the Map interface. It maps keys to values using a hash function.
2. Array list is an array with dynamic resizing and shifting, while a linked list is a set of nodes linked together. Arrays are great for accessing data an any index in constant time, but inserts require O(n-index) time, so inserting to the front of an ArrayList is linear time for EACH insert, while it's constant time in a LinkedList. However, accessing data near the middle of a LinkedList takes O(n) time because we have to travel through the nodes to get to it.
3. To my knowledge, collisions are handled internally when you put an item into a HashMap. One issue with HashMap that you won't get with a linking HashTable is that you cannot put a key to map to two different values. For example if you had a key<string> "John Smith" and you wanted 4 different phone number values for it, you could not do that with a HashMap (You can, however, have multiple keys map to a single value.)
4. Runtime Polymorphism is just what it sounds like - Polymorphism that occurs at runtime. So polymorphism basically deals with inheritance. Suppose we have Class Employee, and Subclass Lawyer. Using polymorphism we'd have:
Class Employee {
// Some stuff
}
Class Lawyer extends Employee {
// Some stuff
}
So we can say:
Employee lawMan = new Lawyer(); //right?
Doing this at runtime simply could go many ways. An example would be a method that builds Employees for you taking a string parameter, and something like:
//pseudo code
Some method (String str)
Employee emp;
if (str.equals("Lawyer"))
emp = new Lawyer();
Something like that would happen at runtime.
So, there's plenty of explanation on how/why to do a QuickSort, but in my opinion, something MAJOR is left out here, which is to *Ask your interviewer questions before answering!* QuickSort can quickly become the wrong answer with some detail.
- kakitayuri March 19, 20141. Is the list sorted? Probably not, but worst case you get "no" and best case, you're applauded for being thorough.
2. Can I sort the list? And if not, do I have the memory to copy then sort the list? A no here means that again QuickSort is out.
3. How big is the list? If you've got an int array list of a constant size 5, QuickSort is sort of using the broad sword when the butter knife will do.
All a bit pedantic here perhaps, but keeping this mindset is vital.