Dsa 2022
Dsa 2022
Note: C code should be given for implementation based questions. State any assumptions made.
1 Consider the following node structure for questions 1a, b, c, d.
typedef struct node
{
int data;
struct node* next;
}NODE;
a) Write a C function to create a copy of the Singly Linked List using recursion. 4
Eg: Original list : 1->2->3->4->NULL
After copying:
Original list : 1->2->3->4->NULL
Copied list: 1->2->3->4->NULL
Function prototype to be implemented: NODE* copyList(NODE* head);
b) Given two Singly Linked Lists sorted in ascending order, write a function to return 6
the number of nodes that have the same data across both the lists.
Function prototype to be implemented:
int countCommonData(NODE *a,NODE *b);
c) Write a C function which takes the address of the first node of a singly-linked list 6
as input argument and modifies the list by moving the last element to the front of
the list and returns the modified list. Your code should handle all the boundary
conditions.
Function prototype to be implemented: NODE* moveToFront(NODE* head);
d) Given a singly linked list, check if it is circular. An empty list is considered to be 4
circular.
Function prototype to be implemented: int isCircular(struct NODE* head);
3 a) Define the following w.r.t binary tree. Give an example for each. 6
i) Binary tree (ii) Depth of a node (iii) Height of a node
b) Write a C program for the implicit array representation of binary tree with inorder 6
traversal.
c) i) Construct a max heap for the following elements using top down approach by 8
showing the different stages pictorially. (5+3)
30, 62, 53, 42, 18, 95, 90, 33
ii) Write a C function for top down max heap construction. Consider the root node
is indexed at 0.
4 a) Construct an AVL tree for the following elements: 10, 11, 13, 8, 7, 9, 12 6
b) What is a splay tree? Explain the search and delete operations in splay tree with 6
examples.
c) Construct a B tree of order m=5 for the following elements. 4
5, 10, 15, 20, 1, 3, 2, 4, 16, 7, 14, 9, 8, 12, 6, 17, 11, 13, 18, 19
d) Write the BFS and DFS traversal for the following graph. Consider starting vertex 4
is 1 for both the traversals. Use lexicographic ordering.
SRN
5 a) Consider a hash table size is 11 and the following keys are mapped into the table. 8
10, 35, 54, 67, 70, 82, 3, 29, 24, 20
Consider the hash function key % tableSize is used.
i) Show the contents of the hash table when the collision is resolved using linear
probing.
ii) Show the contents of the hash table when the collision is resolved using
quadratic probing.
b) Write a C function for open address hashing using quadratic probing for collision 4
resolution.
Consider the following structure:
struct element {
int key;
char name[100];
int mark;
};
Function prototype to be implemented:
int insertToHash(struct element *ht, int size, int key, char*name, int *count);
ht: hash table
size: size of the hash table
key: key to be inserted
name: name to be inserted
count: no. of elements present in the hash table
return 1 on success, 0 on failure.
c) i) Construct a trie for the following patterns: 6
ant, apple, app, bat. (2+4)
ii) Write a C function to insert a pattern in a trie data structure housing lower case
English alphabets only.
Consider the following structure of the trie node
struct trienode
{
struct trienode *child[26];
int endofword;
}
Function prototype to be implemented : void insert(TRIE *root,char *pattern);
d) Differentiate between suffix trie and a suffix tree. 2