# data structures interview questions and answers for freshers

** Q. What is Data?**

Data is a raw material for data processing. It refers to unprocessed

information.

**Q. What is information?**

It is the data that has been processed in a meaningful form to the one who receives it.

**Q. What is Data Structure?**

It is the specified format for organizing and storing data.

**Q. What are the different types of data structures?**

Data Structures are divided into two categories:

1. Primitive Data Structure (int, char, float, double, etc)

2. Non Primitive Data Structure

Non Primitive datatype is further divided into two categories :

a. Linear (Array, linked list, stack, queue)

b. Non-Linear (Tree, Graph)

**Q. What are the different operations applied to Data Structures?**

Traversing, Searching, Insertion, deletion, sorting, and searching.

**Q. Give some areas where data structures are used?**

Data Structure provides us the means to manage large amounts of data efficiently for uses such as large databases and internet indexing services.

**Q. Name the type of data structure used in the following:**

1. Hierarchical Data Model: Tree

2. RDBMS: Array

3. Network Data Model: Graph

**Q. What is an Algorithm?**

The algorithm denotes a sequence of steps to solve a particular problem.

**Q. What are different approaches to develop algorithms?**

Greedy, Divide and Conquer, Dynamic Programming.

**Q. What is Hashing?**

Hashing is the process of mapping a given value with a particular key for faster access to elements. The efficiency of mapping depends on the efficiency of the hash function used.

**Q. Explain the Greedy algorithm?**

Algorithms following greedy approach build-up solution step by step. It is mostly used in optimization problems. It makes an optimal choice at each step, to solve the entire problem.

Example: Dijkstra Algo, Prim’s Algo, Kruskal.

**Q. What is dequeue operation?**

It is a double-ended queue. In the double-ended queue, insertion, and deletion takes place at both ends.

**Q. Explain Divide & Conquer algorithm?**

Algorithms following the D&C approach works in two steps-Divide & Combine. At first, we divide the problem into subparts, solve them individually and then combine the result of all subparts to get a collective solution.

Example: Binary Search, Merge Sort.

**Q. Explain Dynamic Programming?**

Dynamic Programming is used to find the most optimized solution by eliminating the standard recursive calls.

Example: Finding Fibonacci series.

**Q. What are the parameters that are cared for in an algorithm?**

Time Complexity and Space Complexity.

**Q. What are Abstract Datatypes?**

ADTs are the special data types constructed from the collection of data items.

Example: Array, Linked list, Queue

**Q. What is the need for Data Structure?**

It tells how data can be stored and accessed at its elementary level. It

allows us to manage a huge amount of data efficiently. It provides different techniques for searching and sorting data

**Q. Explain the role of malloc(), calloc(), realloc() and free()in dynamic memory allocation.**

1. malloc() is one of the functions used for dynamic memory allocation. It takes up single arguments, which denotes the number of bytes to be allocated.

malloc() is faster than calloc().

Syntax : int *p = (int *)malloc(sizeof(int))

2. calloc() is one of the functions used for contiguous dynamic memory allocation. It takes up two arguments, in which the first argument denotes the number of bytes to be allocated, and the second argument denotes the size of each block. It initializes allocated memory by 0.

3.The realloc() function is used to resize allocated memory without losing old data.

Syntax: void *realloc(void *p, size_t newsize);

4.free() is use to free the memory block that had been allocated

dynamically.

**Q. What is Array?**

Array refers to the collection of similar data items.

Syntax – int a[10];

Here, a is the array having size 10.

**Q. What is a 2D Array?**

2D array or 2-dimensional array is an array of arrays. It is used to store the data in tabular form in the terms of rows and columns.

It is represented as int a[m][n], where m denotes the number of rows and n denotes the number of columns.

**Q. What is Linked List?**

A linked list is a list of data elements linked to one another. In a linked list, each element consists of a node, with two fields each :

the data field (a variable that denotes the content of node)

next (pointer variable that stores the address of next node)Types of Linked List :

1. Singly LL

2. Double LL

3. Circular LL

4. Circular Double LL

**Q. How the linked list is better than an array?**

1. The array is static and the Linked list is dynamic.

2. Linked list avoids memory wastage.

**Q. What do you mean by Stack?**

Stack is a linear data structure in which insertion and deletion are done only from one end. It follows the LIFO (Last In First Out) order.

**Q. What are the operations that we can apply to the stack?**

Push: Insertion of element on top

Pop: Deletion of element on top

**Q. What is Stack Overflow & Stack Underflow?**

Stack Overflow: Condition when the array is full and the user requests for another insertion Stack Underflow: Condition when the array is empty and user requests for deletion operation

**Q. In how ways we can implement stack?**

Two ways: using arrays and linked list

**Q. Differentiate between binary tree and tree.**

In an ordinary tree, a parent may have many children, but a binary tree can have at most 2 children.

**Q. What is peek() operation in Stack?**

It returns a topmost element of Stack.

What is the condition of Stack Overflow?

top=n-1, where n is the number of elements in the stack.

**Q. Give some applications of the stack?**

1. For data reversal.

2. Evaluating arithmetic operations.

3. To calculate postfix expressions.

4. For parsing.

5. For simulation of recursion.

**Q. What is recursion?**

Recursion is the process in which a function is called by itself again &

again.

**Q. What is Queue?**

**Q. Differentiate between B-Tree & B+ Tree?**

**Q. Define Graph Data Structure?**

**Q. What is linear searching?**