Data Structure Interview Questions – Set 04

What is a Stack?

Stack is an ordered list in which, insertion and deletion can be performed only at one end that is called the top. It is a recursive data structure having pointer to its top element. The stack is sometimes called as Last-In-First-Out (LIFO) list i.e. the element which is inserted first in the stack will be deleted last from the stack.

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

The heterogeneous linked list contains different data types, so it is not possible to use ordinary pointers for this. For this purpose, you have to use a generic pointer type like void pointer because the void pointer is capable of storing a pointer to any type.

What is a postfix expression?

An expression in which operators follow the operands is known as postfix expression. The main benefit of this form is that there is no need to group sub-expressions in parentheses or to consider operator precedence.

The expression “a + b” will be represented as “ab+” in postfix notation.

What are the scenarios in which an element can be inserted into the circular queue?

  • If (rear + 1)%maxsize = front, the queue is full. In that case, overflow occurs and therefore, insertion can not be performed in the queue.
  • If rear != max – 1, the rear will be incremented to the mod(maxsize) and the new value will be inserted at the rear end of the queue.
  • If front != 0 and rear = max – 1, it means that queue is not full therefore, set the value of rear to 0 and insert the new element there.

Mention the data structures which are used in graph implementation.

For the graph implementation, following data structures are used.

  • In sequential representation, Adjacency matrix is used.
  • In Linked representation, Adjacency list is used.

How can AVL Tree be useful in all the operations as compared to Binary search tree?

AVL tree controls the height of the binary search tree by not letting it be skewed. The time taken for all operations in a binary search tree of height h is O(h). However, it can be extended to O(n) if the BST becomes skewed (i.e. worst case). By limiting this height to log n, AVL tree imposes an upper bound on each operation to be O(log n) where n is the number of nodes.

Which data structures are used in BFS and DFS algorithm?

  • In BFS algorithm, Queue data structure is used.
  • In DFS algorithm, Stack data structure is used.

Describe the types of Data Structures?

Data Structures are mainly classified into two types:

Linear Data Structure: A data structure is called linear if all of its elements are arranged in the sequential order. In linear data structures, the elements are stored in a non-hierarchical way where each item has the successors and predecessors except the first and last element.

Non-Linear Data Structure: The Non-linear data structure does not form a sequence i.e. each item or element is connected with two or more other items in a non-linear arrangement. The data elements are not arranged in the sequential structure.

What is the maximum number of nodes in a binary tree of height k?

2k+1-1 where k >= 1

List the area of applications where stack data structure can be used?

  • Expression evaluation
  • Backtracking
  • Memory Management
  • Function calling and return