Q1. What is a Linked List? Explain types and advantages.
A linked list is a linear data structure in which elements are stored in nodes, and each node
contains data and a reference (pointer) to the next node. Unlike arrays, linked lists do not store
elements in contiguous memory locations.
There are different types of linked lists such as singly linked list, doubly linked list, and circular
linked list. In a singly linked list, each node points to the next node only. In a doubly linked list,
each node points to both next and previous nodes. In a circular linked list, the last node points
back to the first node.
Linked lists are dynamic in size, meaning memory is allocated during runtime. They allow easy
insertion and deletion of elements without shifting other elements, which makes them efficient
for dynamic data handling. However, they require extra memory for pointers and have slower
access time compared to arrays.
Q2. Explain Stack. Write its operations and applications.
A stack is a linear data structure that follows the LIFO (Last In First Out) principle, meaning the
last element inserted is the first one to be removed. It is called an Abstract Data Type (ADT)
because it defines operations without specifying implementation.
The main operations of a stack are push (inserting an element), pop (removing an element), peek
(view top element), and isEmpty (checking whether stack is empty).
Stacks are widely used in computer science. They are used in function calls (recursion),
expression evaluation, undo operations in software, and syntax parsing in compilers. Stack
overflow occurs when more elements are inserted than capacity, while stack underflow occurs
when popping from an empty stack.
Q3. What is Queue? Explain types and real-life applications.
A queue is a linear data structure that follows the FIFO (First In First Out) principle, where the
first element inserted is the first one to be removed.
The main types of queue include simple queue, circular queue, priority queue, and double-ended
queue (deque). In a simple queue, insertion happens at rear and deletion at front. In a circular
queue, the last position is connected back to the first position.
Queues are used in real life such as printer scheduling, CPU task scheduling, call center systems,
and network data handling. They ensure fair processing of tasks in the order they arrive.
Q4. What is Recursion? Explain with example.
Recursion is a programming technique in which a function calls itself to solve a problem. It
divides a problem into smaller sub-problems until a base condition is reached.
A recursive function must have a base case and a recursive case. The base case stops recursion,
while the recursive case calls the function again.
For example, factorial of a number is calculated using recursion:
Factorial(n) = n × Factorial(n-1), with Factorial(0) = 1.
Recursion is used in tree traversal, searching algorithms, and mathematical computations.
However, it may lead to stack overflow if not properly controlled.
Q5. Explain Binary Search Tree (BST) and its properties.
A Binary Search Tree (BST) is a binary tree in which the left subtree contains values smaller
than the root and the right subtree contains values greater than the root.
The properties of BST include: each node has at most two children, left child is smaller than
parent, and right child is greater than parent. This property allows efficient searching, insertion,
and deletion operations.
BST is widely used in searching applications because it provides average time complexity of
O(log n). However, in worst cases (skewed tree), complexity becomes O(n).
Q6. Explain Bubble Sort Algorithm with example.
Bubble sort is a simple sorting algorithm in which adjacent elements are compared and swapped
if they are in wrong order. It repeatedly passes through the list until it becomes sorted.
In each pass, the largest element moves to the end of the array like a bubble rising to the top.
Its time complexity is O(n²) in worst and average cases, making it inefficient for large datasets.
However, it is easy to understand and implement.
Bubble sort is mainly used for educational purposes.
Q7. Explain Selection Sort Algorithm.
Selection sort is a sorting algorithm in which the smallest element is selected from the unsorted
part and placed at the beginning.
It divides the array into sorted and unsorted parts. In each iteration, the minimum element is
selected and swapped with the first unsorted element.
Its time complexity is O(n²), and it performs poorly on large datasets. However, it requires fewer
swaps compared to bubble sort.
Q8. What is Big-O Notation? Why is it important?
Big-O notation is used to describe the performance or complexity of an algorithm in terms of
time and space. It shows how an algorithm performs as input size increases.
It is important because it helps compare different algorithms and choose the most efficient one.
Common complexities include O(1), O(log n), O(n), O(n²).
For example:
• Array insertion → O(n)
• Linked list insertion → O(1) (at head)
Big-O notation is essential in analyzing data structures and improving performance of programs.
• ARRAY •
Definition An array is a collection of elements stored in contiguous (continuous) memory
locations. •
Features •
Fixed size Size is decided when the array is created. •
Fast access using index Elements can be accessed quickly using position numbers. •
Same data type elements All elements in an array must be of the same type. •
Operations •
Traversal – Access all elements one by one. •
Insertion – Add a new element. •
Deletion – Remove an element. •
Searching – Find an element in the array. •
Updating – Change the value of an element. •
Advantages • Easy access to elements using index. • Efficient memory usage because elements
are stored continuously. •
Disadvantages • Fixed size cannot be changed easily. • Insertion and deletion are costly because
elements may need shifting. • Applications • Storing students’ marks • Working with matrices •
Creating lookup tables
4. Sorting: Selection Sort
The 2025 paper asked for Bubble Sort (optionally). This makes Selection Sort a
very high-priority candidate for the 2026 exam.
Java
public void selectionSort(int[] arr) {
int n = [Link];
for (int i = 0; i < n - 1; i++) {
int minIdx = i;
// Find the minimum in unsorted part
for (int j = i + 1; j < n; j++) {
if (arr[j] < arr[minIdx]) {
minIdx = j;
}
}
// Swap the found minimum with the first element
int temp = arr[minIdx];
arr[minIdx] = arr[i];
arr[i] = temp;
}
}
C. Insertion Sort
import [Link];
public class InsertionSort {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of elements: ");
int n = [Link]();
int[] arr = new int[n];
[Link]("Enter array elements:");
for (int i = 0; i < n; i++) {
arr[i] = [Link]();
}
// Insertion Sort
for (int i = 1; i < n; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = key;
}
// Display sorted array
[Link]("Sorted Array:");
for (int i = 0; i < n; i++) {
[Link](arr[i] + " ");
}
[Link]();
}
}