dsa Interview Questions and Answer C, C++,Java, Unix, Networking, Data Structure, STL, Unix Commands, Operating System
This is a free C, C++, Java, Unix, Networking, Data Structure, STL, Unix Commands, Operating System site, to help you to learn and sharpen your axe for interview.

 

Data Structure Interview Questions/Answer's,

_____________________________________________

A data structure is a way of storing data in a computer so that it can be used efficiently. Different kinds of data structures are suited to different kinds of applications.

______________________________________________

1.What is data structure?

Answer: A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data.

2.Types of Data Strucutre.

(1)Array (2) Stacks (3) Queues (4) Linked lists (5) Trees (6) Graphs

3.What are the major data structures used in the following areas : RDBMS, Network data model & Hierarchical data model.

Answer: The major data structures used are as follows:

  • RDBMS - Array (i.e. Array of structures)
  • Network data model - Graph
  • Hierarchical data model - Trees
4. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

Answer: The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable of storing pointer to any type as it is a generic pointer type.

5. How do you find out if a linked-list has an end? (i.e. the list is not a cycle)

You can find out by using 2 pointers. One of them goes 2 nodes each time. The second one goes at 1 nodes each time. If there is a cycle, the one that goes 2 nodes each time will eventually meet the one that goes slower. If that is the case, then you will know the linked-list is a cycle.

6. How do you write a function that can reverse a linked-list?

void reverselist(void)
{
if(head==0)
return;
if(head->next==0)
return;
if(head->next==tail)
{
head->next = 0;
tail->next = head;
}
else
{
node* pre = head;
node* cur = head->next;
node* curnext = cur->next;
head->next = 0;
cur-> next = head;

for(; curnext!=0; )
{
cur->next = pre;
pre = cur;
cur = curnext;
curnext = curnext->next;
}
curnext->next = cur;
}
}

7.Tell how to check whether a linked list is circular.

Create two pointers, each set to the start of the list. Update each as follows:
while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print (\”circular\n\”);
}
}

OK, why does this work?
If a list is circular, at some point pointer2 will wrap around and be either at the item just before pointer1, or the item before that. Either way, it’s either 1 or 2 jumps until they meet.

8. Minimum number of queues needed to implement the priority queue?

Answer: Two. One queue is used for actual storing of data and another for storing priorities.

9. What is the data structures used to perform recursion?

Answer: Stack. Because of its LIFO (Last In First Out) property it remembers its 'caller' so knows whom to return when the function has to return. Recursion makes use of system stack for storing the return addresses of the function calls.

Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written, explicit stack is to be used.

10.What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms?

Answer: Polish and Reverse Polish notations.

11. Convert the expression ((A + B) * C - (D - E) ^ (F + G)) to equivalent Prefix and Postfix notations.

Answer: Prefix Notation: ^ - * +ABC - DE + FG

Postfix Notation: AB + C * DE - - FG + ^

12. What are the methods available in storing sequential files?

Answer: The methods available in storing sequential files are:

  • Straight merging,
  • Natural merging,
  • Polyphase sort,
  • Distribution of Initial runs.

13. How many different trees are possible with 10 nodes ?

Answer: 1014

For example, consider a tree with 3 nodes(n=3), it will have the maximum combination of 5 different (ie, 23 - 3 = 5) trees

In general:
If there are n nodes, there exist 2n-n different trees.

14. List out few of the Application of tree data-structure?

Answer: The list is as follows:

  • The manipulation of Arithmetic expression,
  • Symbol Table construction,
  • Syntax analysis.

15. List out few of the applications that make use of Multilinked Structures?

Answer: The applications are listed below:

  • Sparse matrix,
  • Index generation.

16. List out few of the Application of tree data-structure?

Answer: The list is as follows:

  • The manipulation of Arithmetic expression,
  • Symbol Table construction,
  • Syntax analysis.

17. List out few of the applications that make use of Multilinked Structures?

Answer: The applications are listed below:

  • Sparse matrix,

18. What is a spanning Tree?

Answer: A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized.

Index generation.

19. Whether Linked List is linear or Non-linear data structure?

Answer: According to Access strategies Linked list is a linear one.
According to Storage Linked List is a Non-linear one.

20. What pointer type is used to implement the heterogeneous linked list in C?

The answer is the void pointer. The heterogeneous linked list contains different data types in it's nodes and we need a link, pointer, to connect them. Since we can't use ordinary pointers for this, we use the void pointer. Void pointer is a generic pointer type, and capable of storing pointer to any type.

21. What is the minimum number of queues needed to implement the priority queue?

Two. One queue is used for the actual storing of data, and the other one is used for storing the priorities.

22. What are some of the applications for the tree data structure?

·Manipulation of the arithmetic expressions.

·Symbol table construction.

·Syntax analysis.

23. Which data strucutres algorithm used in solving the eight Queens problem?

ANS :- Backtracking

24. In an AVL tree, at what condition the balancing is to be done?

If the "pivotal value", or the "heig