Sunday 7 February 2016

Some technical interview questions

Here are some technical interview questions asked now day's.

1.  Which is faster, heap or stack?
Solution : The stack is faster because the access pattern makes it trivial to allocate and deallocate memory from it (a pointer/integer is simply incremented or decremented), while the heap has much more complex bookkeeping involved in an allocation or free. Also, each byte in the stack tends to be reused very frequently which means it tends to be mapped to the processor's cache, making it very fast. Another performance hit for the heap is that the heap, being mostly a global resource, typically has to be multi-threading safe, i.e. each allocation and deallocation needs to be - typically - synchronized with "all" other heap accesses in the program.


2. Which data structure is used in recursion calls? And why?
Solution : Well if you think about it, then you might be wondering that there should be some place where those function calls are stored. And there is some order in which they are called, right...
Yes, the answer is stack data structure. Now think why not queue.