This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What is a heap data structure? |
|
Answer» Heap is a special tree-based non-linear data structure in which the tree is a complete binary tree. A binary tree is said to be complete if all levels are completely filled except possibly the last level and the last level has all elements as left as possible. Heaps are of two types:
|
|
| 2. |
Which data structures are used for implementing LRU cache? |
|
Answer» LRU cache or Least Recently Used cache allows quick identification of an element that hasn’t been put to use for the longest time by organizing items in order of use. In order to achieve this, two data structures are used:
|
|
| 3. |
Define Red-Black Tree and its applications |
|
Answer» Red Black Trees are a type of self-balancing binary search tree. Rudolf Bayer invented it in 1972 and dubbed it "symmetric binary B-trees." A red-black tree is a Binary tree in which each node has a colour attribute, either red or black. By comparing the node colours on any simple path from the root to a leaf, red-black trees ensure that no path is more than twice as long as any other, ensuring that the tree is generally balanced. Red-black trees are similar to binary trees in that they both store their data in two's complementary binary formats. However, red-black trees have one important advantage over binary trees: they are faster to access. Because red-black trees are so fast to access, they are often used to store large amounts of data. Red-black trees can be used to store any type of data that can be represented as a set of values. Every Red-Black Tree Obeys the Following Rules:
Following are some real-time applications for the Red-Black Tree data structure:
|
|
| 4. |
Define Trie data structure and its applications |
|
Answer» The word "Trie" is an abbreviation for "retrieval." Trie is a data structure that stores a set of strings as a sorted tree. Each node has the same number of pointers as the number of alphabet characters. It can look up a word in the dictionary by using its prefix. Assuming that all strings are formed from the letters 'a' to 'z' in the English alphabet, each trie node can have a maximum of 26 points. Trie is also referred to as the digital tree or the prefix tree. The key to which a node is connected is determined by its position in the Trie. Trie allows us to insert and find strings in O(L) time, where L is the length of a single word. This is clearly faster than BST. Because of how it is implemented, this is also faster than Hashing. There is no need to compute a hash function. There is no need to handle collisions (like we do in open addressing and separate chaining) Another benefit of Trie is that we can easily print all words in alphabetical order, which is not easy with hashing. Trie can also perform prefix search (or auto-complete) efficiently. The main disadvantage of tries is that they require a large amount of memory to store the strings. We have an excessive number of node pointers for each node Following are some real-time applications for Trie data structure:
|
|
| 5. |
Define Segment Tree data structure and its applications. |
|
Answer» A segment Tree is a binary tree that is used to store intervals or segments. The Segment Tree is made up of nodes that represent intervals. Segment Tree is used when there are multiple range queries on an array and changes to array elements. The segment tree of array A[7] will look like this: Following are key operations performed on the Segment tree data structure:
Following are real-time applications for Segment Tree:
|
|
| 6. |
What is a B-tree data structure? What are the applications for B-trees? |
|
Answer» The B Tree is a type of m-way tree that is commonly used for disc access. A B-Tree with order m can only have m-1 keys and m children. One of the primary reasons for using a B tree is its ability to store a large number of keys in a single node as well as large key values while keeping the tree's height relatively small. A B-tree of order 4 is shown below in the image: Following are the key properties of a B-tree data structure:
Following are real-time applications of a B-Tree data structure:
|
|
| 7. |
What is AVL tree data structure, its operations, and its rotations? What are the applications for AVL trees? |
|
Answer» AVL trees are height balancing binary search trees named after their inventors Adelson, Velski, and Landis. The AVL tree compares the heights of the left and right subtrees and ensures that the difference is less than one. This distinction is known as the Balance Factor.
We can perform the following two operations on AVL tree:
An AVL tree can balance itself by performing the four rotations listed below:
Following are some real-time applications for AVL tree data structure:
|
|
| 8. |
What is the difference between the Breadth First Search (BFS) and Depth First Search (DFS)? |
||||||||||||||||||||
Answer»
|
|||||||||||||||||||||
| 9. |
What is graph data structure and its representations? What are the applications for graphs? |
|
Answer» A graph is a type of non-linear data structure made up of nodes and edges. The nodes are also known as vertices, and edges are lines or arcs that connect any two nodes in the graph. The following are the two most common graph representations: 1. Adjacency Matrix: Adjacency Matrix is a two-dimensional array with the dimensions V x V, where V is the number of vertices in a graph. Representation is simpler to implement and adhere to. It takes O(1) time to remove an edge. Queries such as whether there is an edge from vertex 'u' to vertex 'v' are efficient and can be completed in O(1). One of the cons of this representation is that even if the graph is sparse (has fewer edges), it takes up the same amount of space. Adding a vertex takes O(V^2). It also takes O(V) time to compute all of a vertex's neighbours, which is not very efficient. 2. Adjacency List: In this method, each Node holds a list of Nodes that are directly connected to that vertex. Each node at the end of the list is connected with null values to indicate that it is the last node in the list. This saves space O(|V|+|E|). In the worst-case scenario, a graph can have C(V, 2) edges, consuming O(V^2) space. It is simpler to add a vertex. It takes the least amount of time to compute all of a vertex's neighbours. One of the cons of this representation is that queries such as "is there an edge from vertex u to vertex v?" are inefficient and take O (V) in the worst case. |
|
| 10. |
Compare different implementations of priority queue |
||||||||||||||||
|
Answer» The following table contains an asymptotic analysis of different implementations of a priority queue:
|
|||||||||||||||||
| 11. |
What is a priority queue? What are the applications for priority queue? |
|
Answer» Priority Queue is an abstract data type that is similar to a queue in that each element is assigned a priority value. The order in which elements in a priority queue are served is determined by their priority (i.e., the order in which they are removed). If the elements have the same priority, they are served in the order they appear in the queue. Following are some real-time applications for priority queue:
|
|
| 12. |
What are some key operations performed on the Deque data structure? |
|
Answer» Following are the key operations available deque:
|
|
| 13. |
What is a deque data structure and its types? What are the applications for deque? |
|
Answer» A deque can be thought of as an array of items, but with one important difference: Instead of pushing and popping items off the end to make room, deques are designed to allow items to be inserted at either end. This property makes deques well-suited for performing tasks such as keeping track of inventory, scheduling tasks, or handling large amounts of data. There are two types of deque:
Following are some real-time applications for deque data structure:
|
|
| 14. |
What are tree traversals? |
|
Answer» Tree traversal is the process of visiting all the nodes of a tree. Since the root (head) is the first node and all nodes are connected via edges (or links) we always start with that node. There are three ways which we use to traverse a tree − 1. Inorder Traversal:
void printInorderTraversal(Node root) { if (root == null) return; //first traverse to the left subtree printInorderTraversal(root.left); //then print the data of node System.out.print(root.data + " "); //then traverse to the right subtree printInorderTraversal(root.right); }
2. Preorder Traversal:
void printPreorderTraversal(Node root) { if (root == null) return; //first print the data of node System.out.print(root.data + " "); //then traverse to the left subtree printPreorderTraversal(root.left); //then traverse to the right subtree printPreorderTraversal(root.right); }
3. Postorder Traversal:
void printPostorderTraversal(Node root) { if (root == null) return; //first traverse to the left subtree printPostorderTraversal(root.left); //then traverse to the right subtree printPostorderTraversal(root.right); //then print the data of node System.out.print(root.data + " "); }
Consider the following tree as an example, then:
|
|
| 15. |
What is binary search tree data structure? What are the applications for binary search trees? |
|
Answer» A binary search tree is a data structure that stores items in sorted order. In a binary search tree, each node stores a key and a value. The key is used to access the item and the value is used to determine whether the item is present or not. The key can be any type of value such as an integer, floating point number, character string, or even a combination of these types. The value can be any type of items such as an integer, floating point number, character string, or even a combination of these types. When a node is added to the tree, its key is used to access the item stored at that node. When a node is removed from the tree, its key is used to access the item stored at that node. A binary search tree is a special type of binary tree that has a specific order of elements in it. It has three basic qualities:
Following are some applications for binary tree data structure:
|
|
| 16. |
What is binary tree data structure? What are the applications for binary trees? |
|
Answer» A binary tree is a data structure that is used to organize data in a way that allows for efficient retrieval and manipulation. It is a data structure that uses two nodes, called leaves and nodes, to represent the data. The leaves represent the data and the nodes represent the relationships between the leaves. Each node has two children, called siblings, and each child has one parent. The parent is the node that is closest to the root of the tree. When a node is deleted from the tree, it is deleted from both its child and its parent. Following are some applications for binary tree data structure:
|
|