Data Structure Interview Questions and Answers


Answer. Data Structure is a way of organizing all data items that considers not only the elements stored but also their relationship to each other.

Answer. 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.

Answer. A particular kind of data item, as defined by the values it can take, the programming language used, or the operations that can be performed on it.

Answer. Primitive data structures are basic structures and are directly operated upon by machine instructions.

Answer. A data structure is said to be Linear, if its elements are connected in linear fashion by meAnswer of logically or in sequence memory locations.

Answer. Algorithm is a step by step procedure, which defines a set of instructions to be executed in certain order to get the desired output.

Answer. Memory allocation is the process of setting aside sections of memory in a program to be used to store variables, and instances of structures and classes.

Answer. The malloc( ) function allocates a block of memory in bytes. The user should explicitly give the block sixe it requires of the use. The malloc( ) is like a request to the RAM of the system to allocate memoty.

Answer. This function works exactly similar to malloc( ) function except for the fact that it needs two arguments as against one argument required by malloc( ).

Answer. The free( ) function is used to de-allocate the previously allocated memory using malloc( ) or calloc( ) functions.

Answer. This function is used to resize the size of memory block, which is already allocated. It found use of in two situations :

  • If the allocated memory block is insufficient for current application.
  • If the allocated memory is much more than what is required by the current application.

Answer. Recursion is one of the most powerful tools in a programming language, but one of the most threatening topics-as most of the beginners and not surprising to even experienced students feel.

Answer. There are two types of Recursion

  • Direct recursion.
  • Indirect recursion.

Answer. An array is a data structure used to process multiple elements with the same data type when a number of such elements are known.

Answer. A one-dimensional array is one in which only one subscript specification is needed to specify a particular element of the array.

Answer. Two dimensional arrays are also called table or matrix, two dimensional arrays have two subscripts. Two dimensional array in which elements are stored column by column is called as column major matrix.

Answer. Strings in C are stored as null character, '', terminated character arrays.

Answer. An array of strings is just a two dimensional array of characters.

Answer. A stack is a non-primitive linear data structure. It is an ordered list in which addition of new data item and deletion of already existing data item is done from only one end, known as top of stack(TOS).

Answer. The push operation is used to insert an element into the stack. The new element is added at the topmost position of the stack.

Answer. The pop operation is used to delete the topmost element from the stack.

Answer. Queue is an abstract data structure, somewhat similar to stack. In contrast to stack, queue is opened at both end. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue).

Answer. As queues follows FIFO method, they are used when we need to work on data-items in exact sequence of their arrival.

Answer. There is a special data structure called Linked list that provides a more flexible storage system and it does not require the use of arrays.

Answer. A Singly Linked list is one in which all nodes are linked together in some sequential manner. Hence, it also called linear linked list. Clearly it has the beginning and the end.

Answer. A doubly linked list is one in which all nodes are linked together by multiple number of links which help in accessing both the successor node and predecessor node from the given node position. It provides bi-directional traversing.

Answer. In a circular linked list, the last node contains a pointer to the first node of the list. We can have a circular singly linked list as well as a circular doubly linked list.

Answer. A circular doubly linked list or a circular two-way linked list is a more complex type of linked list which contains a pointer to the next as well as the previous node in the sequence.

Answer. A tree is non-linear data structure in which items are arranged in a sorted sequence. It is used to impose a hierarchical structure on a collection of data items.

Answer. It is specially designed data item in a tree. It is the first in the hierarchical arrangement of data items. The root node is the topmost node in the tree.

Answer. Each data item in a tree is called a node.

Answer. The degree of a node of a tree is the number of subtrees having this node as a root. In other words, the degree is the number of descendants of a node. If the degree is zero, it is called a terminal or leaf node of a tree.

Answer. The children nodes of a given parent node are called siblings.

Answer. It is a connecting line of two nodes. That is, the line drawn from one node to another node is called an edge.

Answer. The binary tree is a fundamental data structure used in computer science. The binary tree is a useful data structure for rapidly storing sorted data and rapidly retrieving stored data.

Answer. If every non-terminal node in a binary tree consists of non empty left subtree and right subtree, then such a tree is called strictly binary tree.

Answer. A complete binary tree is a binary tree that satisfies two properties. First, in a complete binary tree, every level, except possibly the last, is completely filled.

Answer. A binary search tree, also known as an ordered binary tree, is a variant of binary tree in which the nodes are arranged in an order.

Answer. A graph is an abstract data structure that is used to implement the mathematical concept of graphs. It is basically a collection of vertices (also called nodes) and edges that connect these vertices.

Answer. Graph traversal is the problem of visiting all the nodes in a graph in a particular manner, updating and/or checking their values along the way.

Answer. The shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized.

Answer. Sorting is nothing but storage of data in sorted order, it can be in ascending or descending order. The term Sorting comes into picture with the term Searching.

Answer. Bubble sorting is a simple sorting technique in which we arrange the elements of the list by forming pairs of adjacent elements.

Answer. The selection sort technique is based upon the extension of the minimum/maximum technique.

Answer. An insertion sort is one that sorts a set of values by inserting values into an existing sorted file.

Answer. It is one of the most popular sorting techniques. Quick sort possesses a very good average-case behaviour among all the sorting techniques. This is developed by C.A.R. Hoare.

Answer. Merge sort is a sorting technique which divides the array into subarrays of size 2 and merge adjacent pairs.

Answer. Heap Sort is one of the best sorting methods being in-place and with no quadratic worst-case scenarios.

Answer. Shell sort is considered an improvement over insertion sort as it compares elements separated by a gap of several positions. This enables the element to take bigger steps towards its expected position.

Answer. The idea is to consider the key one character at a time and to divide the entries, not into two sub lists, but into as many sub lists as there are possibilities for the given character from the key.