Monday, January 14, 2013

Java - Data Structure Question & Answer

1. What is data structure?
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.

There are two types of data structure
  • Linear 
  • Nonlinear

2. List out the areas in which data structures are applied extensively?
  1. Compiler Design,
  2. Operating System,
  3. Database Management System,
  4. Statistical analysis package,
  5. Numerical Analysis,
  6. Graphics,
  7. Artificial Intelligence,
  8. Simulation
3. What are the major data structures used in the following areas : RDBMS, Network data model and Hierarchical data model.
  1. RDBMS = Array (i.e. Array of structures)
  2. Network data model = Graph
  3. Hierarchical data model = Trees
4. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
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. Minimum number of queues needed to implement the priority queue?
Two. One queue is used for actual storing of data and another for storing priorities.
6. What is the data structures used to perform recursion?
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.

7. What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms?
Polish and Reverse Polish notations.
8. Convert the expression ((A + B) * C - (D - E) ^ (F + G)) to equivalent Prefix and Postfix notations.
  1. Prefix Notation: - * +ABC ^ - DE + FG
  2. Postfix Notation: AB + C * DE - FG + ^ -
9. Sorting is not possible by using which of the following methods? (Insertion, Selection, Exchange, Deletion)

Sorting is not possible in Deletion. Using insertion we can perform insertion sort, using selection we can perform selection sort, using exchange we can perform the bubble sort (and other similar sorting methods). But no sorting method can be done just using deletion.
10. What are the methods available in storing sequential files ?
  1. Straight merging,
  2. Natural merging,
  3. Polyphase sort,
  4. Distribution of Initial runs.
11. List out few of the Application of tree data-structure?
  1. The manipulation of Arithmetic expression,
  2. Symbol Table construction,
  3. Syntax analysis.
12. List out few of the applications that make use of Multilinked Structures?
  1. Sparse matrix,
  2. Index generation. 
13. In tree construction which is the suitable efficient data structure? (Array, Linked list, Stack, Queue)
Linked list is the suitable efficient data structure.
14. What is the type of the algorithm used in solving the 8 Queens problem?
15. In an AVL tree, at what condition the balancing is to be done?
If the 'pivotal value' (or the 'Height factor') is greater than 1 or less than -1.
16. What is the bucket size, when the overlapping and collision occur at same time?
One. If there is only one entry possible in the bucket, when the collision occurs, there is no way to accommodate the colliding value. This results in the overlapping of values.
17. Classify the Hashing Functions based on the various methods by which the key value is found.
  1. Direct method,
  2. Subtraction method,
  3. Modulo-Division method,
  4. Digit-Extraction method,
  5. Mid-Square method,
  6. Folding method,
  7. Pseudo-random method.
18. What are the types of Collision Resolution Techniques and the methods used in each of the type?
  1. Open addressing (closed hashing), The methods used include: Overflow block.
  2. Closed addressing (open hashing), The methods used include: Linked list, Binary tree.
19. In RDBMS, what is the efficient data structure used in the internal storage representation?
B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes searching easier. This corresponds to the records that shall be stored in leaf nodes.
20. What is a spanning Tree?
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.
21. Does the minimum spanning tree of a graph give the shortest distance between any 2 specified nodes?
No. The Minimal spanning tree assures that the total weight of the tree is kept at its minimum. But it doesn't mean that the distance between any two nodes involved in the minimum-spanning tree is minimum.
22. Which is the simplest file structure? (Sequential, Indexed, Random)
Sequential is the simplest file structure.
23. Whether Linked List is linear or Non-linear data structure?
According to Access strategies Linked list is a linear one.
According to Storage Linked List is a Non-linear one.

24. What is a Linked list ?
A linked list is a linear collection of data elements, called nodes, where the linear order is given by pointers. Each node has two parts first part contain the information of the element second part contains the address of the next node in the list.

25. What is Queue ?
 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.

 26. What is Precision ?
Precision refers the accuracy of the decimal portion of a value. Precision is the number of digits allowed after the decimal point.

27.  What are the goals of Data Structure ?
It must rich enough in structure to reflect the actual relationship of data in real world. The structure should be simple enough for efficient processing of data.

28. What is the difference between a Stack and an Array?
  • Stack is a dynamic object whose size is constantly changing as items are pushed and popped .
  • Stack may contain different data types.
  • Stack is declared as a structure containing an array to hold the element of the stack, and an integer to indicate the current stack top within the array.
  • Stack is a ordered collection of items.
  • Array
  • Array is an ordered collection of items.
  • Array is a static object.
  • It contains same data types.
  • Array can be home of a stack i.e. array can be declared large enough for maximum size of the stack.

 29. What is Sequential Search ?

In sequential search each item in the array is compared with the item being searched until a match occurs. It is applicable to a table organized either as an array or as a linked list.

 30. What are the disadvantages array implementations of linked list?
The no of nodes needed can’t be predicted when the program is written.
The no of nodes declared must remain allocated throughout its execution.

31. What is a priority queue?
The priority queue is a data structure in which the intrinsic ordering of the elements.

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

33. Define circular list?
In linear list the next field of the last node contain a null pointer, when a next field in the last node contain a pointer back to the first node it is called circular list.

34. What does abstract Data Type Mean?
Data type is a collection of values and a set of operations on these values. Abstract data type refer to the mathematical concept that define the data type.

35.  What do you mean by recursive definition?
The definition which defines an object in terms of simpler cases of itself is called recursive definition.

36. What actions are performed when a function is called?
    When a function is called
  • arguments are passed
  • local variables are allocated and initialized
  • transferring control to the function

37. Define double linked list?
    It is a collection of data elements called nodes, where each node is divided into three parts
  • An info field that contains the information stored in the node.
  • Left field that contain pointer to node on left side.
  • Right field that contain pointer to node on right side.
38. What do you mean by overflow and underflow?
When new data is to be inserted into the data structure but there is no available space 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.

39. Whether Linked List is linear or Non-linear data structure?
According to Access strategies Linked list is a linear one. According to Storage Linked List is a Non-linear one.

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

 41. What are the methods available in storing sequential files ?
  • Straight merging
  • Natural merging
  • Polyphase sort
  • Distribution of Initial runs

 42. What is a node class?
A node class is a class that has added new services or functionality beyond the services inherited from its base class.

 43. what is binary tree?
A binary tree is a tree data structure in which each node has at most two child nodes, usually distinguished as left and right.

44. Why is the isEmpty() member method called?

The isEmpty() member method is called within the dequeue process to determine if there is an item in the queue to be removed i.e. isEmpty() is called to decide whether the queue has at least one element. This method is called by the dequeue() method before returning the front element.

 45. How is the front of the queue calculated ?
The front of the queue is calculated by front = (front+1) % size.

 46. What does each entry in the Link List called?
Each entry in a linked list is called a node. Think of a node as an entry that has three sub entries. One sub entry contains the data, which may be one attribute or many attributes. Another points to the previous node, and the last points to the next node. When you enter a new item on a linked list, you allocate the new node and then set the pointers to previous and next nodes.

 47. What member function places a new node at the end of the linked list?
The appendNode() member function places a new node at the end of the linked list. The appendNode() requires an integer representing the current data of the node.

48. How is any Data Structure application is classified among files?
A linked list application can be organized into a header file, source file and main application file. The first file is the header file that contains the definition of the NODE structure and the LinkedList class definition. The second file is a source code file containing the implementation of member functions of the LinkedList class. The last file is the application file that contains code that creates and uses the LinkedList class.

49. Run Time Memory Allocation is known as ?
Allocating memory at runtime is called a dynamically allocating memory. In this, you dynamically allocate memory by using the new operator when declaring the array, for example : int grades[] = new int[10];

50. What method is used to place a value onto the top of a stack?
push() method, Push is the direction that data is being added to the stack. push() member method places a value onto the top of a stack.

51. What method removes the value from the top of a stack?
The pop() member method removes the value from the top of a stack, which is then returned by the pop() member method to the statement that calls the pop() member method.

52. 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\”);