DSA Viva Questions
DSA Viva Questions
Ans) A data structure is a storage that is used to store and organize data. It is a way of arranging data on
a computer so that it can be accessed and updated efficiently.
Ans)(i) Linear data structure: Static data structure, Dynamic data structure
Ans) Data type is a collection of values and a set of operations on these values. Abstract data type refer
to the mathematical concept that defines the data type. It is a useful tool for specifying the logical
properties of a data type.
Q4) What are the various operations that can be performed on different Data Structures?
Ans) Singly Linked List is a Sequence of dynamically allocated Storage elements, each element of which
contains a pointer to its successor.
Ans) In Doubly Linked List each element contains two pointers: One Pointer points to its successor and
another to its predecessor.
Ans) Stack is an ordered collection of items into which items can be inserted and deleted from only one
end called as “Top” of the Stack. It is also called as LIFO list.
Ans) Is Stack is empty and POP operation is performed it is not possible to delete the items. This situation
is called Stack Underflow.
Q10) What is Stack Overflow?
Ans) If Stack is full and PUSH operation is performed it is not possible to insert or Push the new items into
the stack. This situation is called Stack Overflow.
Ans) i) Stacks are used to convert Infix expression into Postfix. ii) Stacks are used to Evaluate Postfix
Expression. iii) Stacks are used in recursion etc.
Ans) It is an ordered collection of items into which items can be inserted from one end called as REAR
end and items are deleted from other end called as FRONT end of the Queue. It is also called as FIRST IN
FIRST OUT.
Ans) Huffman’s algorithm is used for creating extended binary trees that have minimum weighted path
lengths from the given weights. It makes use of a table that contains the frequency of occurrence for each
data element.
Ans) Fibonacci search is a search algorithm that applies to a sorted array. It makes use of a divide-and-
conquer approach that can significantly reduce the time needed in order to reach the target element.
Where : hL is the Height of the left subtree and hR is the Height of the right subtree.
Ans) If a binary tree of height ‘h’ has exactly [2h+1 -1] nodes then that binary tree is called as Full Binary
Tree.
Ans) A binary tree is a 2-ary tree in which each node(N) has atmost 2 children (either 0 or 1). The node
with 2 children are called internal nodes, and the nodes with 0 children are called external nodes or leaf
nodes.
Ans) A Binary tree is complete binary tree if all levels are completely filled except possibly the last/lowest
level are full and in the last/lowest level all the items are on the left.
Q19) What is a Binary Search Tree?
Ans) A BST(Binary Search Tree) is a binary tree in which each node satisfies search property. Each node's
key value must be greater than all values in its left subtree and must be less than all values in its right
subtree.
Ans) Traversal is used to visit each node in the tree exactly once. A full traversal of a binary tree gives a
linear ordering of the data in the tree. There are 3 different type of tree traversal: (i) Inorder Traversal
(ii) Preorder Traversal (iii) Postorder Traversal
Ans) AVL tree is a self-balancing binary search tree with height-balanced condition. For every node the
height of left subtree and right subtree can be differ by at most 1.
Ans) A B+ Tree is a tree data structure which represents sorted data in a way that allows for efficient
insertion, retrieval and removal of records, each of which is identified by a key. It is a dynamic multilevel
index, with maximum and minimum bounds on the number of keys in each segment (usually called a
'block' or 'node')
Ans) A Binary Heap tree is a balanced binary tree where root node are compared with its children and
placed accordingly. Heap have two properties namely, structure and order property.
Q27) What is Structure Property?
Ans) It is a complete binary tree where all the levels except possibly the last/lower level are full and in the
last/lower level all the items are on the left. Due to this fact that binary heap is a complete binary it can
be implemented using a simple array.
Ans) The heap order property for MinHeap is 'a parent is less than (or equal to) its children' whereas for
MaxHeap 'a parent is greater than its children'.
Ans) Bubble sort is a simple sorting algorithm, it works by repeatedly stepping through the list to be sorted
comparing each pair of adjacent items and swapping if they are in the worng order.
Ans) Insertion sort is a simple comparison sorting algorithm, every iteration of insertion sort removes an
element from the input data and insert it into the correct position in the already sorted list until no input
element remains.
Ans) Insertion sort is a simple comparison sorting algorithm, the algorithm works as follows:
Ans) Merge sort is an O(nlogn) comparison-based divide and conquer sorting algorithm, it works as
follows:
Ans) Heap Sort is a comparison-based sorting algorithm which is much more efficient version of selection
sort, it works by determining the largest (or smallest) element of the list, placing that at the end (or
beginning)of the list, then continuing with the rest of the list, but accomplishes this task efficiently by
using a data structure called a heap. Once the data list has been made into a heap, the root node is
gurantedd to be the largest (or smallest) element.
Q34) What is Quick Sort?
Ans) Quick sort sorts by employing a divide and conquer strategy to divide a list into two sub-lists. The
steps are:
Reorder the list so the elements which are less than the pivot come before the pivot and the elements
greater than pivot come after it. After this partitioning the pivot is in its final positon.
Recursively sort the sub-list of lesser elements and the sub-list of greater elements.
Ans) A graph is a pair of sets (V,E), where V is the sets of vertices and E is the set of edges connecting the
pair of vertices.
Ans) A undirected graph is connected if there is a path from every vertex to every other vertex. A directed
graph with this property is called strongly connected.
Ans) A graph can be represented in two forms 'Adjacency matrix' and 'Adjacency list'.
Adjacency matrix is a two dimensional arrays where for each edge, (u,v) A[u,v] = true otherwise it
will be false. The space complexity to represent a graph using this is O(|V|2).
Adjacency list are used where each list stores adjacent vertices of the corresponding vertex. The
space complexity to represent a graph using this is O(|V|+|E|).
Ans) A Spanning tree is a graph which must include every vertex and if the graph contain n vertices,
spanning tree must contain exactly (n-1) edges and is a subgraph of G.
Ans) A Minimum Spanning tree is a spanning tree such that the summ of all the weights of edges in
spanning tree is minimum.
Q43) Explain algorithm for finding Minimum Spanning Tree?
Ans) There are 2 widely used algorithm for finding minimum spanning tree:
Prims Algorithm computes the minimum spanning tree by including appropriate vertex and thus one edge
into existing partially constructed tree in successive stages. The time complexity of the Prim’s Algorithm
is O((V+E)logV).
Kruskal Algorithm computes the minimum spanning tree by adding edges one by one into a growing
spanning tree.
Ans)
Stack Queue
Stack is a linear data structure where data is added Queue is a linear data structure where data is
and removed from the top. ended at the rear end and removed from the
front.
Stack is based on LIFO(Last In First Out) principle Queue is based on FIFO(First In First Out) principle
Insertion operation in Stack is known as push. Insertion operation in Queue is known as eneque.
Delete operation in Stack is known as pop. Delete operation in Queue is known as dequeue.
Only one pointer is available for both addition and Two pointers are available for addition and
deletion: top() deletion: front() and rear()
Used in solving recursion problems Used in solving sequential processing problems
Q45) What is the difference between the Breadth First Search (BFS) and Depth First Search (DFS)?
Ans)
Ans) 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.
Ans) Heap is a special tree-based non-linear data structure in which the tree is a complete binary tree.
Heaps are of two types: (i) Max-Heap (ii) Min-Heap
Ans) In a Max-Heap the data element present at the root node must be the greatest among all the data
elements present in the tree.
Ans) In a Min-Heap the data element present at the root node must be the smallest (or minimum) among
all the data elements present in the tree.
Q50) Explain the difference between file structure and storage structure?
Ans) File Structure: Representation of data into secondary or auxiliary memory say any device such as a
hard disk or pen drives that stores data which remains intact until manually deleted is known as a file
structure representation.
Storage Structure: In this type, data is stored in the main memory i.e RAM, and is deleted once the
function that uses this data gets completely executed.
The difference is that the storage structure has data stored in the memory of the computer system,
whereas the file structure has the data stored in the auxiliary memory.
Q63) Difference between Linear and Non-Linear Data structures give examples
Q70) How to Implement Binary Tree using Array and Linked List?
Q72) How to Implement Circular Queue using Array and Linked List?
Q78) List out the operations of Singly and doubly linked list.