Programs

# Data Structure Interview Question & Answers [For Freshers & Experienced]

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. If you want to gain expertise and get your dream data science job, check out our data science certifications.

## 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:

1. Â· Minimal spanning tree algorithm of Djikstra, Kruskal, and Prim
2. Â· Graph â€“ Colouring of map
3. Problem of Vertex Cover
4. Â· Problem of Job Scheduling
5. Â· Problem of Knapsack
6. Â· Problem of Travelling Salesman

10. Examples of divide and conquer algorithms

1. Stassenâ€™s Matrix Multiplication
2. Quick Sort
3. Merge Sort
4. Closest pair
5. Binary Search

11. Examples of dynamic programming algorithms:

1. Tower of Hanoi
2. Shortest path by Dijkstra
3. Project scheduling
4. Knapsack problem
5. Â Fibonacci number series
6. 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

upGrad’s Exclusive Data Science Webinar for you –

## Explore our Popular Data Science Courses

 Executive Post Graduate Programme in Data Science from IIITB Professional Certificate Program in Data Science for Business Decision Making Master of Science in Data Science from University of Arizona Advanced Certificate Programme in Data Science from IIITB Professional Certificate Program in Data Science and Business Analytics from University of Maryland Data Science Courses

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.

## Top Data Science Skills to Learn

 Top Data Science Skills to Learn 1 Data Analysis Course Inferential Statistics Courses 2 Hypothesis Testing Programs Logistic Regression Courses 3 Linear Regression Courses Linear Algebra for Analysis

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.

## Read our popular Data Science Articles

 Data Science Career Path: A Comprehensive Career Guide Data Science Career Growth: The Future of Work is here Why is Data Science Important? 8 Ways Data Science Brings Value to the Business Relevance of Data Science for Managers The Ultimate Data Science Cheat Sheet Every Data Scientists Should Have Top 6 Reasons Why You Should Become a Data Scientist A Day in the Life of Data Scientist: What do they do? Myth Busted: Data Science doesnâ€™t need Coding Business Intelligence vs Data Science: What are the differences?

## Final thoughts

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Â Executive PG Programme 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.

## What is meant by an abstract data structure?

The Abstract Data Structure or Abstract Data Type (ADT) is a mathematical model of data structures that show the type of data stored, the operations supported by the data, and the types of operations parameters. With the help of ADT, users can find out about what each operation does. It cannot help in finding the working of the operations though. Different data structures can be used to perform abstract data structures. Specifying an ADT for the program is an excellent initial step in determining what data structure to employ in a program.

## What are the different types of data structures?

Data structures are classified into two types: linear and non-linear data structures. The elements of linear data structures are placed sequentially one after the other. They are simple to execute since the pieces are organized in a specific order. However, as the program's complexity grows, linear data structures may not be the ideal solution due to operational difficulties. Non-linear data structures donâ€™t have elements in a typical order. Instead, they are organized in a hierarchical order, with one element linked to one or more others.

## What features of data structures will stay relevant in the future?

Almost all features of Data structures are likely to remain relevant in the future because Data structures are at the heart of computer science. From basic arrays to Binary Search Trees and beyond, they serve critical roles in developing algorithms that are essentially ingrained in everyday life. Because of data structures, today's technology world is quick, efficient, and exact. The strategies used to modify data structures will become more indistinguishable.