Data Structure Interview Questions and Answers - 2

9. What is the primary advantage of a linked list?

Answer:

Linked list is a dynamic data structure so it can grow and shrink at runtime by allocating and deallocating memory. So there is no need to give initial size of linked list. As size of linked list can increase or decrease at run time so there is no memory wastage.

Data structures such as stack and queues can be easily implemented using linked list.

10. What is the difference between a PUSH and a POP?

Answer:

PUSH basically is an operation to insert data into stack and POP is an operation to remove and read data from stack.

11. What is a linear search?

Answer:

In linear search method, each element in the list is checked and compared against the target key. The process is repeated until found or if the end of the file has been reached. Time taken to search elements keeps increasing as the number of elements is increased.

12. What is the advantage of the heap over a stack?

Answer:

The heap is more flexible than the stack. That is because memory space for the heap can be dynamically allocated and de-allocated as needed. However, the memory of the heap can at times be slower when compared to that stack.

13. What is recursive algorithm?

Answer:

Recursive algorithm targets a problem by dividing it into smaller, manageable sub-problems. The output of one recursion after processing one sub-problem becomes the input to the next recursive process.

14. What is binary search?

Answer:

A binary search works only on sorted lists or arrays. A binary search is a quick and efficient method of finding a specific target value from a set of ordered items.

It first checks the middle item and based on that comparison it discards the other half the records. The same procedure is then applied to the remaining half until a match is found or there are no more items left.

15. What is hashing?

Answer:

Hashing is a technique that is used to uniquely identify a specific object from a group of similar objects.

For example, each student in a college is assigned a unique roll number that can be used to retrieve information about them.

Here, the students are hashed to a unique number.

Hashing is implemented in two steps:

An element is converted into an integer by using a hash function. This element can be used as an index to store the original element, which falls into the hash table.

The element is stored in the hash table where it can be quickly retrieved using hashed key.