Top 50 Data Structures Interview Questions for Freshers
https://www.computersprofessor.com/2019/04/top-50-data-structures-interview.html
Data Structure Interview Questions
A list of most frequently asked Data Structure interview questions and answers are given below.
1) What is Data Structure? Explain.
The data structure is a way that specifies how to organize and manipulate the data. It also defines the relationship between them. Some examples of Data Structures are arrays, Linked List, Stack, Queue, etc. Data Structures are the central part of many computer science algorithms as they enable the programmers to handle the data in an efficient way
2) Describe the types of Data Structures?
Data Structures are mainly classified into two types:
Linear Data Structure: A data structure is called linear if all of its elements are arranged in the sequential order. In linear data structures, the elements are stored in a non-hierarchical way where each item has the successors and predecessors except the first and last element.
Non-Linear Data Structure: The Non-linear data structure does not form a sequence i.e. each item or element is connected with two or more other items in a non-linear arrangement. The data elements are not arranged in the sequential structure.
3) List the area of applications of Data Structure.
Data structures are applied extensively in the following areas of computer science:
- Compiler Design,
- Operating System,
- Database Management System,
- Statistical analysis package,
- Numerical Analysis,
- Graphics,
- Artificial Intelligence,
- Simulation
4) What is the difference between file structure and storage structure?
Difference between file structure and storage structure:
The main difference between file structure and storage structure is based on memory area that is being accessed.
Storage structure: It is the representation of the data structure in the computer memory.
File structure: It is the representation of the storage structure in the auxiliary memory.
5) List the data structures which are used in RDBMS, Network Data Modal, and Hierarchical Data Model.
- RDBMS uses Array data structure
- Network data model uses Graph
- Hierarchal data model uses Trees
6) Which data structure is used to perform recursion?
Stack data structure is used in recursion due to its last in first out nature. Operating system maintains the stack in order to save the iteration variables at each function call
7) What is a Stack?
Stack is an ordered list in which, insertion and deletion can be performed only at one end that is called the top. It is a recursive data structure having pointer to its top element. The stack is sometimes called as Last-In-First-Out (LIFO) list i.e. the element which is inserted first in the stack will be deleted last from the stack.
8) List the area of applications where stack data structure can be used?
- Expression evaluation
- Backtracking
- Memory Management
- Function calling and return
9) What are the operations that can be performed on a stack?
- Push Operations
- Pop Operations
- Peek Operations
10) Write the stack overflow condition.
Overflow occurs when top = Maxsize -1
11) What is the difference between PUSH and POP?
PUSH and POP operations specify how data is stored and retrieved in a stack.
PUSH: PUSH specifies that data is being "inserted" into the stack.
POP: POP specifies data retrieval. It means that data is being deleted from the stack.
12) Write the steps involved in the insertion and deletion of an element in the stack.
Push:
- Increment the variable top so that it can refer to the next memory allocation
- Copy the item to the at the array index value equal to the top
- Repeat step 1 and 2 until stack overflows
Pop:
- Store the topmost element into the an another variable
- Decrement the value of the top
- Return the topmost element
13) What is a postfix expression?
An expression in which operators follow the operands is known as postfix expression. The main benefit of this form is that there is no need to group sub-expressions in parentheses or to consider operator precedence.
The expression "a + b" will be represented as "ab+" in postfix notation.
14)Write the postfix form of the expression: (A + B) * (C - D)
AB+CD-*
15) Which notations are used in Evaluation of Arithmetic Expressions using prefix and postfix forms?
Polish and Reverse Polish notations.
16)What is an array?
Arrays are defined as the collection of similar types of data items stored at contiguous memory locations. It is the simplest data structure in which each data element can be randomly accessed by using its index number.
17) How to reference all the elements in a one-dimension array?
It can be done by using an indexed loop such that the counter runs from 0 to the array size minus one. In this manner, you can reference all the elements in sequence by using the loop counter as the array subscript.
18) What is a multidimensional array?
The multidimensional array can be defined as the array of arrays in which, the data is stored in tabular form consists of rows and columns. 2D arrays are created to implement a relational database lookalike data structure. It provides ease of holding the bulk of data at once which can be passed to any number of functions wherever required.
19) How are the elements of a 2D array are stored in the memory?
There are two techniques by using which, the elements of a 2D array can be stored in the memory.
- Row-Major Order: In row-major ordering, all the rows of the 2D array are stored into the memory contiguously. First, the 1st row of the array is stored into the memory completely, then the 2nd row of the array is stored into the memory completely and so on till the last row.
- Column-Major Order: In column-major ordering, all the columns of the 2D array are stored into the memory contiguously. first, the 1st column of the array is stored into the memory completely, then the 2nd row of the array is stored into the memory completely and so on till the last column of the array.
20) Calculate the address of a random element present in a 2D array, given base address as BA.
Row-Major Order: If array is declared as a[m][n] where m is the number of rows while n is the number of columns, then address of an element a[i][j] of the array stored in row major order is calculated as,
Address(a[i][j]) = B. A. + (i * n + j) * size
Column-Major Order: If array is declared as a[m][n] where m is the number of rows while n is the number of columns, then address of an element a[i][j] of the array stored in column major order is calculated as
Address(a[i][j]) = ((j*m)+i)*Size + BA.
21) Define Linked List Data structure.
Linked List is the collection of randomly stored data objects called nodes. In Linked List, each node is linked to its adjacent node through a pointer. A node contains two fields, i.e. Data Field and Link Field.
22) Are linked lists considered linear or non-linear data structures?
A linked list is considered both linear and non-linear data structure depending upon the situation.
- On the basis of data storage, it is considered as a non-linear data structure.
- On the basis of the access strategy, it is considered as a linear data-structure.
23) What are the advantages of Linked List over an array?
- The size of a linked list can be incremented at runtime which is impossible in the case of the array.
- The List is not required to be contiguously present in the main memory, if the contiguous space is not available, the nodes can be stored anywhere in the memory connected through the links.
- The List is dynamically stored in the main memory and grows as per the program demand while the array is statically stored in the main memory, size of which must be declared at compile time.
- The number of elements in the linked list are limited to the available memory space while the number of elements in the array is limited to the size of an array.
24) Write the syntax in C to create a node in the singly linked list.
- struct node
- {
- int data;
- struct node *next;
- };
- struct node *head, *ptr;
- ptr = (struct node *)malloc(sizeof(struct node));
25) If you are using C language to implement the heterogeneous linked list, what pointer type should be used?
The heterogeneous linked list contains different data types, so it is not possible to use ordinary pointers for this. For this purpose, you have to use a generic pointer type like void pointer because the void pointer is capable of storing a pointer to any type.
26) What is doubly linked list?
The doubly linked list is a complex type of linked list in which a node contains a pointer to the previous as well as the next node in the sequence. In a doubly linked list, a node consists of three parts:
- node data
- pointer to the next node in sequence (next pointer)
- pointer to the previous node (previous pointer).