Data Structures are the base of software engineering. Almost all coding interviews you face today are mainly comprised of Data structure and Algorithm based questions. And big organizations like Google, Amazon, Facebook, etc., are also hiring programmers who are exceptionally good at optimizing data structures.

If you're aspiring to take your career to the next level in Data Structures but confused about what kind of programming questions you'll face in your interview? Well, you've reached the right place!

This article shares the latest 2021 Data Structure Interview questions and answers collected from different interviews for programmers at varying levels of experience. We hope the topic areas covered in this blog help both beginners and experienced crack their next interview!

If you would like to Enrich your career with a Java certified professional, then Enrol Our  “Core Java Certification TrainingCourse. This course will help you to achieve excellence in this domain.

According to research Data structures has a market share of about 9.4%. So, You still have the opportunity to move ahead in your career in Data structures. Mindmajix offers Advanced Data structures Interview Questions 2021 that help you in cracking your interview & acquire a dream career as a Data structures Developer.

Data structures Interview Questions and Answers

Below mentioned are the Top Frequently asked Data structures Interview Questions and Answers that will help you to prepare for the Data structures interview. Let's have a look into them.

Frequently Asked Data structures Interview Questions 

Top Data structures Interview Questions and Answers

Q1) Explain what is data structure?

Ans: The data structure is nothing but an entity where the data is perfectly aligned and it can be manipulated as per the requirement. When we deal with data structure it is not just about one table of data but it is about different data sets and how well they are aligned with each other. Overall, it helps the data to be organized.

Q2) What are the basic operations performed on various data structures?

Ans:  The basic operations performed on data structures are as follows:

  • Insertion - Adds a new data element in the data structure.  
  • Deletion - Removes a data element in a data structure. 
  • Searching - Involves searching for a specified data element in a data structure.
  • Traversal - Processing all data elements present in it.
  • Merging - Combines two similar data structures to form a new data structure of the same type.
  • Sorting - Arranging data elements of a data structure in a specified order.

Q3) Explain what is a linked list?

Ans: A linked list is nothing but a sequence of nodes. With this sequence, each node is connected to the following node. It forms a chain of data storage.

Q4) Explain the process of how do you reference all the elements in the one-dimension array in detail?

Ans: To reference all the elements in the one-dimension array, we have to use an indexed loop. With the help of this, it executes from “0” to array size minus one. By following this process the loop counter will be able to refer to all the elements.

Q4) List out the areas where the data structure is applied?

Ans: The data structure is a vital aspect while handling data. The following are specific areas where the data structure is applied:

1. Numerical analysis
2. Operating systems
3. A.I.
4. Database management
5. Statistical analysis

The above are few areas where the data structure is applied and not limited to.

Q5) What is infix, prefix, and postfix in data structure?

Ans. The way to write arithmetic expressions is known as notation. There are three types of notations used in an arithmetic expression, i.e., without changing the essence or output of expression. These notations are:

  • Prefix (Polish) Notation - In this, the operator is prefixed to operands, i.e. ahead of operands.
  • Infix Notation - In this, operators are used in between operands.
  • Postfix (Reverse-Polish) Notation - In this, the operator is postfixed to the operands, i.e., after the operands.

The following table briefly tries to show the difference in all three notations −

Infix Notation Prefix Notation Postfix Notation
x + y + x y x y +
(x + y) ∗ z ∗ + x y z x y + z ∗
x ∗ (y + z) ∗ x + y z x y z + ∗
x / y + z / w + / x y / z w x y / z w / +
(x + y) ∗ (z + w) ∗ + x y + z w x y + z w + ∗
((x + y) ∗ z) - w - ∗ + x y z w x y + z ∗ w -

Data Structures Interview Questions and Answers for Freshers

Q6) Explain the terminology LIFO?

Ans: LIFO stands for Last In First Out.

This process describes how the data is accessed, stored, and then retrieved. So the latest data that is stored in the database can be extracted first.

Q7) Explain what is a  binary tree?

Ans:  It is one type of data structure that has two nodes, has left node and right node. In a programming language, binary trees are considered to be an extension to the linked list.

Q8) Define what is a stack?

Ans: The stack is considered as a data structure where the top layer element can be accessed. The data is stored in the stack and every time when data is stored, it pushes the data downwards which enables the users to access the latest data from the top layers.

Q9) Explain what is multidimensional arrays?

Ans:  Multidimensional arrays use multiple indexes in order to store data into the database. In a few scenarios, data cannot be stored using a single dimension index, in these scenarios multidimensional arrays are useful.

Q10) Explain whether a linked list is considered as a linear or non-linear data structure?

Ans: This is purely determined on the requirement basis, a linked list can be considered as a linear data structure or a non-linear data structure. For example: If the linked list is used on storages, then the linked list is considered as a nonlinear data structure.

If linked lists are used against access strategies then they are considered as a linear data structure.

Q11) Explain how does dynamic memory allocation will help you in managing data?

Ans: A dynamic memory allocation will help you effectively manage your data by allocating structured blocks to have composite structures that can be flexible, i.e. it can expand and can contract based on the need.

Also, they are capable of storing simple structured data types.

Q12) What is FIFO?

Ans:  FIFO in data terminology it stands as “First in, First Out”.

This process defines or depicts how the data is stored inserted and accessed in a queue. Within this process, the data that is inserted at the beginning of the queue will only be extracted or accessed first.

Q13) Explain what is merge sort and how it is useful?

Ans: A merge sort is nothing but a process where the data is divided and sorted to reach the end goal. Within this process, the adjacent elements are merged and sorted to create bigger elements. These sorted elements are gathered again and made the even bigger list. This process is continuous and repetitive until and unless they have nailed it down to a single sorted list.

Q14) List out all the advantages of a linked list?

Subscribe to our youtube channel to get new updates..!

Ans: The important aspect or advantage of a linked list is that it is the perfect data structure where the data can be modified very easily. Also, it doesn’t matter how many elements are available on the linked list.

Q15) Explain the main difference between PUSH and a POP?

Ans: The two main activities, i.e. Pushing and Popping applies the way how data is stored and retrieved in an entity. So if you check in detail, a Push is nothing but a process where data is added to the stack.  On the contrary, a Pop is an activity where data is retrieved from the stack. When we discuss the data retrieval it only considers the topmost available data.

Q16) Can you explain with an example how does a variable declaration activity will consume or affect the memory allocation?

Ans: The amount of space or memory is occupied or allocated depends upon the data type of the variables that are declared. So let’s explain the same by considering an example:  Let’s say the variable is declared as an integer type then 32 bits of memory storage is allocated for that particular variable.
So based on the data type of the variable, the memory space will be allocated.

Core Java Programming Tutorial

Q17) Define the advantages and disadvantages of the heap compared to a stack?

Ans: The advantages of the heap compared to a stack are listed below:

  1. Heap is more flexible when compared to a stack
  2. Memory space of the heap can actually be allocated and de-allocated as per the need.

On the contrary, the disadvantages of the heap compared to a stack is listed below:

  1. The memory of the heap is slower when compared to the memory of the stack

Q18) Explain how new data can be inserted into the tree?

Ans:  The following are the steps that you need to follow to insert the data into the tree:

  1. First of all, check whether the data is unique or not ( i.e. check whether the data that you are going to insert doesn’t already exist in the tree).
  2. Then check if the tree is empty. If the tree is empty then all you need to do is just insert a new item into the root.  If the key is smaller to that of a root’s key then insert that the data into the root’s left subtree or otherwise, insert the data into the right side of the root’s subtree.

Q19) Can you tell me the minimum number of nodes that a binary tree can have?

Ans:  A binary tree is allowed or can have a minimum of zero nodes. Further, a binary tree can also have 1 or 2 nodes.

Q20) Explain a little bit about the dynamic data structure?

Ans:  The nature of the dynamic data structure is different compared to the standard data structures, the word dynamic data structures means that the data structure is flexible in nature. As per the need, the data structure can be expanded and contracted. Thus it helps the users to manipulate the data without worrying too much about the data structure flexibility.

Q21) Define what is an array?

Ans: While referring to array the data is stored and utilized based on the index and this number actually co-relates to the element number in the data sequence. So thus making it flexible to access data in any order. Within programming language, an array is considered as a variable having a certain number of indexed elements.

Q22) Can you tell me the minimum number of queues that are needed to implement a priority queue?

Ans: The minimum number of queues that is needed is two. Out of which, one queue is intended for sorting priorities and the other queue is meant for the actual storage of data.

Q23) List out all different sorting algorithms that are available and state which sorting algorithm is considered as the fastest?

Ans:  The list of all sorting algorithms are below:

1. Quicksort
2. Bubble sort
3. Balloon sort
4. Radix sort
5. Merge sort

Out of the above sorting options, none of the sorting algorithms can be tagged as the fastest algorithm, because each of these sorting algorithms is defined for a specific purpose. So based on the data structure and data sets available the sorting algorithms are used.

Q24) Explain what is a dequeue?

Ans:  A dequeue is nothing but a double-ended queue. Within this structure, the elements can be inserted or deleted from both sides.

Q25) Explain the process of how a selection sort works?

Ans: A selection sort is a process where it picks up the smallest number from the entire data set list and places at the beginning. The same process is continued where the second position is already filled in. The same process is continued all the way until the list is completed. The selection sort is defined as a simple sort algorithm when compared to others.

Data Structures Interview Questions and Answers for Experienced

Q26) Explain what is a graph?

Ans: A graph is nothing but a type of data structure that has a set of ordered pairs. In turn, these pairs are again acknowledged as edges or arcs. These are used to connect different nodes where the data can be accessed and stored based on the needs.

Q27) Is it possible to implement a stack using a queue?

Ans: Yes, you can implement stack using two queues. Any data structure to act like a stack should have a push() method to add data on top and a pop() method to remove the top data.

Q28) How would you implement a queue using stack?

Ans: Using two stacks, you can implement a queue. The purpose is to complete the queue's enqueue operation so that the initially entered element always ends up at the top of the stack. 

  • First, to enqueue an item into the queue, migrate all the elements from the beginning stack to the second stack, push the item into the stack, and send all elements back to the first stack.
  • To dequeue an item from the queue, return the top item from the first stack.

Q29) Where is the LRU cache used in data structure?

Ans: In data structures, you use LRU (Least Recently Used) cache to organize items in order of use, enabling you to quickly find out which item hasn't been used for a long time.

Q30) Which Data Structure is used to implement LRU cache? 

Ans: To implement the LRU cache, you should use two data structures: a hashmap and a doubly linked list.

A hashmap helps with the lookup of cached keys, and a doubly-linked list helps maintain the eviction order.

Q31) What is the difference between an array and a linked list?

Ans: Array and Linked list are two ways of organizing the data in memory. The below table lists the various differences between the array and linked lists:

Array Linked List
An array is a sequence of elements of a similar data type. A Linked list is a set of objects known as a node, where it internally consists of two parts, i.e., data and address.
It can be accessed irregularly using the array index. Linked lists support random access. Only supports sequential access.
Array elements store in contiguous locations in memory. New elements can be stored anywhere, and a reference is created for the new element using pointers.
In arrays, memory allocation is done during compile time. In linked lists, memory allocation is done during runtime.
Array size must be defined at the time of declaration/initialization. Linked list size grows when new elements are inserted or deleted.

Q32) What are the advantages of Linked Lists over Array?

Ans: The following are the advantages of Linked Lists over Arrays:

  • Dynamic Data Structure - A Linked list is a dynamic data structure so that it can grow at runtime by deallocating and allocating memory. There is no need to present the linked list initial size.
  • Insertion and Deletion Operations - Insertion and Deletion operations are easier in linked lists. You need to have to update the address present in the next pointer of a node.
  • Implementation - Data structures like queue, tree, and stack are easily implemented using the Linked list.
  • No memory wastage - Efficient memory utilization can be achieved in the linked lists.

Q33) What are the applications of a stack in a data structure?

Ans: Following are some of the essential applications in a data structure:

  • Expression evaluation
  • Backtracking 
  • Function calling and return
  • Memory management
  • Checking parenthesis matching in an expression

Q34) What are the different types of Linked List?

Ans: The following are the different types of Linked Lists.

  • Singly Linked List - This is the most common type, and each node has data and a pointer to the next node. 

Singly Linked List

  • Doubly Linked List - In this type, the pointer is added to the previous node, either in a forward or backward direction.

Doubly Linked List

  • Circular Linked List - In this type, the last element is linked to the first element. 

Circular Linked List

Q35) What is the difference between storage structure and file structure?

Ans: The main difference between storage structure and file structure depends on the memory area that is accessed.

  • Storage structure: It's a data structure representation in computer memory. 
  • File structure: It's a storage structure representation in the auxiliary memory.

Q36) What operations can be performed on a stack?

Ans: Mainly the following operations are performed on a stack:

  • Push operation: To add an item to the stack. If the stack is complete, then it is in an overflow condition.
  • Pop operation: It is used to remove an item from the stack. If it's an empty stack, then it is in underflow condition.
  • isEmpty operation: If the stack is empty returns true, else false.
  • Peek or Top operation: This returns the top element of the stack.

Q37) Name some applications of data structures?


  • Operating system
  • Artificial Intelligence
  • Statistical analysis
  • Database management
  • Compiler design
  • Graphics
  • Simulation 
  • Numerical analysis

Q38) Explain about Linked List Data Structure.

Ans: A linked list is a series of data structures connected via links. In simple words, it's a sequence of links that contain items. After the array, the linked list is the second most used data structure. The essential terms to understand the linked list are:

Link - In a linked list, each link stores data called an element.

Next - In a linked list, each link is connected to the following link called next.

LinkedList -  It contains the connection link to the first link called first.


The below diagram depicts how nodes are connected in the Linked List:

Linked List

Basic operations supported by a linked list:

  • Insertion - Inserts an element at the list beginning.
  • Deletion - Deletes an element at the list beginning.
  • Display - Displays the complete list.
  • Search - Searches an element using the given key.
  • Delete - Deletes an element using the given key.

Q39) Are linked lists considered non-linear or linear data structures?

Ans: It depends on where you plan to use Linked lists. You can consider a linked list for both non-linear and linear data structures. When used for data storage, it is regarded as a non-linear data structure. When used for access strategies, it is considered a linear data structure.

Q40) What is a doubly-linked list used for?

Ans: A doubly linked list is one of the complex types of the linked list, where a node contains a pointer to the previous and the next node in the sequence. It consists of three parts: node data, a pointer to the next node in sequence (next pointer), a pointer to the previous node (previous pointer)

The below diagram depicts the working of doubly linked list:

Doubly Linked list

Some of the real-time applications where doubly-linked lists used are navigation systems and browsers (when both back and front navigation is required).

Frequently Asked Core Java interview questions

Q41) What is a queue in data structure?

Ans: A queue is a linear data structure that supports a specific order in which operations are performed. The order is FIFO (First in First Out) methodology, i.e., data items stored first will be accessed first. Unlike stack, the queue is open at both ends, and one end is always used to insert data and another one to remove data.

The basic operations associated with queues -

  • Dequeue - To remove an item
  • Enqueue - To insert an item
  • isempty() − Confirms whether the queue is empty.
  • isfull() − Confirms whether the queue is full.
  • peek() − Gets the element at the front of the queue without removing it.

Q42) List a few queue data structure applications.

Ans: As the name suggests, the queue is used whenever you need to manage a group of objects in the order FIFO. A few of the queue data structure applications are listed below:

  • Serving requests on a single shared resource, like CPU task scheduling, printer, etc.
  • Handling interruptions in real-time systems.
  • Buffers in apps like CD player and MP3 media players
  • In maintaining a playlist in media players, like adding or removing songs.

Q43) What is the difference between stack and heap?

Ans: Both stack and heap used for memory needs. The stack is primarily used to save the method execution order and local variables, and always follow the LIFO order.

Whereas heap used for dynamic allocation and deallocation of memory blocks. It stores objects in Java. Memory allocated to the heap lives until one of the following events occurs:

  • Memory free
  • Program terminated

The size of heap memory is more when using recursion when compared with the stack, as it quickly fill-ups stack memory.

Q44) Name a few graph data structure applications.

Ans: Applications of graph data structures in real-time are:

  • Social graphs
  • Path optimization algorithms
  • Recommendation engines
  • Scientific computations

Q45) What is an AVL tree?

Ans: An AVL (Adelson, Velskii, and Landi) is a self-balancing binary search tree where the variation of heights of the right and left subtrees of any node is not more than one.

An example of an AVL tree:

 AVL Tree

A tree is balanced if the balance factor of each node is between -1 to 1. Or else, the tree is unbalanced and needs to be balanced.

Q46) How do you detect a loop in a linked list?


  • Using Floyd's cycle-finding Algorithm
  • Using hashing
  • Using the visited nodes method 

Q47) What is a Jagged array?

Ans: Jagged arrays are a particular type of arrays used for storing rows of data of varying lengths to improve efficiency when working with multidimensional arrays.

Q48) What is the max heap in the data structure?

Ans: A max heap in a data structure is a complete binary tree where each internal node's value is greater than or equal to that node's children's values.

Q49) How to find the height of a node in a tree?

Ans. You can find the height of a binary tree using a recursive Depth-First Search (DFS) algorithm, as shown below:

  • Base case: If there is no node, return 0.
  • Else: If there are 1 or 2 children, return the peak of the height of the left and right subtrees, plus 1 to account for the current node.

Q50) List the types of tree.


  • General Tree
  • Binary Tree
  • Forests
  • Expression Tree
  • Binary Search Tree
  • Tournament Tree

Q51) Which data structures do you use in DFS and BFS algorithms?


  • In the DFS algorithm, you use the Stack data structure.
  • In the BFS algorithm, you use the Queue data structure.


By now, you must have got enough idea about what kind of Data Structure Interview Questions you can expect in your interview. Although you can expect many of these questions, you need to spend some more time on your learning curve. There is no point in attempting these questions if you don't have enough knowledge of essential Data Structure and Algorithms.