Solved Question Paper
Q1: Attempt any eight of the following
a) What are the advantages of linked list over an array?
Dynamic memory allocation
Easy insertion/deletion
No memory wastage
Flexible size
b) How to measure performance of an algorithm?
By calculating time and space complexity
Using asymptotic notations like Big O, Omega, and Theta
c) What is adjacency matrix?
A 2D matrix used to represent a graph
If there’s an edge between vertex i and j, matrix[i][j] = 1
d) What is pointer to pointer?
A pointer that holds the address of another pointer
Example: int **ptr;
e) What is complete binary tree
All levels are completely filled except the last, which is filled from left to
right.
f) What is polynomial? How is it differ from structure
Polynomial is an algebraic expression (e.g., 3x² + 2x + 1)
Structure is a data type in C to group different data types
Polynomial can be represented using structures
1
g) What is Priority Queue?
A queue where each element is associated with a priorit
Elements with higher priority are dequeued firs
h) Difference between stack and linked list:
Stack uses LIFO (Last-In-First-Out), limited access
Linked list is flexible and allows access from any node
i) What is the need for the header?
Header stores meta-information such as start pointer, size, etc. in data
structures like linked list
j) What is balance factor? How is it calculated
Balance factor = Height(left subtree) - Height(right subtree)
Used in AVL Trees to maintain balance
Q2: Attempt any four of the following
a) What is height-balanced tree? Explain RR and RL rotations with example.
AVL Tree is a height-balanced tree with balance factor -1, 0, or +1
RR Rotation: Right-heavy – Rotate left
RL Rotation: Right child is left-heavy – Perform right-left rotation
Example (RL): Insert 10, 30, 20 → imbalance at 10
Resulting tree after RL rotation:
20
/ \
10 30
2
b) What is linked list? Explain its types in detail.
Linked list is a data structure with nodes linked together using pointers
Types:
1. Singly Linked List 2. Doubly Linked List 3. Circular Linked List
c) Explain different types of asymptotic notation in detail.
Big O (O): Worst-case
Omega (Ω): Best-case
Theta (Θ): Average-case
Used to analyze algorithm efficiency
Q3) Attempt any four of the following : [4×4=16]
a) Write a function to create & display circular singly linked list.
a) Circular Singly Linked List in C:
```c
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
struct Node* head = NULL;
void create(int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
if (head == NULL) {
head = newNode;
head->next = head;
} else {
3
struct Node* temp = head;
while (temp->next != head)
temp = temp->next;
temp->next = newNode;
newNode->next = head;
}
}
void display() {
struct Node* temp = head;
if (head != NULL) {
do {
printf("%d ", temp->data);
temp = temp->next;
} while (temp != head);
}
}
```
b) Write a function to insert an element into a circular queue, in which the
queue is implemented as an array.
b) Insertion in Circular Queue using Array:
```c
#define SIZE 5
int queue[SIZE], front = -1, rear = -1;
void enqueue(int value) {
if ((front == 0 && rear == SIZE-1) || (rear + 1) % SIZE == front)
printf("Queue is Full
");
else {
if (front == -1) front = 0;
rear = (rear + 1) % SIZE;
queue[rear] = value;
}
4
}
```
c) Write a function for in order traversal of the tree.
c) Inorder Traversal of Binary Tree:
```c
struct Node {
int data;
struct Node* left;
struct Node* right;
};
void inorder(struct Node* root) {
if (root != NULL) {
inorder(root->left);
printf("%d ", root->data);
inorder(root->right);
}
}
```
d) Write a function to delete first node from singly linked list.
d) Delete First Node from Singly Linked List:
```c
void deleteFirst() {
if (head == NULL) return;
struct Node* temp = head;
head = head->next;
free(temp);
}
```
e) Write a function to search the element from array using binary search.
e) Binary Search in Array:
```c
5
int binarySearch(int arr[], int n, int key) {
int low = 0, high = n - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (arr[mid] == key) return mid;
else if (arr[mid] < key) low = mid + 1;
else high = mid - 1;
}
return -1;
}
```
Q4) Attempt any four of the following : [4×4=16]
a) Construct AVL tree for data: WED, TUE, MON, SAT, THUR, FRI
Order of insertion causes imbalance: perform rotations
Final AVL Tree:
TUE
/ \
MON WED
/ / \
FRI SAT THUR
b) For given data, construct a binary search tree: 15, 30, 20, 5, 10, 2, 7
b) Binary Search Tree (BST):
Inserting in order: 15, 30, 20, 5, 10, 2, 7 results in:
```
15
/ \
5 30
/\ /
6
2 10 20
/
7
```
```
d) Write a C-program to traverse the linked list.
d) Linked List Traversal in C:
```c
struct Node {
int data;
struct Node* next;
};
void traverse(struct Node* head) {
struct Node* temp = head;
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
}
```
e) What is Dequeue? Explain its operation with example.
e) Dequeue (Double Ended Queue):
A dequeue allows insertion and deletion from both front and rear ends.
Operations:
- insertFront()
- insertRear()
- deleteFront()
- deleteRear()
Example:
Insert 10 at rear, 20 at front, delete from rear.
7
Q5) Attempt any two of the following : [2×3=6]
a) Convert the following expression into postfix.
i) (A + B) * C - D
ii) A + B * C - D / E * F
ans) Postfix Conversions:
i) (A + B) * C - D -> AB + C * D -
ii) A + B * C - D / E * F -> ABC * + DEF / * -
b) Define the following terms :
i) Degree of node
ii) Child node
iii) Path
b) Definitions:
i) Degree of node: Number of edges incident to a node.
ii) Child node: Node directly connected and one level below a parent node.
iii) Path: A sequence of nodes where each adjacent pair is connected by an
edge.