0% found this document useful (0 votes)
20 views39 pages

Data Strctures Question Bank -22.07.24

Uploaded by

brawltalk2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views39 pages

Data Strctures Question Bank -22.07.24

Uploaded by

brawltalk2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

1

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


CS3301-DATA STRUCTURES
Question Bank
Unit-I –Lists
Part-A
1. What is Data structures?
Data Structure is defined as the way of organizing data not only tell how data
is stored but also explains the relationships among them.
Ex: List, Stack, Queue, Tree, Graph and etc.
2. What is the difference between linear and nonlinear data structures? (NOV 2022)
Linear Data Structures- In which the elements are accessed sequentially.
Ex: List, Stack, Queue
Non-Linear Data Structures-In which the elements are not accessed sequentially.
Ex: Tree, Graph
3. Define Abstract Data type. (Nov 2019) (NOV 2023)
The abstract datatype is a special kind of datatype, whose behavior is defined
by set of values and set of operations.
The ADT is made of primitive datatypes, but operation logics are hidden from
the user.
Ex: List, Stack, Queue, Tree, Graph and etc.
4. State the advantages of ADT (Nov 2018), (APR 2023).
In ADT, the implementations of operations are completely hidden from the
user. Implementations of ADTs can be changed without requiring changes to the
program that uses the ADTs. Code is easier to understand.
5. What are the advantages and Disadvantages of array?
Advantages of Array
 Accessing the element from the array is easy.
Disadvantages of Array
 Size of the array cannot be increased or decreased since the array size
is defined statically.
 Insertion and deletion is not easy as they involve lot of data movement
to ensure that the array is stored continuously in memory.
Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai
2

6. Define Linked List. (Nov 2019)


The linked list consists of series of structures (Nodes) which are not stored
continuously in memory. Each structure contains one element of the list and address
to the next structure in the list. Last Structure address will be stored as ‘NULL’.
Diagrammatic Representation:

Types of Linked List:


• Singly Linked List
• Doubly Linked List
• Circularly Linked List
7. What are the disadvantages of Linked list over array? (Nov 2018)
I. More memory is required in the linked list as compared to an array.
II. Direct access to an element is not possible in a linked list as in an array by
index.
III. Reverse traversing is not possible in linked list.
8. What are the advantages of Linked list over array? (Apr 2019)
I. Insertion and deletion operations are very easy in linked list. There is no need
to move the elements forward and backward after the insertion or deletion of
an element as in array, only the address present in the next pointer needs to
be updated.
II. In the linked list, efficient memory utilization can be achieved since the size of
the linked list increase or decrease at run time so there is no memory wastage
and there is no need to pre-allocate the memory as in array.
9. Compare array and linked list.
S.No Array Linked List
Size of the linked list can be increased or
1 Size of the array is fixed
decreased at run time
Insertion and deletion Insertion and deletion operations are very easy
operations are difficult in linked list. There is no need to move the
2
because it is necessary to elements forward and backward, only the links
move the elements forward are changed.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


3

and backward after the


insertion or deletion of an
element.
Direct access to an element is
3 Direct access to an element is not possible.
possible.
Memory Utilization is not
4 Memory Utilization is efficient.
efficient.

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.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


4

13. List out the applications of circularly linked list.


I. Circularly linked lists are useful in applications where the process has to
repeatedly go around the list.
II. Circularly linked list are mostly used in task maintenance in operating systems.
III. Circularly linked list are being used in browser surfing where a record of pages
visited in the past by the user, is maintained in the form of circularly linked lists.
14. List the applications of linked list.
I. Linked list is used for single variable polynomial manipulation.
II. Linked list is used in Radix sort.
III. Multi linked list structure is used for course registration in university.
15. When arrays are better than linked list? Give an example. (Nov 2021)
Arrays are used in the data collection which is rarely modified or only read
operation is done over the collection.
 Dictionary data
 Catalogs
16. What is the benefit of circularly linked list over singly linked list in search
applications? (NoV 2021)
Searching requires to traverse the linked list completely. The traversal in the
circularly linked list can be started from any node and the list will be completely
traversed till the starting position is reached. But the singly linked list gives the valid
answer for search if the search starts from the beginning of the list. Hence circularly
linked list is preferred over the singly linked list for searching.
17. Outline Circular linked list with diagram. (NOV 2022)
Circularly linked list is a linked list where all nodes are connected to form a
circle. There is no NULL at the end. We traverse a circularly linked list until we reach
the same node where we started. Any node can be a starting node. We can traverse
the whole list by starting from any node.

18. Infer the uses of Multilist. (NoV 2023)


Multi Linked List is a 2D data structure that comprises several linked lists and
each node in a multilevel linked list has a next and child pointer. All the elements are

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


5

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

20. What are the advantages of multi linked list?


The advantages of a multi-linked list are:
 Sets of same data can be processed into multiple sequences.
 Data are not duplicated anywhere.
 Data of one kind exist only once in the list.

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’.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


6

• 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:

• Insert(45) before (20)


• It is necessary to identify the address of 20 and call it as ‘p’
• Create a node for 45;

• Insert the data 45 into the data part of the node

During Insertion:

header

head

10 20 30

2000(Pre) 1500(p) 4300

45

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


3100(newnode)
7

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

2000(Pre) 1500(p 4300

45

Implementation:
3100(newnode)

Assume the following

• x is the element to be inserted;


• m is the element before which new node is inserted
• p is the node address holds the address of m
void insertspecify(struct snode *head, int x, int m)
{
struct snode *newnode,*p, *pre;
newnode=(struct snode *)malloc(sizeof(struct snode));
newnode->data=x;
pre=head;
p=head->next;
while(p!=null)
{
if(m==p->data)
{
newnode->next=p;
pre->next=newnode;
return;

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


8

}
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)

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


10

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

2. What are the applications of stack? (Nov 2018, Nov 2019)


Stack has numerous applications. Some of the important applications are listed below.
o Stack is used to check whether the symbols are balanced in the given
expression.
o Stack is used to convert infix expression into postfix expression.
o Stack is used to evaluate the postfix expression.
o Stack is used for function call implementation in programming.
3. What are the necessary conditions for insertion and deletion operations on static
stack? (Nov 2021)
 For insertion, stack full condition should be verified.
 For deletion, stack empty condition should be verified.
4. Write the rules to be followed during infix to postfix conversion. (Nov 2019)
Algorithm for converting Infix to Postfix expression
Input : Infix expression
Output : Postfix expression
Step 1 : Append ‘#’ delimiter at the end of given infix expression.
Step 2 : Push ‘#’ onto the stack.
Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai
11

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.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


12

Queue Model

6. Compare stack and queue.


S.No Stack Queue
1 Stack is a LIFO structure. Queue is a FIFO Structure,
Insertion and deletion operations are Insertion and deletion operations are
2
done at one end. done at different ends.
Rear pointer controls the insertion
Top pointer controls the insertion
3 and front pointer controls the
and deletion.
deletion.

7. Define Circular queue.


A circular queue is similar to a linear queue except that the last position is connected
to the first position that forms a circle. It is also known as a Ring Buffer.

E.g.Circular representation of queue

8. What conversions are required to a queue data structure to behave as a circular


queue? (Nov 2021)
 The last position of the queue data structure should be connected to first
position so that queue behaves as circular queue.
 Rear and front pointers should be incremented as follows to show the wrap
around condition.
o rear=(rear+1) mod size of queue array
o front=(front+1) mod size of queue array

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


13

9. Compare linear queue and circular queue.


S.No Linear Queue Circular Queue
Arranges the data in circular pattern
1 Arranges the data in linear pattern where rear end is connected to front
end
Insertion and deletion operations Insertion and deletion operations can
2
are fixed be done continuously.
3 Memory utilization is poor Memory utilization is good.

10. List the applications of Dequeue.


 Dequeue is used in Palindrome checking.
 Dequeue is used in job scheduling for multiprocessors.
 Dequeue is used to implement undo-redo operations in software applications.
11. Convert the infix expression (a+b)*(c-d) into prefix expression. (Nov 2022)
Step 1: Parenthesize the expression
((a+b)*(c-d))
Step 2: Move all the operators to its corresponding left parenthesis
Prefix expression is *+ab-cd
12. What are the limitations of linear queue (Apr 2023)
13. Write the underflow and overflow conditions in stack. (Apr 2023) (Nov 2023)
Underflow condition in stack ------ when top is equal to -1
Overflow condition in stack ------- When top is equal to n-1 (where ‘n’ is the
size of the stack)
14. List some applications of queue (Nov 2023)
 Queues are widely used as waiting lists for a single shared resource like
printer, disk, CPU.
 Lines at ticket counters are queue.
 Queues are used in operating systems for handling interrupts.
 Calls to large companies are placed in a queue.

15. Draw the structure of dynamic stack.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


14

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.

17. Draw the structure of dynamic queue.

18. What is dequeue? Draw the model of dequeue.


Dequeue is a linear data structure in which the insertion and deletion operations are
performed from both ends.
Dequeue Model:

19. What are the two types of dequeue?


Types of Dequeue

There are two types of dequeue


• Input-restricted queue
• Output-restricted queue.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


15

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.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


17

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)

Sibling of node ‘E’ – node ‘D’


Height of the tree - 4
3. Show the result of Inorder traversal of the Binary Search Tree given below. (Nov 2018)

Inorder Traversal : 1,2,3,4,5,6,7,9

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


18

4. What do you mean by the level of the tree? (Nov 2019)


In tree ADT, the datas’ are stored in nodes and the nodes are arranged in
levels. The root node is at the level 0. The nodes arranged in level by level shows the
hierarchical arrangement of the data.
Example:

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

Heap after Insertion

11

8 1
0

3 2 5 7

Level Order Traversal: 11,8,10,3,2,5,7


7. The depth of the binary tree is 8 and compute the number of nodes in the leaf. (Apr
2019)
No of nodes in the Binary tree of depth 7 = 2 7+1-1= 28-1=256-1=255.
No of nodes in the Binary tree of depth 8 = 2 8+1-1= 29-1=512-1=511.
No of nodes only in level 8 = 511-255 = 256 (28).
Hence, the number of leaf nodes in the binary tree of depth 8 ranges from 1 to 256.
8. List the applications of priority queue.
Priority queue is used in the following
 CPU Scheduling
 Graph algorithms
 All queue applications where priority is involved.
9. Define Heap and write the properties of heap. (Nov 2022)

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:

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


20

With respect to heap order property, the heap is classified into,


1. Min heap
2. Max heap
Min Heap:
A Min-Heap is a complete binary tree in which the value in each internal node is smaller
than or equal to the values in the children of that node.
Ex:

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

10. Define Balance Factor of a node.


Balance factor of a node is defined as the difference between height of the
node’s left subtree and height of the node’s right subtree.

Ex: Balance Factor of ‘node 3’ is =2-3= -1.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


21

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

Height of the tree =2

13. Compare Full Binary Tree and Complete binary tree.


S.No Full Binary Tree Complete Binary Tree
The binary tree is said to be full The complete binary tree is a binary
1 binary tree iff it has exactly 2h+1-1 tree which has 2h to 2h+1-1 nodes for
nodes for the tree of height h. height h.
Ex: Full Binary Tree of Height 1, Ex: Complete Binary Trees of Height 1,

10 10
10
2

5 15 5 15
5

14. Define AVL Tree.


The binary search tree is said to be AVL tree iff all the nodes of the tree
have the balance factor either +1, -1 or 0.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


22

Ex: : AVL Tree

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

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


23

16. Construct the binary tree for the expression (a+b)*(c-d) (Nov 2022)

+ -

a b c d

17. Mention the types of rotations in AVL Tree. (APR 2023)


AVL Rotations are classified into
 Single Rotation
o Left Left Rotation (LL Rotation)
o Right Right Rotation (RR Rotation)
 Double Rotation
o Right Left Rotation (RL Rotation)
o Left Right Rotation (LR Rotation)

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.

19. What are the applications general tree?


Applications of General Tree
• The files and folders in the windows explorer are stored in the tree
format.
• The layout of a webpage is designed using tree structure.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


24

20. Write the algorithm to construct expression tree from postfix.


Algorithm for constructing expression tree from postfix expression:
Input : Postfix expression
Output : Expression Tree
Step 1: Append ‘#’ delimiter at the end of given postfix expression.
Step 2: Read the character ‘ch’ from postfix expression one at a time and test the ‘ch’
Step 2.1: If the ‘ch’ is operand then create a node for the operand and push
the pointer of the operand node to the stack.
Step 2.2 : If the ‘ch’ is operator then create the node for the operator and pop
two entries from the stack. The first popped entry is the right child of the operator node
and the second popped entry is the left child of the operator node. Then push the
pointer of the operator node on to the stack.
Step 2.3 : If the ‘ch’ is ‘#’, then pop the entry from the stack, that is the pointer
of the root node of the expression tree.
Step 3: Repeat step 2 until ‘#’ delimiter is encountered in the postfix expression.

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)

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


25

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

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai

V3
26

3. What are the representations of graph?


There are two representations of graph.
a. Adjacency Matrix representation
b. Adjacency Linked List representation
E.g:1 Adjacency Matrix

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

Adjacency Linked List representation:

V1 V2 V3 V4
V2 V1 V4
V3
V1 V4
V4
V1 V2 V3

4. When the graph is said to be strongly connected?


The directed graph is said to be strongly connected if and only if there is the path
between every pair of vertices otherwise the graph is called weakly connected graph.
E.g: Strongly Connected Graph

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

6. Define Euler Circuit and Euler path. (Nov 2018)


Euler Circuit
A path that contains all the edges of the graph without repetition and the starting
vertex and ending vertex of the path is same.

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

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


28

7. What is biconnectivity? (Apr 2019)


The connected undirected graph is said to be biconnected if and only if the
removal of any vertex does not disconnect the graph.

E.g:1

V1 V2
It is a biconnected Graph

V3

E.g:2

V1 V2 It is not a biconnected Graph because


the removal of vertex ‘v2’ cause the
graph becomes disconnected

V3

8. Define Complete Graph.


The undirected graph is said to be complete if and only if there is the direct
edge between each pair of vertices.

E.g:

V1 V2

V3 V4

9. What is the significance of articulation points in graphs? (NOV 2021)


If the graph is not biconnected then the removal of articulation point (or) cut
vertex will disconnect the graph.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


29

V1 The vertex ‘v2’ is articulation point


V2
since it removal makes the graph
disconnected

V3

10. What is Minimum Spanning Tree? (Understand)


Definition:
Minimum Spanning Tree is the connected sub graph of the given undirected
weighted graph contains all the vertices with the minimum total edge weight.
E.g

Graph Minimum Spanning Tree (MST)

1 1
A B A B
2 2
5

C D C D
3 3
Weight of the MST=6

11. Compare Prims and Kruskals algorithm.


S.No Prim’s Algorithm Kruskal’s Algorithm
Prim’s algorithm forms Minimum Kruskal’s algorithm forms Minimum
Spanning Tree by adding vertices Spanning Tree by adding edges one by
1.
one by one until all the vertices are one until all the edges are added to the
added to the Minimum Spanning Tree Minimum Spanning Tree.
The same vertex is traversed more The same edge is traversed only once.
2. than once in order to get it minimum
edge.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


30

12. Compare DFS and BFS traversal algorithm.


S.No DFS Algorithm BFS Algorithm
DFS considers one adjacent vertex of BFS considers all the adjacent vertices of
1.
the search vertex for exploration. the search vertex for exploration.
DFS uses stack data structure for BFS uses queue data structure for vertex
2.
vertex exploration exploration
DFS is more suitable for decision BFS is not suitable for decision making
3.
making problems problems

13. Write the applications of Depth First Search.

o DFS is used to check whether the graph is connected or not. - In an undirected


graph, if the depth first spanning forest contains single tree then the graph is
connected, otherwise the graph is unconnected. -In a directed graph, if the
depth first spanning forest contains single tree then the graph is strongly
connected, otherwise it is weakly connected graph.
o DFS is used to find the strongly connected components in the directed graph.
o DFS is used to check whether the graph is acyclic or not. If the depth first
spanning forest of the graph contains back edges, then the graph contains
cycle.
o DFS is used to check whether the undirected connected graph is biconnected
or not.
14. Compare B-Tree and B+Tree. (Nov 2018) (Nov 2022)
S.No B Tree B+ Tree
Data stored in both internal and leaf
1 Data stored in leaf nodes only
nodes
2 No redundancy in data Redundancy in data
Searching is not efficient as data in both Searching is efficient as data is
3
leaf nodes and internal nodes stored only in leaf nodes
4 Deletion is time consuming process Deletion is fast
Sequential accessing is not
5 Sequential accessing is not possible
possible

15. Give the structure of node in B-Tree. (NOV 2021)


The B-Trees are specialized m-way search tree. This can be widely used
for disc access. A B-tree of order m, can have maximum m-1 keys and m children.
This can store large number of elements in a single node.
Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai
31

16. Define Critical Path. (Apr 2023)


Critical path is the longest path that connects the source and destination
points in the graph.
Example:

17. State the uses of Topological sorting. (Apr 2023)


The Applications of Topological Sort are:
 Finding cycle in a graph
 Operation System deadlock detection
 Dependency resolution
 Sentence Ordering
 Critical Path Analysis
 Course Schedule problem
 Other applications like manufacturing workflows, data serialization
and context-free grammar.
18. Define B+ tree with an example. (Nov 2023)
B + Tree is a variation of the B-tree data structure. In a B + tree, data pointers
are stored only at the leaf nodes of the tree. In a B+ tree structure of a leaf node differs
from the structure of internal nodes. The leaf nodes have an entry for every value of
the search field, along with a data pointer to the record (or to the block that contains
this record). The leaf nodes of the B+ tree are linked together to provide ordered
Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai
32

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

20. Write the properties of minimum spanning tree (MST)


 MST does not contain cycle.
 MST contains all the vertices of the graph and does not contain all the edges.
 MST is not unique for the graph. For the same graph many number of MSTs are
possible.
Part-B
1. Explain Depth first and Breadth first traversal algorithm in detail. (NOV 2019) (NOV
2021) (Nov 2022) (Nov 2023)
2. Explain Topological Sorting algorithm in detail. (NOV 2019) (Nov 2023)
3. Explain Dijkstra’s single source shortest path algorithm in detail. (Nov 2022) (Nov
2023)
4. Explain how articulation points are identified in the undirected Graph? (Understand)
5. Explain Prims algorithm and kruskals algorithm of finding Minimum Spanning Tree

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


33

in detail. (Apr 2023)


6. Explain insertion and deletion in B-Tree. (Nov 2023)
7. Explain insertion and deletion in B+ Tree. (Apr 2023)
8. Using Kruskals algorithm, find the minimum spanning tree from the following graph.
(Nov 2022)

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)

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


34

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)

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


35

Shell sort is a highly efficient algorithm and it is based on insertion sort


algorithm. This algorithm avoids the large shift of elements from the far right to far left
which are happened in the insertion sort. This algorithm sorts widely spaced elements
first, then sorts the less widely spaced elements using insertion sort. This spacing is
termed as interval (h).
Algorithmic Steps:
1. Initialize h=‘n/2’.
2. Divide the list into sub-lists and each sub list contains the elements of equal interval
h.
3. Sort these sub-lists using insertion sort.
4. Update the value of h, as h=h/2.
5. Repeat the steps 2 to 4 until h become 1.
6. If h=1, then apply the insertion sort to sort elements.

5. What is divide and Conquer Principle? (Nov 2022)


Divide and Conquer Algorithm is a problem-solving technique used to solve
problems by dividing the main problem into subproblems, solving them individually and
then merging them to find solution to the original problem.
Example : Merge sort. Quick sort
6. What is the principle behind the external sorting algorithm? (Apr 2023)
External sorting is a class of sorting algorithms that can handle massive
amounts of data. External sorting is required when the data being sorted do not fit into
the main memory of a computing device (usually RAM) and instead they must reside
in the slower external memory, usually a disk drive. Thus, external sorting algorithms
are external memory algorithms and thus applicable in the external memory model of
computation.
7. What is hashing?
Hashing is the technique used to perform insertions, deletions and find in
constant average time. Hashing is used to implement Hash table data structure.
8. What is hash function? Write the properties defining good hash function. (Nov 2022)
(Nov 2023)
Hash Function
It is the mapping function that place the elements in the hash table
Properties of Hash Function
 It should be simple to compute.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


36

 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.

10. What is hash table?


Hash table data structure is the array of some fixed size containing set of
elements. The elements in the hash table are placed in the position from 0 to
tablesize-1.
11. What is load factor?
It is the ratio of the number of elements in the hash table to the table size.
12. What is the reason for collision in hashing technique? (NOV 2021)
Collision is occurred when two elements are hashed into the same cell of the
hash table.
Collision resolution techniques
 Separate Chaining (or) open hash table
 Open Addressing (or) closed hash table
13. What are the advantage and disadvantage of separate chaining and open addressing?
(NOV 2018)
Advantages of separate chaining
o The number of elements stored in the hash table can exceed the size
of the hash table.
Disadvantages of separate chaining
o It requires pointers.
o The search time will be more if the list having long chain.
Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai
37

Advantages of Open Addressing


o The elements are stored inside the hash table.
Disadvantages of Open Addressing
o Linear probing leads to primary clustering problem.
o Quadratic probing leads to secondary clustering problem.
o Double hashing leads to thrashing.
14. Write about extendible hashing. (APR 2019)
The extendible hashing is applied if the data to be hashed is in the external
storage. Extendible Hashing is a dynamic hashing method wherein directories, and
buckets are used to hash data.
15. Define Primary clustering.
Primary Clustering:
Even though the table is relatively empty, the blocks of occupied cells start
forming in linear probing. This effect is called as primary clustering. Due to primary
clustering, element hashes into the table requires several attempts to resolve the
collision. Afterwards it will add into the cluster.
16. Define Secondary clustering.
Secondary Clustering:
Quadratic probing leads to effect of secondary clustering i.e the elements that
hash to the same position will probe to the same alternative cells.
17. When rehashing is done?
Rehashing can be implemented in several ways with quadratic probing.
 Once the table is half full.
 When an insertion fails.
 When the table reaches the certain load factor.
18. Write the algorithm for linear search.
i. The array of elements and the element to be searched are given.
ii. The array elements are accessed from the first element.
iii. While there are elements in the array, compare the current element of the
array with the element to be searched.
a. If match is found, return the index of the current element of the array,
otherwise move to the next element.
iv. Return -1 to indicate the unsuccessful search.

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai


38

19. Write the algorithm for binary search.


Algorithmic Steps:
1. The sorted array of elements and the element to be searched is given.
2. Set low=0, high=n-1, Where ‘n’ is the size of the array.
3. If low<=high, go to step 4, otherwise return -1 and halt.
4. i. Calculate mid=low+(high-low)/2.
ii. If the element to be searched is matched with the middle
element, then return the position of the middle element and halt.
iii. If the element to be searched is less than the middle element,
then use the first half of the array to continue the search by
changing high=mid-1. Go to step 3 to continue the search.
iv. If the element to be searched is greater than the middle element,
then use the second half of the array to continue the search by
changing low=mid+1. Go to step 3 to continue the search.

20. Write the pseudo code for selection sort algorithm.


Assume the array ‘a’ has n elements which is to be sorted by selection sort.
for i= 0 to n-2 do
min=i
for j=i+1 to n-1 do
if a[j] < a[min] then
min=j
end if
end for
swap(a[i], a[min])
end for
Part-B
1. Explain linear search and binary search in detail and illustrate the steps with example.
(NOV 2018) (Nov 2022) (Nov 2023)
2. Explain Insertion sort in detail and sort the following sequence using insertion sort.
3,10,4,2,8,6,5,1. (APR 2019) (Nov 2023)
3. Explain Bubble sort algorithm with example. (Nov 2022) (Apr 2023)
4. Explain Selection sort algorithm with example.
5. Explain Shell sort algorithm in detail.
6. Outline the steps in the Insertion sort algorithm and apply the algorithm for the numbers
given below:
12, 6, 14, 2, 1, 4, 3
Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai
39

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)

Prepared By Dr.C.Callins Christiyana Professor and Head, CSE, SRM Madurai

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy