More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. The impact of both cases (fixed hashcode or random hashcode for keys) will have same result and that is "unexpected behavior". The very basic need of hashcode in HashMap is to identify the bucket location where to put the key-value pair, and from where it has to be retrieved.
If the hashcode of key object changes every time, the exact location of key-value pair will be calculated different, every time. This way, one object stored in HashMap will be lost forever and there will be very minimum possibility to get it back from map.
For this same reason, key are suggested to be immutable, so that they return a unique and same hashcode each time requested on same key object.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Message queues implement an asynchronous communication pattern between two or more processes/threads whereby the sending and receiving party do not need to interact with the message queue at the same time. Messages placed onto the queue are stored until the recipient retrieves them. Message queues have implicit or explicit limits on the size of data that may be transmitted in a single message and the number of messages that may remain outstanding on the queue.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Work with two pointers on the linked list - a slow pointer (increments by one node) and a fast pointer (increments by two nodes). If both of these pointers meet at the same node, then there is a cycle in the linked list. Otherwise, no cycle.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Array needs continuous memory location because it need to provide random access of it's elements which is not required for Linked List.
Array index acts as an offset from the base address and hence can retrieve the respective element using the expression Base Address + ( Index * Element Size ). This expression could only hold true if the elements are in continuous memory location.
Help us improve. Please let us know the company, where you were asked this question :
Ans. The array index starts with 0 because program locates an element using the expression ( BaseAddress + ( Index * size of array Element ), where index is used as an offset. As the starting address is actually the address of first element, the index of first element is used as 0 and so on.
Help us improve. Please let us know the company, where you were asked this question :
Ans. pop method pulls the top element from the stack and then move the top to the next element whereas peek only get the top element but doesn't move the top.
Help us improve. Please let us know the company, where you were asked this question :
Q29. Write a program to sort a stack in ascending order You should not make any assumptions about how the stack is implemented The following are the only functions that should be used to write this program: push | pop | peek | isEmpty