## Introduction To Data Structures And Algorithms Interview Questions And Answers

Data Structure is a way that defines, stores, and retrieves the data in a structural and systematic format. A data structure contains different types of data sets. Different kinds of data are available to different kinds of applications, and some of the data are highly specialized to specific tasks. An algorithm is a step by step procedure with a set of instructions to execute appropriately to get the desired output. In mathematics and computer science, an algorithm usually means a small procedure that solves a recurrent problem.

If you are looking for a job related to Data Structures And Algorithms, you need to prepare for the 2021 Data Structures And Algorithms Interview Questions. Though every interview is different and the scope of a job is also different, we can help you out with the top Data Structures And Algorithms Interview Questions and Answers, which will help you take the leap and succeed in your interview.

Below are the top 2021 Data Structures And Algorithms Interview Questions and Answers. These top questions are divided into two parts are as follows:

### Part 1 – Data Structures And Algorithms Interview Questions (Basic)

This first part covers the basic Interview Questions and Answers.

#### 1. What is a data structure?

**Answer:**

A data structure is a way of defining, storing & retrieving data in a structural & systematic way. A data structure may contain a different type of data item. Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks.

#### 2. What are the various data-structures available?

**Answer:**

Data structure availability may vary by programming language. Commonly available data structures are the list, arrays, stack, queues, graph, tree, etc.

4.7 (3,220 ratings)

View Course

#### 3. What is an algorithm?

**Answer:**

An algorithm is a step by step procedure, which defines a set of instructions to be executed in certain order to get the desired output. A computer program can be viewed as an elaborate algorithm. In mathematics and computer science, an algorithm usually means a small procedure that solves a recurrent problem.

Let us move to the next Data Structures And Algorithms Interview Questions

#### 4. Differentiate file structure from the storage structure?

**Answer:**

Actually, the key difference is the memory area that is being accessed. When dealing with the structure that resides the computer system’s main memory, this is referred to as storage structure. When dealing with an auxiliary structure, we refer to it as file structures.

#### 5. What is a linked-list?

**Answer:**

A linked-list is a list of data-items connected with links, i.e. pointers or references. Most modern high-level programming language does not provide the feature of directly accessing a memory location; therefore, linked-list is not supported in them or available in the form of inbuilt functions. In computer science, a linked list is a linear collection of data elements, in which their physical placement does not give linear order in memory. Instead, each element points to the next. It is a data structure consisting of a group of nodes that together represent a sequence.

#### 6. What is the stack?

**Answer:**

In the data-structure, a stack is an Abstract Data Type (ADT) used to store and retrieve values in the Last In First Out method. The stack is the memory set aside as scratch space for a thread of execution.

#### 7. Why do we use stacks?

**Answer:**

A stack structure restricts dramatically how elements are inserted, retrieved, and removed: The most recently inserted element in the stack is the only one that can be retrieved or removed. Stacks follow the LIFO method and the addition and retrieval of a data item take only Ο(n) time. Stacks are used where we need to access data in the reverse order of their arrival. Stacks are used commonly in recursive function calls, expression parsing, depth-first traversal of graphs, etc.

### Part 2 – Data Structures And Algorithms Interview Questions (Advanced)

Let us now have a look at the advanced Interview Questions.

#### 8. What operations can be performed on stacks?

**Answer:**

The below operations can be performed on a stack −

- push() − adds an item to stack – Insertion
- pop() − removes the top stack item -Deletion
- peek() − gives a value of a top item without removing it -Traversal
- isempty() − checks if a stack is empty –Null check
- isfull() − checks if a stack is full –No space

#### 9. What is a queue in the data-structure?

**Answer:**

The queue is an abstract data structure, somewhat similar to stack. In contrast to stack, a queue is opened at both ends. One end is always used to insert data (enqueue), and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.

#### 10. What is linear searching?

**Answer:**

Linear search tries to find an item in a sequentially arranged data type. These sequentially arranged data items known as array or list, are accessible in incrementing memory location. Linear search compares expected data item with each of the data items in list or array. The linear search’s average case time complexity is Ο(n), and worst-case complexity is Ο(n2). Data in target arrays/lists need not be sorted.

#### 11. What is a binary search?

**Answer:**

A binary search works only on sorted lists or arrays. This search selects the middle, which splits the entire list into two parts. First, the middle is compared.

This search first compares the target value to the mid of the list. If it is not found, then it decides on the weather. In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array.

#### 12. What is a graph?

**Answer:**

A graph is a pictorial representation of a set of objects where links connect some pairs of objects. The interconnected objects are represented by points termed as vertices, and the links that connect the vertices are called edges. A graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed graph.

#### 13. What is a recursive function?

**Answer:**

A recursive function is one that calls itself, directly or calls a function that in turn calls it. Every recursive function follows the recursive properties − base criteria where functions stop calling themselves and progressive approach where the functions try to meet the base criteria in each iteration. An important application of recursion in computer science is defining dynamic data structures such as Lists and Trees.

#### 14. What is a tower of Hanoi?

**Answer:**

Tower of Hanoi, is a mathematical puzzle that consists of three towers (pegs) and more than one ring. All rings are of different sizes and stacked upon each other where the large disk is always below the small disk. The aim is to move the tower of a disk from one peg to another, without breaking its properties. This game’s objective is to move the disks one by one from the first peg to the last peg. And there is only ONE condition, and we cannot place a bigger disk on top of a smaller disk.

#### 15. Give some examples of greedy algorithms?

**Answer:**

The below-given problems find their solution using a greedy algorithm approach −

- Travelling Salesman Problem
- Prim’s Minimal Spanning Tree Algorithm
- Kruskal’s Minimal Spanning Tree Algorithm
- Dijkstra’s Minimal Spanning Tree Algorithm
- Graph – Map Coloring
- Graph – Vertex Cover
- Knapsack Problem
- Job Scheduling Problem

### Recommended Article

This has been a guide to List Of Data Structures And Algorithms Interview Questions and Answers so that the candidate can crackdown these Interview Questions easily. You may also look at the following articles to learn more –