EEE DS Question Bank
EEE DS Question Bank
4. Describe the difference between `const` and `#define` for defining constants in C.
15. Describe the syntax of `if`, `if-else`, and `nested if` statements in C.
17. What are looping statements in C? Give examples of `for`, `while`, and `do-while` loops.
23. What are strings in C? How are they represented and manipulated?
10. Implement a program to find the GCD (Greatest Common Divisor) of two numbers.
11. Write a C program to sort elements in an array using the bubble sort algorithm.
12. Implement a program to concatenate two strings without using the standard library
function.
14. Create a C program to swap two numbers without using a temporary variable.
Explain the stages involved in compiling and linking a C program. Discuss the role of each
stage in producing an executable file. Provide a step-by-step explanation with examples.
Define constants and variables in C programming. Explain the different data types available
in C with examples. Discuss the importance of data types in memory allocation and program
efficiency.
3. **Expressions Using Operators**:
Illustrate the use of arithmetic, relational, logical, and bitwise operators in C programming
with suitable examples. Explain operator precedence and associativity rules in evaluating
expressions.
Compare `printf()` and `scanf()` functions in C. Explain how formatted input and output
operations are managed in C programming. Provide examples demonstrating their usage.
Describe the syntax and usage of `if`, `else if`, and `else` statements in C. Provide a
comprehensive example that demonstrates nested decision-making based on multiple
conditions.
6. **Looping Statements**:
Discuss the `for`, `while`, and `do-while` loops in C programming. Provide examples of
each loop type and explain when each loop type is most appropriate to use.
Define strings in C and explain how they are represented and manipulated. Discuss string
handling functions such as `strlen()`, `strcpy()`, `strcat()`, and `strcmp()`. Provide examples
of each function.
Implement a C program that performs sorting of an array using the bubble sort algorithm.
Explain the algorithm's working principles and analyze its time complexity.
10. **Matrix Operations**:
Write a C program to perform matrix multiplication of two matrices. Discuss the algorithm
used, and explain the steps involved in multiplying matrices. Provide examples with different
sizes of matrices to demonstrate the correctness of your program.
You have been assigned to develop a Student Management System for a university. The
system needs to handle student records, including student ID, name, and grades for three
subjects (Mathematics, Physics, and English). The system should allow for inputting student
data, calculating averages, displaying student information, and generating reports.
Tasks:
1. Design a structure Student in C that includes fields for student ID (integer), name
(string), and grades in Mathematics, Physics, and English (float).
2. Implement functions to perform the following operations:
o inputStudentData(): This function should take input from the user for each
student's ID, name, and grades.
o calculateAverage(): This function should compute the average grade for each
student based on their grades in Mathematics, Physics, and English.
o displayStudentInfo(): This function should display the student's ID, name,
grades in each subject, and the calculated average grade.
3. Write a main program that allows the user to:
o Input data for multiple students.
o Calculate and display the average grade for each student.
o Display all student information including ID, name, grades, and average.
4. Ensure error handling for input operations and validate grades to be within the range
of 0 to 100.
5. Provide a menu-based interface where the user can choose options to input student
data, calculate averages, display student information, and exit the program.
6. Include appropriate comments and documentation to explain the purpose and
functionality of each function and section of code.
Additional Requirements:
Use appropriate data types and structures to efficiently store and manage student data.
Ensure that the program is modular, with functions dedicated to specific tasks to
promote code reusability and maintainability.
Implement error-checking mechanisms to handle invalid input gracefully.
Test the program with multiple students and verify the correctness of average
calculations and data display.
Note: You can assume that the maximum number of students that can be handled by the
system is predefined (e.g., 50 students).
Unit-II
Certainly! Here are 30 two-mark questions based on the topics of Functions, Pointers,
Recursion, Structures, Unions, and Storage classes in C programming:
### Functions
6. Explain the difference between `return 0;` and `return 1;` in a function.
10. How can a function return multiple values in C? Explain with an example.
### Recursion
12. Explain the base case and recursive case in recursion with an example.
13. What is the difference between direct recursion and indirect recursion?
### Pointers
29. What are storage classes in C? Explain the difference between `auto`, `static`, and
`extern`.
10. Implement a program to show the difference between `struct` and `union` in memory
allocation.
11. Write a C program to count the number of vowels in a string using pointers.
12. Create a function to find the maximum and minimum elements in an array.
15. Write a program to illustrate the use of pre-processor directives like `#define` and
`#ifdef`.
15 marks:
2. **Pointer Arithmetic**: Create a program that dynamically allocates memory for an array
of integers based on user input for size. Use pointers to initialize the array with user-entered
values, display the array, and calculate the sum of its elements.
3. **Recursion with File Operations**: Write a C program that recursively reads characters
from a text file until EOF is encountered. Print these characters in reverse order to another
text file using recursion.
8. **File Handling with Preprocessor Directives**: Create a C program that reads integers
from a text file, counts the occurrences of each integer, and prints the frequency of each
integer using preprocessor directives for file name definition and handling.
10. **String Manipulation with Pointers**: Design a program that reads a sentence from the
user, counts the number of words using pointers, and prints each word in reverse order.
12. **Handling Multiple Files with Storage Classes**: Write a C program that uses external
(global) and static variables to maintain counters for total number of lines, words, and
characters across multiple text files. Display the cumulative counts at the end.
13. **Matrix Operations with Function Pointers**: Create a C program that performs matrix
addition, subtraction, and multiplication using function pointers to select the operation based
on user input.
14. **Polynomial Operations using Structures**: Implement a C program that uses structures
to represent polynomials with coefficients and degrees. Include functions to add, subtract,
and multiply two polynomials.
15. **Error Handling with Preprocessor Macros**: Write a C program that reads integers
from a file, computes their average, and handles division by zero errors using preprocessor
macros for error checking and reporting.
You are tasked with implementing a payroll system for a small company. Each employee's
data includes their employee ID, name, hourly rate, and hours worked. Design a C program
using functions and pointers to calculate and display the weekly pay for each employee,
including overtime pay (1.5 times hourly rate for hours over 40).
You need to develop a C program to process a text file containing student records. Each
record includes student ID, name, and three test scores. Implement recursion to read these
records from the file, compute the average score for each student, and write the results to
another text file along with a grade (A, B, C, D, F) based on average score.
You are developing a system to manage inventory for a grocery store. Design a C program
using structures and unions where each product in inventory has a unique identifier, name,
price, and either weight or quantity depending on the type of product (solid or liquid).
Implement functions to add new products, update prices, and display inventory details.
You are working on a project where performance is critical. Design a C program that uses
`static` variables and pre-processor directives to maintain a cache of frequently accessed data.
Implement functions to update and retrieve data from this cache efficiently, ensuring minimal
overhead and maximum performance.
You are developing a student management system where each student's information
includes their roll number, name, and grades in three subjects. Design a C program that
dynamically allocates memory for an array of student structures based on user input for the
number of students. Implement functions to add new students, display all student details, and
calculate the average grade for the entire class.
Unit-III
1. Define an array.
o An array is a collection of elements identified by index or key, stored in
contiguous memory locations.
2. What is meant by array indexing?
o Array indexing is the process of accessing an element in the array using its
position number, starting from 0 in most programming languages.
3. How do you declare a one-dimensional array in C?
o int arr[10]; declares a one-dimensional array of integers with 10 elements.
4. What is the difference between a static array and a dynamic array?
o A static array has a fixed size determined at compile-time, whereas a dynamic
array can change size at runtime.
5. What are the advantages of using arrays?
o Arrays allow for efficient random access to elements and can be easily iterated
over.
6. Define a stack.
o A stack is a linear data structure that follows the Last In First Out (LIFO)
principle.
7. What operations are performed on a stack?
o The primary operations are push (inserting an element), pop (removing an
element), and peek (accessing the top element).
8. Define a queue.
o A queue is a linear data structure that follows the First In First Out (FIFO)
principle.
9. What are the main operations of a queue?
o The primary operations are enqueue (inserting an element at the rear) and
dequeue (removing an element from the front).
10. What is a circular queue?
o A circular queue is a linear data structure in which the last position is
connected back to the first position to make a circle.
Linked Lists
Evaluation of Expressions
include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int n = sizeof(arr) / sizeof(arr[0]);
int largest = arr[0];
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int n = sizeof(arr) / sizeof(arr[0]);
reverseArray(arr, 0, n-1);
#include <stdio.h>
#define MAX 5
void pop() {
if (top == -1)
printf("Stack underflow\n");
else
printf("Popped element: %d\n", stack[top--]);
}
void display() {
if (top == -1)
printf("Stack is empty\n");
else {
printf("Stack elements: ");
for (int i = top; i >= 0; i--)
printf("%d ", stack[i]);
printf("\n");
}
}
int main() {
push(10);
push(20);
push(30);
display();
pop();
display();
return 0;
}
#include <stdio.h>
#define MAX 5
void dequeue() {
if (front == -1)
printf("Queue underflow\n");
else {
printf("Dequeued element: %d\n", queue[front]);
if (front == rear) front = rear = -1;
else front++;
}
}
void display() {
if (front == -1)
printf("Queue is empty\n");
else {
printf("Queue elements: ");
for (int i = front; i <= rear; i++)
printf("%d ", queue[i]);
printf("\n");
}
}
int main() {
enqueue(10);
enqueue(20);
enqueue(30);
display();
dequeue();
display();
return 0;
}
Linked Lists
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
int main() {
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
head->data = 1;
head->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = NULL;
display(head);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
int main() {
struct Node* head = NULL;
insertAtBeginning(&head, 1);
insertAtBeginning(&head, 2);
insertAtBeginning(&head, 3);
display(head);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
struct Node* top = NULL;
void pop() {
if (top == NULL)
printf("Stack underflow\n");
else {
struct Node* temp = top;
printf("Popped element: %d\n", top->data);
top = top->next;
free(temp);
}
}
void display() {
struct Node* temp = top;
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
int main() {
push(10);
push(20);
push(30);
display();
pop();
display();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
struct Node* front = NULL;
struct Node* rear = NULL;
void dequeue() {
if (front == NULL)
printf("Queue underflow\n");
else {
struct Node* temp = front;
printf("Dequeued element: %d\n", front->data);
front = front->next;
if (front == NULL) rear = NULL;
free(temp);
}
}
void display() {
struct Node* temp = front;
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
int main() {
enqueue(10);
enqueue(20);
enqueue(30);
display();
dequeue();
display();
return 0;
}
Evaluation of Expressions
int stack[MAX];
int top = -1;
int pop() {
return stack[top--];
}
1. **Scenario:**
You are developing a simple image processing application. Each image is
represented by a 2D array where each element stores the pixel intensity value.
**Question:**
Write a function to rotate the image 90 degrees clockwise. How would you
represent the image as a 2D array and perform the rotation efficiently?
2. **Scenario:**
A web browser uses a stack to keep track of the pages visited in the current session.
When the user clicks the "back" button, the browser pops the most recently visited
page from the stack.
**Question:**
Design a stack-based system to manage the browser history, including methods for
visiting a new page, going back to the previous page, and displaying the current page.
### Linked Lists
3. Scenario:
You are tasked with creating a music playlist application where each song is a node
in a linked list. Users can add songs to the end of the playlist, remove songs, and skip
to the next or previous song.
Question:
Implement a singly linked list to manage the playlist. Include methods for adding,
removing, and traversing songs.
4. Scenario:
A ticketing system for a theater uses a queue to manage customers waiting to
purchase tickets. Each customer is represented as a node in a linked list.
Question:
Implement a queue using a linked list to manage the ticket line. Include methods for
enqueuing (adding a customer), dequeuing (removing a customer), and checking the
front of the queue.
Evaluation of Expressions
5. Scenario:
An arithmetic expression evaluator needs to compute the result of expressions
written in postfix notation (e.g., "3 4 + 2 * 7 /").
Question:
Design a stack-based algorithm to evaluate a postfix expression. Describe how you
would handle different operators and operands in the stack.
6. Scenario:
You are writing a program to perform arithmetic operations on polynomials. Each
polynomial is represented as a linked list where each node contains the coefficient and
exponent of a term.
Question:
Implement a function to add two polynomials represented by linked lists. Ensure
that the resulting polynomial is also represented as a linked list.
7. Scenario:
You are developing a feature for a social media platform where each user can post
messages. The messages are stored in a stack so that the most recent message can be
retrieved first. Additionally, users can comment on posts, and comments are stored in
a queue for each post to maintain the order in which they were received.
Question:
Design a system using stacks and queues implemented with linked lists to manage
posts and comments. Include methods for adding a new post, retrieving the most
recent post, adding a comment to a post, and retrieving all comments for a specific
post.
UNIT-IV
Applications of Trees
Graph Traversals
37. What is the difference between Depth-First Search (DFS) and Breadth-First
Search (BFS)?
38. Describe the process of Depth-First Search (DFS).
39. Describe the process of Breadth-First Search (BFS).
40. How is DFS used to detect cycles in a graph?
41. How is BFS used to find the shortest path in an unweighted graph?
42. Explain the importance of graph traversal in computer networks.
2. **Question:**
Given a binary tree represented as an array: `[1, 2, 3, 4, 5, None, 6]`, write a
function to convert this array representation to a linked list representation. Each node
should have attributes `value`, `left`, and `right`.
3. **Question:**
Write a function to perform an in-order traversal of the following binary tree and
return the list of visited nodes:
```
A
/\
B C
/\ \
D E F
```
4. **Question:**
Given a binary search tree with the following structure:
```
50
/ \
30 70
/\ /\
20 40 60 80
```
Write a function to insert a new node with value 65 into the BST.
5. **Question:**
Write a function to find the lowest common ancestor (LCA) of two given nodes in a
binary search tree. Assume the BST is represented as follows:
```
20
/ \
10 30
/ \
25 35
```
6. **Question:**
Implement a function to construct a Huffman tree given the following character
frequencies:
```
{'a': 5, 'b': 9, 'c': 12, 'd': 13, 'e': 16, 'f': 45}
```
7. **Question:**
Implement the union-find data structure with path compression. Write functions for
the `find` and `union` operations. Use this structure to solve the problem of detecting
cycles in an undirected graph represented by the following edge list:
```
[(0, 1), (1, 2), (2, 3), (3, 4), (4, 1)]
```
8. Question:
Given the following adjacency matrix representation of a graph, write a function to
convert it to an adjacency list representation:
```
0100
1011
0101
0110
```
Graph Traversals
9. Question:
Given the following graph represented as an adjacency list:
{
0: [1, 2],
1: [2],
2: [0, 3],
3: [3]
}
Write a function to perform a depth-first search (DFS) starting from node 2 and
return the list of visited nodes.
10. Question:
Given a weighted graph represented as an adjacency list:
{
'A': [('B', 1), ('C', 4)],
'B': [('A', 1), ('C', 2), ('D', 5)],
'C': [('A', 4), ('B', 2), ('D', 1)],
'D': [('B', 5), ('C', 1)]
}
Write a function to find the shortest path from node 'A' to node 'D' using Dijkstra's
algorithm and return the path and its cost.
1. **Scenario:**
You are designing a directory structure for a file system where each directory can
have multiple subdirectories or files, represented as nodes in a tree.
**Question:**
Implement a function to list all the files in the file system using a depth-first search
(DFS) traversal.
2. **Scenario:**
You are creating a program to evaluate arithmetic expressions stored in a binary tree
where each leaf node represents an operand and each internal node represents an
operator.
**Question:**
Write a function to evaluate the expression represented by the binary tree using
post-order traversal.
3. **Scenario:**
You are building a contact management system where each contact's name is stored
in a binary search tree for quick lookup, insertion, and deletion.
**Question:**
Implement a function to search for a contact by name in the BST. If the contact is
found, return the contact's details; otherwise, return a message indicating the contact
is not found.
4. **Scenario:**
You are developing a range query feature for the contact management system to
find all contacts whose names fall within a given alphabetical range.
**Question:**
Implement a function to perform a range query on the BST and return all contacts
within the specified range.
5. **Scenario:**
You are tasked with optimizing a company's network by compressing data
transmissions using Huffman coding.
**Question:**
Given the frequency of different data packets, write a function to build a Huffman
tree and generate the corresponding Huffman codes for each data packet.
6. **Scenario:**
You are developing a social network platform where you need to manage connected
components representing groups of friends. Each user is initially in their own set.
**Question:**
Implement the union-find data structure with path compression to efficiently
manage and query connected components (friend groups) as users connect with each
other.
7. **Scenario:**
You are working on a networking project that requires you to detect if there is a
loop in a given network of computers connected by cables.
**Question:**
Use the union-find data structure to detect cycles in the network, represented as an
undirected graph.
8. **Scenario:**
You are creating a mapping application where cities are nodes and roads are edges.
The adjacency list representation of the graph is used for efficient traversal.
**Question:**
Write a function to convert a list of roads (edges) into an adjacency list
representation of the graph.
9. **Scenario:**
You are developing a feature for a travel planning application that recommends the
shortest path between two cities. The cities and roads are represented as a weighted
graph.
**Question:**
Implement Dijkstra's algorithm to find the shortest path between two specified cities
in the graph and return the path and its total distance.
10. **Scenario:**
You are designing a maze-solving robot that needs to explore all possible paths in a
maze to find the exit. The maze is represented as a graph where each cell is a node.
**Question:**
Write a function to perform a breadth-first search (BFS) on the maze graph starting
from the entrance and return the path to the exit if it exists.
UNIT-V
30. **Question:** Describe what is meant by overflow in the context of hash tables.
31. **Question:** Explain the concept of separate chaining for overflow handling in
hash tables.
32. **Question:** Describe the open addressing method for handling overflow in
hash tables.
33. **Question:** How does double hashing work in handling overflow?
34. **Question:** Implement a simple hash table with open addressing using linear
probing for collision resolution.
35. Compare the space complexity of merge sort and quick sort.
36. Explain the divide-and-conquer approach in the context of sorting algorithms.
37. Describe a scenario where linear search is more efficient than binary search.
38. How does the choice of pivot affect the performance of quick sort?
39. Implement a function to perform binary search on a sorted linked list.
1. **Problem:**
You are given an unsorted array of integers. Write a function to find the first
occurrence of a given integer `x` in the array using linear search. Return the index of
`x` if found, otherwise return -1.
2. **Problem:**
You have a sorted array of integers. Write a function to find the position of a given
integer `x` using binary search. If the integer is not found, return -1.
3. **Problem:**
Implement the bubble sort algorithm to sort an array of integers in ascending order.
Print the array after each pass through the array.
4. **Problem:**
Write a function to sort an array of integers using insertion sort. Return the sorted
array.
5. **Problem:**
Implement the merge sort algorithm to sort an array of integers in ascending order.
Print the array after each merge operation.
6. **Problem:**
Write a function to sort an array of integers using quick sort. Choose the last
element as the pivot. Print the array after each partition operation.
**Array:** `[10, 7, 8, 9, 1, 5]`
7. **Problem:**
You need to design a hash table to store employee records. Each record contains an
employee ID and name. Implement the hash table using separate chaining to handle
collisions. Include methods to insert, delete, and search for an employee by ID.
**Operations:**
- Insert: `(123, "Alice")`, `(456, "Bob")`
- Search: `123`
- Delete: `123`
8. **Problem:**
Design a hash table to store student records with their IDs. Implement the hash table
using open addressing with linear probing to handle collisions. Include methods to
insert, delete, and search for a student by ID.
**Operations:**
- Insert: `(1, "John")`, `(2, "Jane")`, `(3, "Joe")`
- Search: `2`
- Delete: `1`
9. **Problem:**
You are given an unsorted array of integers. First, sort the array using merge sort,
then search for a given integer `x` using binary search. Return the index of `x` if
found, otherwise return -1.
10. Problem:
You are given a list of student records where each record contains the student’s
name and marks. Write a function to sort the records based on marks in descending
order using quick sort. Print the sorted list of records.
Linear Search
1. Scenario:
You are developing an application that requires searching for a specific product in a
large list of products based on the product ID. The products are listed in the order they
were added.
Question:
Implement a linear search algorithm to find the product by its ID. Given a list of
product IDs, write a function to return the index of the specified product ID or -1 if
not found.
Binary Search
2. You are creating a library management system. The books are sorted
alphabetically by their titles. You need a fast way to find if a particular book is
available.
Question:
Write a function using binary search to check if a given book title exists in the
sorted list of book titles. Return the index if the book is found, otherwise return -1.
Bubble Sort
3. You are developing a leaderboard for a gaming application where players' scores
need to be displayed in ascending order.
Question:
Implement the bubble sort algorithm to sort the players' scores. Show the sorted list
of scores after each pass.
Insertion Sort
4. Scenario:
You are implementing an auto-complete feature for a search engine where you need
to sort a list of recent searches entered by the user.
Question:
Write a function to sort the recent searches using insertion sort. Return the sorted
list of searches.
Merge Sort
5. You are tasked with merging and sorting two large datasets of customer
information from two different branches of a company.
Question:
Implement the merge sort algorithm to sort the combined dataset. Ensure that the
customer information is sorted by customer ID.
6. You are creating an application for managing large inventories. To quickly access
items, you need to sort the inventory based on item IDs.
Question:
Implement the quick sort algorithm to sort the inventory items by their IDs. Use the
last element as the pivot.
Hash Tables
7. Scenario:
You are building a cache system for a web server to store recently accessed pages.
Each page is identified by a unique URL.
Question:
Design a hash table with separate chaining to handle collisions. Implement methods
for inserting a page, retrieving a page, and deleting a page based on the URL.
Overflow Handling
8. Scenario:
You are developing a login system where usernames are stored in a hash table. To
handle potential collisions, you decide to use open addressing with quadratic probing.
Question:
Implement a hash table using open addressing with quadratic probing for collision
resolution. Include methods for inserting, searching, and deleting usernames.
9. Scenario:
You are creating a movie database application. First, you need to sort the movies
based on their release dates, and then search for a specific movie by its title.
Question:
Implement a function to sort the movies using merge sort based on their release
dates and then use binary search to find a movie by its title.
10. Scenario:
You are developing a report card system for a school. The system needs to sort
students based on their grades in descending order to determine class rankings.
Question:
Write a function to sort the students' records using quick sort based on their grades.
Print the sorted list of students with their grades.