Monday 17 September 2012

DS Interview Questions-1



11. Can we apply binary search algorithm to a sorted linked list, why?
Ans: No we cannot apply binary search algorithm to a sorted linked list, since there is no way of indexing the middle element in the list. This is the drawback in using linked list as a data structure.

12. What do you mean by free pool?
Ans: Pool is a list consisting of unused memory cells which has its own pointer.

13. What do you mean by garbage collection?
Ans: It is a technique in which the operating system periodically collects all the deleted space onto the free storage list.It takes place when there is minimum amount of space left in storage list or when CPU is ideal.
The alternate method to this is to immediately reinsert the space into free storage list which is time consuming.

14. What do you mean by overflow and underflow?
Ans: When new data is to be inserted into the data structure but there is no available space i.e. free storage list is empty this situation is called overflow. When we want to delete data from a data structure that is empty this situation is called underflow.
15. What are the disadvantages array implementations of linked list?
Ans:
i) The no of nodes needed can’t be predicted when the program is written.
ii) The no of nodes declared must remain allocated throughout its execution

16. What is a queue?
Ans: A queue is an ordered collection of items from which items may be deleted at one end (front end) and items inserted at the other end (rear end). It obeys FIFO rule there is no limit to the number of elements a queue contains.

17. What is a priority queue?
Ans: The priority queue is a data structure in which the intrinsic ordering of the elements (numeric or alphabetic)
Determines the result of its basic operation. It is of two types
i) Ascending priority queue- Here smallest item can be removed (insertion is arbitrary)
ii) Descending priority queue- Here largest item can be removed (insertion is arbitrary)

18. What are the disadvantages of sequential storage?
Ans:
i) Fixed amount of storage remains allocated to the data structure even if it contains less element.
ii) No more than fixed amount of storage is allocated causing overflow

19. What are the disadvantages of representing a stack or queue by a linked list?
Ans:
i) A node in a linked list (info and next field) occupies more storage than a corresponding element in an array.
ii) Additional time spent in managing the available list.

20. What is dangling pointer and how to avoid it?
Ans: After a call to free(p) makes a subsequent reference to *p illegal, i.e. though the storage to p is freed but the value of p(address) remain unchanged .so the object at that address may be used as the value of *p (i.e. there is no way to detect the illegality). Here p is called dangling pointer.
To avoid this it is better to set p to NULL after executing free(p). The null pointer value doesn’t reference a storage location it is a pointer that doesn’t point to anything.

No comments:

Post a Comment