Data Strctures Question Bank -22.07.24
Data Strctures Question Bank -22.07.24
10. Illustrate the differences between linear linked list and circular linked list. (Apr 2019)
S.No Linear Linked List Circular Linked List
In Linear Linked List, the nodes are
Circularly linked list is a linked list where all
1 connected in a linear manner from
nodes are connected to form a circle.
first node to the last node.
The last node next address points The last node next address points header
2
NULL. node.
We can traverse the whole list by We can traverse the whole list by starting
3
starting from first node. from any node.
11. What are the advantages of doubly linked list over singly linked list?. (APR 2023)
I. Reversing the doubly linked list is very easy as doubly linked list is
bidirectional.
II. Deletion of nodes is easy as compared to a Singly Linked List. A singly
Linked list deletion requires a pointer to the node and previous node to be
deleted but in the doubly linked list, it only required the pointer which is to be
deleted.
12. Compare Singly and Doubly Linked List.
S.No Singly Linked List Doubly Linked List
In doubly Linked List, each node has two
In singly Linked List, each node has
1 pointers to point the next node and
pointer to point the next node.
previous node.
2 Reverse traversal is not possible. Reverse traversal is possible.
Deletion of nodes is difficult in Singly Deletion of nodes is easy as compared to
Linked List. A singly linked list a Singly Linked List. The doubly linked list
3 deletion requires a pointer to the requires only the pointer which is to be
node and previous node to be deleted.
deleted.
linked using pointers. Representation: A multilevel linked list is represented by a pointer to the
first node of the linked lists.
Use cases of Multi-Linked Lists:
Some use cases of a multi-linked list are:
Multiple orders of one set of elements
Representation of a sparse matrix
List of List
19. Write the algorithmic steps of radix sort.
Radix Sort:
Radix sort is sorting algorithm for integers. In Radix sort, there is digit by digit sorting
is performed starting from the least significant digit to the most significant digit.
Algorithmic Steps:
1. Find the maximum element in the given list.
2. Find the number of digits (d) in the maximum element.
3. Create ‘d’ buckets of size 0 to 9.
4. For i= 1 to d do
i. Sort the array elements using digits at the ith place
Part B
1. What are the various operations on array? Write a procedure to insert an element in
the middle of the array. (7). (Nov 2018)
2. Explain insertion and deletion operations in array. (APR 2023)
3. Explain various operations of singly linked list in detail. (NOV 2022)
4. What are the ways to insert a node in the linked list? Write an algorithm for inserting a
node before a given node in the linked list. (6). (Nov 2018)
Insertion before the specified node Operation:
• The list and the element to be inserted is given. The new element is inserted before
the specified node of the linked list. It is necessary to traverse the node to reach the
specified node before which the new node will be inserted.
• Assume the specified node as ‘p’.
• After the insertion of new element, the new element will point the node ‘p’ and the next
of previous node of ‘p’ will point the new element.
Before Insertion:
During Insertion:
header
head
10 20 30
45
Changes:
1. newnode->next=1500 (address of 20) (identified in the name of p)
2. pre->next=3100 (address of 45) (identified in the name of newnode)
After Insertion:
header
head
10 20 30
45
Implementation:
3100(newnode)
}
else
{
pre=p;
p=p->next;
}
}
}
5. Explain insertion operations in Linked list. How nodes are inserted after the specified
node? (Nov 2019)
6. Explain various operations of doubly linked list in detail.
7. Explain various operations of single circularly linked list in detail.
8. Explain various operations of double circularly linked list in detail.
9. Write a procedure to delete the last node from circular linked list. (Nov 2018)
10. State the polynomial representation of 6x 3+9x2+7x+1 using linked list. Write a
procedure to add and multiply two polynomials and explain with suitable example. (Nov
2018) (Nov 2022) (APR 2023) (NOV 2023)
11. Write procedures or pseudo codes for the following operations in circularly linked list.
(Nov 2021)
a. Insertion
b. Deletion
c. Count
void count(struct csnode *head)
{
struct csnode *p;
int count=0;
p=head->next;
while(p!=head)
{
count=count+1;;
p=p->next;
}
printf(“the no of nodes = %d, count);
}
Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai
9
12. Implement the polynomial addition using singly linked list. Have procedures for
insertion, comparison and addition of node values of this polynomial application. (Nov
2021)
13. Infer how list and linked list are stored in memory with an example and write a function
to check the current position of the last element in the linked list. (Nov 2023)
14. Explain how linked list are used to sort the following elements using radix sort. (NOV
2023)
A=[432, 8, 530, 90, 88, 231, 11, 45, 677, 199]
15. Differentiate circular linked list and doubly linked list during insertion and deletion.
(NOV 2023)
Part C
1. You are given a Linked List L, another Linked List P containing integers stored in
ascending order. The operation Printlots(L,P) will print the elements in L that are in
positions specified by P. For instance, if P=1,3,4,6, the first, third, fourth and sixth
elements in L are printed. Write the procedure for Printlots(L,P).
2. Write a routine to delete all duplicates in array A[0..n-1].
3. Consider the following problem scenario: In recording scores for a golf tournament,
we enter the name and score of the player as the player finishes. This information is
to be retrieved in each of the following ways:
i. Scores and names can be printed in order by ascending or by
descending scores.
ii. Given the name of a player, other players with the same score can be
printed.
Give procedures by using the doubly linked list data structure, for implementing
a solution for the problem. (Nov 2021)
UNIT-II
Part-A
1. Define stack.
Stack is a list with the restrictions on insertion and deletion.
Insertions and deletions are done at only one end of the list and that end is
identified by the top pointer.
The insertion operation in stack is called as Push and deletion operation in
stack is called as pop.
Stack is called as LIFO (Last In First Out) structure. i.e Last inserted item will
be deleted first.
Stack Model
Step 3 : Read the character ‘ch’ from Infix expression, one character at a time.
Step 4 : Test ‘ch’
Step 4.1: If ‘ch’ is an operand, append it with Postfix expression.
Step 4.2: If ‘ch’ is an operator, do the following,
a. Step 4.2.1 : If the stack contains ‘#’ or ‘(‘ on the top, push the ‘ch’ on to
the stack.
b. Step 4.2.2 : If ‘ch’ is ‘(‘, push it onto the stack.
c. Srep 4.2.3 : If ‘ch’ is ‘)’, pop the symbols from the stack and append
them onto the postfix expression until ‘(‘ is encountered. Then discard
both ‘(‘ and ‘)’.
d. Step 4.2.4 : If the ‘ch’ has higher priority than the operator in the top
of the stack, push the ‘ch’ on to the stack.
e. Step 4.2.5 : If the ‘ch’ has lower priority than the operator in the top of
the stack, pop the symbols from the stack and append them onto the
postfix expression until ‘ch’ has lower priority. Then push ‘ch’ on to the
stack.
f. Step 4.2.6 : If ‘ch’ has the same priority with the top of the stack then
use the associativity rules. If the associativity is from left to right, then
pop and append the top of the stack to the postfix and push the ‘ch’ onto
the stack. If the associativity is from right to left, then push ‘ch’ onto the
stack.
g. Step 4.2.7 : If the ‘ch’ is ‘#’, then pop all the symbols from the stack
and append them onto the postfix expression.
Step 5 : Repeat steps 3-4 until ‘#’ delimiter is encountered in the infix expression.
5. Define queue. (NOV 2022)
Queue is a list with the restrictions on insertion and deletion.
Insertions are done at one end of the list (identified by the rear pointer) and
deletions are done at another end of the list (identified by the front pointer).
The insertion operation in queue is called as Enqueue and deletion operation
in queue is called as Dequeue.
Queue is called as FIFO (First In First Out) structure. i.e First inserted item will
be deleted first.
Queue Model
16. Write the algorithm to evaluate the postfix expression using stack.
Algorithm for evaluating Postfix expression using stack
Input : Postfix expression
Output : Result of the expression
Step 1 : Append ‘#’ delimiter at the end of the given postfix expression.
Step 2 : Push ‘#’ onto the stack.
Step 3 : Read the character ‘ch’ from postfix expression, one character at a time.
Step 4 : Test ‘ch’
Step 4.1: If ‘ch’ is an operand, push ‘ch’ onto the stack.
Step 4.2: If ‘ch’ is an operator, then pop two entries from the stack, the first
popped entry is operand 2 and the second popped entry is operand 1. Apply
‘ch’ on operand 1 and operand 2. The result is pushed on to the stack.
Step 4.3: If ‘ch’ is ‘#’, then pop from the stack, that will be the result of given
postfix expression.
Step 5 : Repeat steps 3-4 until ‘#’ delimiter is encountered in the postfix expression.
Input-restricted queue:
The input-restricted queue means that some restrictions are applied to the
insertion. In input-restricted queue, the insertion is applied to one end while the deletion is
applied from both the ends.
Output-restricted queue:
The output-restricted queue means that some restrictions are applied to the
deletion operation. In an output-restricted queue, the deletion can be applied only from
one end, whereas the insertion is possible from both ends.
20. Write the difference between circular queue and double ended queue. (Nov 2023)
S.No Circular Queue Double ended Queue
In a Circular queue, the elements In Double-ended queue, the insertion
1 are in sequential order but its end and deletion can be done from both
is attached to the starting ends.
But there can be some in between
In a circular queue, there is no in-
2 spaces in the double-ended queue
between space in the queue.
due to the deletion of the elements
There are two types in double ended
There is only one type in circular
3 queue. They are input restricted
queue.
queue and output restricted queue.
Part-B
1. Write the procedures for performing significant operations on stack data structure.
Apply stack to convert the following infix expression to postfix expression
a + b / (d - e ) – f. (Nov 2021)
2. Outline the pseudo code for performing the following operations in the stack using
array implementation. (NOV 2023)
i. Create
ii. Push
Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai
16
iii. Pop
iv. Stack Top
3. Write an algorithm for push and pop operations on stack using linked list. (Nov 2019)
(APR 2023)
4. Write the procedures to convert the infix expressions into postfix and steps involved in
evaluating postfix expression. Convert the expression A-(B/C+(D%E*F)/G)*H into
postfix form. Evaluate the postfix expression 9 3 4 * 8 + 4 / - (Nov 2018) (Nov 2022)
(Nov 2023)
5. Write the procedures for performing significant operations on queue data structure.
Write any four applications of queue. (Nov 2021)
6. Outline the pseudo code for performing the following operations in the queue using
array implementation. (NOV 2023)
i. enqueue
ii. dequeue
iii. isfull
iv. isempty
7. Write an algorithm for enqueue and dequeue operations on queue using linked list.
8. What are circular queues? Write the procedure to insert to the circular queue and
delete an element from the circular queue in array implementation. (Nov 2018)
(APR 2023)
9. What is a dequeue? Explain its operations with examples. (Nov 2019) (Nov 2022)
10. Identify how stacks are used for checking whether an expression is balanced or not for
every left and right brace, bracket and parenthesis. (Nov 2023)
11. Convert the following infix into postfix using stack. (Nov 2023)
i. ((A-(B+C)*D)$(E+F))
ii. (A/(B-C+D))*(E-A)*C
UNIT-III
Part-A
1. What are priority queues? What are the ways to implement priority queues? (Nov
2018)
a. Every element in a priority queue has some priority associated with it.
b. An element with the higher priority will be deleted before the deletion of the
lesser priority.
c. If two elements in a priority queue have the same priority, they will be
arranged using the FIFO principle.
Implementations:
Priority queue can be implemented with singly linked list, Binary Search Tree
and Binary Heap.
2. For the tree given below, find the siblings of ‘E’ and height of the tree? (Nov 2018)
5. Define Binary Search Tree. (Nov 2019) (Apr 2023) (Nov 2023)
Binary search tree is a binary tree in which all the nodes in left subtree of the
node has lesser value and all the nodes in right subtree of the node has greater value.
Ex:
6. The priority queue is implemented with max heap. The level order traversal of the max
heap is 10,8,5,3,2. After the insertion of 11 and 7, what is the level order traversal the
heap? (Apr 2019)
Initial Max Heap
1
0
8 5
3 2
Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai
19
11
8 1
0
3 2 5 7
Binary Heap is a binary tree which follows structure property and heap order property.
Structure Property:
Binary heap is a complete binary tree. The complete binary tree is a binary tree which
has 2h to 2h+1-1 nodes for height h.
Heap Order property:
10
15 25
30 80
Max Heap:
A Max-Heap is a complete binary tree in which the value in each internal node is larger
than or equal to the values in the children of that node.
60
15 25
3 8
11. Mention some problem for which the heaps are more applicable. (Nov 2021)
Sorting
Priority queue implementation
Shortest path problem
Minimum Spanning Tree problem
12. Define height of the tree.
Height of the tree and the depth of the tree are same. Height of the tree is equal
to the height of the root node, ie, the length of the longest path from the root node to
the leaf.
10
E.x:
20 50
30 25
10 10
10
2
5 15 5 15
5
15. Write about the first child – next sibling representation of the General Tree.
In first child next sibling representation, each node of the tree is represented by node
with three fields.
Node structure in linked list representation:
Address of the Address of the
Data Field
first child field next sibling field
i. Data field – stores the data of the node.
ii. Address of first child field – stores the address of the first child of the node.
iii. Address of next sibling field - stores the address of the next sibling of the node.
E.g:
Sample Tree First Child-Next Sibling Representation
16. Construct the binary tree for the expression (a+b)*(c-d) (Nov 2022)
+ -
a b c d
18. Distinguish binary search tree and AVL tree. (Nov 2023)
S.No AVL Tree Binary Search Tree
Binary Tree is not a height balanced
1 AVL Tree is the height balanced tree
tree.
There is a need of computing balance
2 No need to compute the balance factor
factor of every node.
The height of the tree is log n for ‘n The height of the tree is maximum ‘n’
3
elements. for n elements.
Searching of element in binary search
Searching of element in AVL tree is
4 tree is not always faster and it takes n
always faster and it takes log n steps.
steps in worst case.
Part B
1. Explain Insertion and deletion operations in Binary Search Tree. (Nov 2019) (Nov
2023)
2. Explain Find, Findmin and Findmax operations in Binary Search Tree. (Nov 2018)
(Nov 2022)
3. Explain Tree traversal techniques with examples. (Nov 2019) (Nov 2022) (Nov 2023)
4. Construct a Binary Search Tree by inserting 3, 1, 4, 9, 6, 5, 2, 8 and 7 into an empty
tree. Show the result of deleting the values 1, 6 and 7 from the constructed tree.
(NoV 2021)
5. Explain the insertion operation in AVL tree. (Apr 2019)
6. Create a AVL tree with the following data: 2,5,4,6,7,9,8,3,1,10. (Apr 2019)
7. Explain AVL tree rotations in detail. (Nov 2023)
8. Construct an AVL Tree by inserting 4, 1, 2, 5, 6, 17, 3 and 7 into an empty tree. Show
the result of deleting the values 1, 6 and 7 from the constructed tree. Give the order of
visiting the nodes by applying post order traversal algorithm. (Nov 2021)
9. What is Expression Tree? Explain how expression tree is created for an expression.
(Nov 2021)
10. Create an Expression tree for the expression a+b*c/d. (Nov 2018) (Apply)
11. Explain Insertion and deletemin operation in Minheap. (Apr 2023)
UNIT-IV
1. Define Graph.
A Graph G=(V,E) consists of set of vertices and set of edges E. Each edge is
a pair of vertices (v,w) where v Ɛ V and w Ɛ V.
E.g:
V Vertex
V
1 2
Edge
V
3
2. What are the types of graph? (Nov 2022)
A Graph G=(V,E) consists of set of vertices and set of edges E. Each edge is a pair of
vertices (v,w) where (v,w) Ɛ V.
Types of Graph
1. Undirected graph
2. Directed Graph
Undirected Graph
In an Undirected graph, the edge between two vertices are not directionally oriented.
So, the pair of vertices (v,w) and (w,v) is same.
E.g:
V V Verte
2 x
Edge
V
Directed Graph
In a directed graph, the edge between two vertices are directionally oriented. So, the
pair of vertices (v,w) and (w,v) are different. Directed graph is also referred as digraph.
E.g:
V1 V2
V3
26
V1 V2 V3 V4
V1 V2
V1 0 1 1 1
V2 1 0 0 1
V3 1 0 0 1
V4 1 1 1 0
V3 V4
E.g:2
V1 V2
V3 V4
V1 V2 V3 V4
V2 V1 V4
V3
V1 V4
V4
V1 V2 V3
V1 V2
Prepared By V3
Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai
27
5. Differentiate between strongly connected and weakly connected graph. (Nov 2021)
S.No Strongly Connected Graph Weakly Connected Graph
1. The directed graph is said to be The directed graph is said to be
strongly connected if and only if weakly connected if there is the
there is the path between every missing of path between every pair of
pair of vertices vertices
2.
V V V1 V2
1 2
V V3
3
V1 V2
V5
V3 V4
Euler Circuit ---- V5,V4,V3,V1,V2,V5 (source and destination vertices are same)
Euler Path
A path that contains all the edges of the graph without repetition.
V1 V2
V5
V3 V4
E.g:1
V1 V2
It is a biconnected Graph
V3
E.g:2
V3
E.g:
V1 V2
V3 V4
V3
1 1
A B A B
2 2
5
C D C D
3 3
Weight of the MST=6
access to the search field to the records. Internal nodes of a B+ tree are used to guide
the search. Some search field values from the leaf nodes are repeated in the internal
nodes of the B+ tree.
Example:
19. State how graph is differed from spanning tree with example. (Nov 2023)
S.No Graph Spanning Tree
Spanning tree does not contain a
1 Graph contains a cycle
cycle
There may be any number of There is only one path between
2
paths between pair of nodes every pair of nodes.
Spanning tree concept is applicable
3 There may be any types of graph
to undirected weighted graph
9. Using Prims algorithm, find the minimum spanning tree from the following graph. (Apr
2023)
10. Using Dijikstra’s algorithm, find the minimum cost or shortest path from the following
graph. (Nov 2023)
11. Using Prims algorithm, find the minimum spanning tree from the following graph. (Nov
2023)
UNIT-V
1. Compare Linear search and Binary Search. (APR 2019)
S.No Linear Search Binary Search
Linear search finds the element in the array by
Binary search finds the element in the
1 checking the elements of the array
array using divide and conquer principle.
sequentially until match occurs or array ended.
It is not required to sort the array before It is required to sort the array before
2
searching searching
3 Less Efficient More Efficient
4 Linear Complexity Logarithmic Complexity
2. What do you mean by internal and external sorting? (NOV 2019) (Nov 2023)
Internal Sorting: Internal sorting algorithms are designed to handle small inputs. The
data to be sorted is placed in memory for sorting.
External Sorting: External sorting algorithms are designed to handle very large inputs.
The data to be sorted is placed in mass storage devices like taps.
3. What is the concept behind the bubble sort?
Bubble sort compares the adjacent elements of the list and exchange them if
they are out of order. By doing it repeatedly, the largest element is bubbled up to the
last position in the list. The next pass bubbles up the second largest element to the
next to last position. After ‘n-1’ passes, the list is sorted.
4. Write the procedure for shell sort algorithm. (NOV 2021)
It should ensure that distinct elements are placed in the different cells in the
hash table.
9. Outline the perfect minimal hashing function. (Apr 2023)
Given a set S of N elements (keys), a minimal perfect hash function (MPHF)
is an injective function that maps each key of S to an integer in the interval [1,N]. In
other words, an MPHF labels each key of S with integers in a collision-free manner,
using the smallest possible integer range.
7. Explain merge sort algorithm and apply the merge sort procedure for the following set
of numbers. (Nov 2023)
[31, 28, 17,65,35,42,86,25,45,52]
8. Explain separate chaining (Open hashing) and open addressing (Closed hashing) in
detail. (NOV 2018) (Apr 2023) (OR) Explain various Collision resolution strategies in
detail. (NOV 2021) (Nov 2023).
9. Explain rehashing and extendible hashing. (NOV 2018)
10. The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table
of length 10 using linear probing with hash function h(k)=k mod 10. What is the
resultant hash table. (Apr 2023)