interview questions regarding data structures

Q6: What is a heap data structure?

Ans:Heap is a particular non-linear tree-based data structure where the tree is a full binary tree. A binary tree should be finished if all levels are filled except for the last level, and the last level contains all items to the left as feasible. There are two types of Heaps:

  • Max-Heap:
    • In a Max-Heap the data element present at the root node must be largest among all the data elements present in the tree.
    • For all sub-trees of the binary tree, this characteristic should be true recursively.
  • Min-Heap:
    • In a Min-Heap, the root node data element should be the smaller (or least) of all tree-presented data components.
    • For all of the subtrees of the binary tree, this attribute should be recursively true.

Q7: What are the applications of graph data structure?

Ans:Graphs are utilized in many applications. Graphs. Some of the following are:

  • Social network graphs to determine the flow of information on websites such as Facebook, Linked In, etc.
  • Neural network graphs with neurons and edge synapses representing neurons
  • Transportation grids with nodes stations and graph edges are routes.
  • Power or water utility graphs with connecting vertices that edge the cables or pipes that link them.
  • Shortest distance from the algorithms of two endpoints.

Q8: How are the elements of a 2D array are stored in the memory?

Ans: There are two methods by which 2D array elements can be retained in the memory.

  • Row-Major Order:   All 2D array rows are stored contiguously in the memory when ordered row-major. First, the first row of the display is stored in full in the memory, and then the second line of the display is stored in full in the memory until the last row.
  • Column-Major Order:  With the main column sequence all 2D array columns are contiguously saved to memory. First, the first array column is saved fully in the memory, and then the second array row is stored entirely in the memory, etc., till the last array column.

Q9: How do you know when to use DFS over BFS?

Ans:The use of DFS depends greatly on the structure and locations of the search tree/graph. The ideal scenarios for us to employ DFS are as follows:

  • A first search breadth (BFS) could be beneficial if the answer is known to be not distant from tree root.
  • A high depth searcha (DFS) may take a very lengthy time, although BFS could be quicker when the tree is very deep and solutions are rare.
  • A BFS may demand too much memory if the tree is too large, and maybe totally unworkable. In such instances, we resort to DFS.
  • We choose DFS when solutions are frequent but deep in the tree.

Q10: How does a selection sort work for an array?

Ans:The selection type is a somewhat obvious but not necessarily efficient sorting method. The smallest element is initially placed at subscript zero and turned on with the item, placing the smallest element in the first position.

The lowest element left in the subscription is then situated next to subscriptions 1 through n-1, whereas the second smallest element is placed in the second position with subscript 1. Till the last element, processes are repeated in the same way.