Tuesday, January 7, 2014

Interview: Java along with Algorithm

Few days back, I faced a telephonic interview with a Product based company in Gurgaon. It was quite a quick interview round for me. Here I am mentioning the questions asked by interviewer.


So Linked list provides following two advantages over arrays
1)         Dynamic size
2)         Ease of insertion/deletion
Linked lists have following drawbacks:
1)         Random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked lists.
2)         Extra memory space for a pointer is required with each element of the list.
3)         Arrays have better cache locality that can make a pretty big difference in performance. 

Q3. Suggest the best possible data structure in these 2 conditions?
A. DS must have add, delete, search operations, where search is most used functions of the DS?
DS based on hashing technique.
B. DS must have add, delete, rangeSearch operations, where search is most used functions of the DS?
DS based on Tree technique.

Q4. What do you mean by Hashing?
Q5. What are the different algorithms to resolve hash collision?
Q6. Is it possible to call static method within a constructor?
Q7. What is synchronization?
Q8. What are the different ways of implementing Threads?

Q9. What is the difference between creating threads by implementing runnable Interface or extending thread class implementation?
Implements Runnable is the preferred way to do it, IMO. You're not really specializing the thread's behaviour. You're just giving it something to run. That means composition is the philosophically "purer" way to go.

In practical terms, it means you can implement Runnable and extend from another class as well.

Q10. What is the difference between Callable and Runnable interfaces?
The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.

Q11. What is garbage collection?
Q12. What is the difference between notify and notifyAll()?

Q13. What are practical scenarios where notify and notifyAll work?

No comments:

Post a Comment