Data Structure interview answers

[quote]What are the various data-structures available?[/quote]

Data structure availability may vary by programming languages. Commonly available data structures are the list, arrays, stack, queues, graph, tree, etc.

[quote]What is the difference between PUSH and POP?[/quote]

Push and pop refer to the way data are stored into and retrieved from a stack.

[quote]Why do we need to do algorithm analysis?[/quote]

A problem can be solved in more than one ways. So, many solution algorithms can be derived for a given problem. We analyze available algorithms to find and implement the best suitable algorithm.

[quote]What is the difference between malloc() and calloc()?[/quote]

Following are the main difference between malloc() and calloc() functions

[quote]What is a hashing technique?[/quote]

In general, in all searching techniques, search time is dependent on the number of items. Sequential search, binary search, and all the search trees are totally dependent on the number of items and many key comparisons are involved.

Hashing is a technique where search time is independent of the number of items or elements. In this technique, a hash function is used to generate an address from a key. The hash function takes a key as input and returns the hash value of that key which is used as an address index in the array.

[quote]What is a divide and conquer method?[/quote]

The basic idea is to divide the problem into several subproblems beyond which cannot be further subdivided. Then solve the subproblems efficiently and join them together to get the solution for the main problem.

[quote]What are asymptotic notations?[/quote]

Asymptotic analysis can provide three levels of mathematical binding of the execution time of an algorithm − Best case is represented by Ω(n) notation, Worst case is represented by Ο(n) notation, the Average case is represented by Θ(n) notation.

[quote]Give some examples of greedy algorithms?[/quote]

The below-given problems find their solution using the greedy algorithm approach

Travelling Salesman Problem, Prim’s Minimal Spanning Tree Algorithm, Kruskal’s Minimal Spanning Tree Algorithm, Dijkstra’s Minimal Spanning Tree Algorithm, Graph – Map Coloring, Graph – Vertex Cover, Knapsack Problem, Job Scheduling Problem.

[quote]In RDBMS, what is the efficient data structure used in the internal storage representation?[/quote]

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.

[quote]What is the need for the header node?[/quote]

The header of the linked list is the first element in the list and it stores the number of elements in the list. It points to the first data element of the list.

[quote]What is a leaf?[/quote]

In a directed tree any node which has outdegree o is called a terminal node or a leaf.

Data Structure interview answers for fresher

[quote]Which data structure is used to perform recursion?[/quote]

The data structure used for recursion is Stack. Its LIFO property helps it remembers its ‘caller’. This helps it know the data which is to be returned when the function has to return. System stack is used for storing the return addresses of the function calls.

[quote]What is Huffman’s algorithm?[/quote]

It is used in creating extended binary trees that have minimum weighted path lengths from the given weights. It makes use of a table that contains the frequency of occurrence for each data element.

[quote]What is a linked list?[/quote]

The linked list is a data structure which stores the same kind of data elements but not in contiguous memory locations and size is not fixed. The linked lists are related logically.

[quote]How to find if the linked list has a loop?[/quote]

It means we can use the two-pointer approach to solve this problem. If we maintain two pointers, and we increment one pointer after processing two nodes and other after processing every node, we are likely to find a situation where both the pointers will be pointing to the same node. This will only happen if the linked list has the loop.

[quote]What is a stack?[/quote]

In data-structure, the stack is an Abstract Data Type (ADT) used to store and retrieve values in Last In First Out method.

[quote]Why do we use stacks?[/quote]

Stacks follows LIFO method and addition and retrieval of a data item takes only Ο(n) time. Stacks are used where we need to access data in the reverse order or their arrival. Stacks are used commonly in recursive function calls, expression parsing, depth-first traversal of graphs, etc.

[quote]What is the different application of stack?[/quote]

Some of the applications of the stack are as follows – Function calls, Reversal of a string, Checking the validity of an expression containing nested parentheses, Conversion of infix expression to postfix.

[quote]What is a spanning Tree?[/quote]

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.

[quote]What is the queue?[/quote]

A Queue is a sequential organization of data. A queue is a first in first out type of data structure. An element is inserted at the last position and an element is always taken out from the first position.

[quote]What are priority queues?[/quote]

A priority queue is a collection of elements such that each element has been assigned a priority.

Leave a Reply

Your email address will not be published. Required fields are marked *