# Data Structure Interview Questions in C

## Data Structure Interview Questions in C

“Data Structure Interview Questions in C”

If you are looking for Data Structure Interview Questions in C then you are at correct place. This page will provide you with the most important questions and answers to the data structure in C.

PrepInsta will help you throughout the Technical Interview process by providing all the updated information about Technical Interview followed by HR and MR Round.

Click on the button given below to cover all the important points of Interview and Prepare well !! ## Data Structure: Definition

A data structure is a named location that can be used to store and organize data. And, an algorithm is a collection of steps to solve a particular problem. Learning data structures and algorithms allow us to write efficient and optimized computer programs.

If you want to have more knowledge about this then, you can go through this page.

## Commonly Asked DSA Interview Questions and Answers in C

#### 1. State the properties of B Tree?

Solution:-A B tree of order m contains all the properties of an M way tree. In addition, it contains the following properties.

• In a B-Tree, each node has a maximum of m children.
• Except for the root and leaf nodes, every node in a B-Tree has at least m/2 children.
• There must be at least two root nodes.
• The level of all leaf nodes must be the same.

#### 2.Write a recursive C function to calculate the height of a binary tree.

Solution:-

`int countHeight(struct node* t)  {      int l,r;      if(!t)          return 0;      if((!(t->left)) && (!(t->right)))          return 0;      l=countHeight(t->left);      r=countHeight(t->right);      return (1+((l>r)?l:r));  }         `

#### 3.Write the recursive C function to count the number of nodes present in a binary tree.

Solution:-

`int count (struct node* t)  {      if(t)      {          int l, r;          l = count(t->left);          r=count(t->right);          return (1+l+r);      }      else       {          return 0;      }  }  `

#### 4. What is the minimum number of queues that can be used to implement a priority queue?

Solution:- It is enough to create two queues. The data elements are stored in one queue, while the priorities are stored in another.

#### 5. If you are using C language to implement the heterogeneous linked list, what pointer type should be used?

Solution:- Since the heterogeneous linked list includes various data types, ordinary pointers cannot be used. You must use a generic pointer type like void pointer for this purpose, as the void pointer may store a pointer to any type.

#### 6. List some applications of queue data structure.

Solution:-

• The following are some examples of queue applications:
Queues are often used to create waiting lists for a single shared resource, such as a printer, disc, or CPU.
• Pipes, file IO, and sockets all use queues for asynchronous data transfer (where data is not transmitted at the same rate between two processes).
• Many applications, such as MP3 media players and CD players, use queues as buffers.
• Queues are used in media players to keep track of the playlist and add and delete songs from it.
• In operating systems, queues are used to handle interruptions.

#### 7. Can we apply Binary search algorithm to a sorted Linked list?

Solution:- No, we can’t use the binary search algorithm on a sorted linked list because it’s difficult to find the index of the middle variable.

#### 8. When can you tell that a Memory Leak will occur?

Solution:- A memory leak occurs when a program fails to free a dynamically allocated block of memory.

#### 9.What are the differences between B tree and B+ tree?

Solution:- B Tree

• Search keys can’t be saved more than once.
• Data can be stored in both internal and leaf nodes.
• Since data can be found on both internal and leaf nodes, searching for certain information takes longer.
• Internal node deletion is extremely difficult and time-consuming.
• It is not possible to link leaf nodes.

B+ Tree

• It’s possible to have multiple search keys.
• The leaf nodes are the only places where data can be saved.
• Since data can only be found on the leaf nodes, searching is comparatively faster.
• Since elements are always removed from the leaf nodes, deletion will never be a complicated method.
• To make search operations more effective, leaf nodes are linked together.

#### 10.What are the advantages of Selection Sort?

Solution:-

• It is quick and straightforward to enforce.
• It’s suitable for small data sets.
• It’s 60% more effective than bubble sorting.

#### 11.What is a doubly-linked list?

Solution:-

A doubly linked list is a more complicated form of a linked list in which each node has a pointer to both the previous and next node in the chain. A node in a doubly-linked list is made up of three parts:

• node data
• pointer to the next node in sequence (next pointer)
• pointer to the previous node (previous pointer).

#### 12.Are linked lists considered linear or non-linear data structures?

Solution:-

Depending on the case, a connected list may be called both a linear and non-linear data structure.

• It is classified as a non-linear data structure based on data storage.
• It is classified as a linear data structure based on the access strategy.

.

#### 13.Which notations are used in Evaluation of Arithmetic Expressions using prefix and postfix forms?

Solutions:- Polish and Reverse Polish notations.

#### 14.What is an array?

Solution:- Arrays are collections of data objects of related types located in contiguous memory locations. It is the simplest data structure in which each data element’s index number can be used to access it at random.

#### 15.How to reference all the elements in a one-dimension array?

Solution:- It is possible to accomplish this using an indexed loop with a counter that runs from 0 to the array size minus one. By using the loop counter as the array subscript, you can refer to all of the elements in order.

#### 16. When is a binary search best applied?

Solution:-

A binary search is an algorithm that works best when the elements in a list are either sorted or in order. The list is searched from the middle, so if that middle value is not the target search key, it will check to see if the search can begin on the lower half or the upper half of the list. After that, the break and quest will proceed in the same manner.

#### 17. In what areas do data structures are applied?

Solution:-

Data structures are needed in almost every situation involving data. Algorithms involving efficient data structures are used in a variety of fields, including numerical analysis, operating systems, artificial intelligence, compiler design, database management, graphics, and statistical analysis, to name a few.

#### 18. What is an ordered list?

Solution:-

An ordered list is one in which the value of each node’s key component determines its location in the list, such that the key values form an increasing sequence as the list is traversed.

#### 19. What is merge sort?

Solution:-

Merge sorting is a divide-and-conquer method of data sorting. To construct larger sorted lists, adjacent data in a sequence is combined and sorted. These sorted lists are then combined once more to create a larger sorted list, and so on until there is just one sorted list left.

#### 20. Differentiate NULL and VOID

Solution:-

The difference between Null and Void is that Null is a value and Void is a data type identifier. A Null value for a variable means that it has no value. The void is used to indicate pointers that do not have an initial size.