The purpose of penning down a Data Structure and Algorithm Interview Questions is to get you acquainted with the nature of questions that are generally asked in an interview for the subject Data Structure and Algorithms. Good interviewers do not come up with predetermined questions. Typically, questions start from basic concepts of the subject and continue depending on your answers and further discussion.
Data Structures Interview Questions & Answers
1. What is data structure?
You can think of data structure as a methodology that defines, stores, and retrieves data systematically and structurally. A data structure can contain different kinds of data items.
2. What are the various data structures available?
The availability of data structures can vary depending on the programming language. Some of the commonly used data structures are tree, graphs, queues, lists, arrays, and stack.
Also Read: Sorting in Data Structure
3. What does an algorithm mean?
You can think of an algorithm as a stepwise procedure for defining a cluster of instructions whose execution in a fixed order gives the desired output.
4. What is the need for algorithm analysis?
A given problem can be solved in numerous ways. Hence, it is possible to derive several solution algorithms. The purpose of analysing algorithms is to find and implement the most suitable algorithm.
5. Criteria for algorithm analysis
Algorithms are analysed based on two factors – space and time. It implies execution time and extra space required on the part of an algorithm.
6. What is meant by an algorithm’s asymptotic analysis?
For any algorithm, there are three different levels of execution time based on mathematical binding:
- Representation of the Best Case is done by the symbol Ω(n)
- Representation of the Worst-Case is done by the symbol Ο(n)
- Representation of the Average Case is done by the symbol Θ(n)
7. What is meant by a linear data structure?
When data items are arranged sequentially, it is called linear data structure. Data items are stored and accessed sequentially. A typical example of a linear data structure is a list and array.
8. What are the common operations performed on a data structure?
Following are the operations that can be performed on a data structure:
Insertion – Addition of a data item
Deletion – Data item elimination
Traversal – Accessing and printing data items
Search – Find a data item
Sort – Data items arranged in a predefined sequence
Must Read: Data Structure Project Ideas & Topics
9. What are the different approaches to developing algorithms?
There are three commonly used approaches to developing algorithms, which are:
Greedy Approach: Choosing the next best option for finding a solution.
Divide and Conquer: The problem is divided into a minimum possible subproblems and each subproblem is solved independently.
Dynamic Programming: A problem is divided into minimal subproblems, and they are solved together. C
9. Examples of the greedy algorithm:
- · Minimal spanning tree algorithm of Djikstra, Kruskal, and Prim
- · Graph – Colouring of map
- Problem of Vertex Cover
- · Problem of Job Scheduling
- · Problem of Knapsack
- · Problem of Travelling Salesman
10. Examples of divide and conquer algorithms
- Stassen’s Matrix Multiplication
- Quick Sort
- Merge Sort
- Closest pair
- Binary Search
11. Examples of dynamic programming algorithms:
- Tower of Hanoi
- Shortest path by Dijkstra
- Project scheduling
- Knapsack problem
- Fibonacci number series
- All pair shortest path by Floyd-Marshall
12. What is a linked list?
You can think of a linked list as a list of data items that are interconnected with links, i.e. references or pointers. Direct access to memory locations is not permitted in contemporary high-level languages, and are not supported in them. If they are available, it is in the form of in-built functions.
13. What is a stack?
It is a kind of abstract data type used for storing and retrieving values in Last In First Out format.
14. Why do we use stacks?
Stacks uses the LIFO method of addition and retrieval of data items that consume only O(n) time. If you ever need to access data items in reverse order of their arrival, then you can use stacks. Stacks are more commonly used in expression parsing, a recursive function call, and depth-first traversal of graphs.
Common operations that you can perform on a stack:
push(): Adding an item to the stack top
pop(): Removing an item from the stack top
peek(): Shows the value of a top item without deleting it
is empty(): Check if you have an empty stack
is full(): Checks if you have a full-stack
15. What is meant by a queue in data structure?
Like the stack, the queue is also an abstract data structure. However, a queue is open on both ends. It means that one end is used for inserting data (enqueue), and the other end is used for removing the item (dequeue). Queue follows the First-In-First-Out methodology, i.e. the data item that is stored first will be accessed first.
16. What is the use of queues?
As the queue follows the First In First Out method, this data structure can be used for working on data items in the exact sequence of their arrival. Queues are widely used in operating systems for different processes. Breadth-First Traversal of Graphs and Priority Queues are some examples of queues.
17. Operations that can be performed in a queue:
enqueue(): Adding items to the rear end of the queue
dequeue(): Removes an item from the front end of the queue
peek (): Shows the value of the front item without removing it
is empty(): Checks if the stack is empty
is full(): Checks if the stack is full
18. What is a binary search?
Binary search is a searching technique that applies to a sorted list or array. The search selects the middle unit that can split the whole list into two parts. First, the middle unit is compared to the search item.
If it is a match, the algorithm terminates successfully. Otherwise, it tries to ascertain whether the search item is smaller or larger than the middle unit. If the search item is small, then the middle becomes the last item of the array or list. If the search item is large, then the middle becomes the top item of the list.
We hope our data structure interview questions and answers guide is helpful. We will be updating the guide regularly to keep you updated.
If you are curious to learn about data science, check out IIIT-B & upGrad’s PG Diploma in Data Science which is created for working professionals and offers 10+ case studies & projects, practical hands-on workshops, mentorship with industry experts, 1-on-1 with industry mentors, 400+ hours of learning and job assistance with top firms.