0% found this document useful (0 votes)
77 views33 pages

EEE DS Question Bank

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

EEE DS Question Bank

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

1. What is the role of the preprocessor in C programming?

2. Explain the difference between `#include <stdio.h>` and `#include "myfile.h"` in C.

3. How are constants defined in C? Give an example.

4. Describe the difference between `const` and `#define` for defining constants in C.

5. What are variables in C? How do you declare and initialize them?

6. Explain the scope of a variable in C.

7. What are the basic data types available in C?

8. Differentiate between `int`, `float`, and `char` data types in C.

9. How are expressions formed in C? Give an example.

10. Explain the order of precedence and associativity of operators in C.

11. What are the unary, binary, and ternary operators in C?

12. How does C manage input and output operations?

13. Explain the difference between `printf()` and `scanf()` functions in C.

14. What is a decision-making statement in C? Give an example.

15. Describe the syntax of `if`, `if-else`, and `nested if` statements in C.

16. How does the `switch` statement work in C? Provide an example.

17. What are looping statements in C? Give examples of `for`, `while`, and `do-while` loops.

18. Explain the difference between `break` and `continue` statements in C.

19. How do you declare and initialize a one-dimensional array in C?

20. Explain how elements are accessed in a one-dimensional array in C.

21. What is a two-dimensional array? How do you declare and initialize it in C?

22. Describe how elements are accessed in a two-dimensional array in C.

23. What are strings in C? How are they represented and manipulated?

24. Explain the difference between a string and a character array in C.

25. How do you concatenate two strings in C?

26. What are string functions in C? Give examples.

27. How do you sort elements in an array using C? Provide an example.


28. Explain the binary search algorithm and how it can be implemented in C.

29. How do you perform matrix addition in C?

30. Explain how matrix multiplication is performed in C.

1. Write a C program to calculate the factorial of a number using a `for` loop.

2. Write a program to find the largest element in an array of integers.

3. Implement a C program to check if a given number is prime or not.

4. Write a program to reverse a string entered by the user.

5. Create a C program to find the sum of elements in an array using pointers.

6. Write a program to check if two strings are anagrams or not.

7. Implement a C program to perform linear search in an array.

8. Write a program to convert a decimal number to binary.

9. Create a C program to transpose a matrix.

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.

13. Write a program to find the Fibonacci series up to n terms.

14. Create a C program to swap two numbers without using a temporary variable.

15. Write a program to calculate the sum of digits of a number recursively.

1. **Compilation and Linking Processes**:

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.

2. **Constants, Variables, and Data Types**:

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.

4. **Managing Input and Output Operations**:

Compare `printf()` and `scanf()` functions in C. Explain how formatted input and output
operations are managed in C programming. Provide examples demonstrating their usage.

5. **Decision Making and Branching**:

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.

7. **Arrays - Initialization and Declaration**:

Explain the process of declaring and initializing one-dimensional and two-dimensional


arrays in C. Provide examples that demonstrate how arrays are accessed and manipulated
using index notation.

8. **Strings and String Operations**:

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.

9. **Sorting and Searching Algorithms**:

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

Functions - Pass by value - Pass by reference - Recursion - Pointers - Definition -


Initialization - Pointers arithmetic. Structures and unions - definition - Structure within a
structure - Union - Programs using structures and Unions - Storage classes, Pre-processor
directives

Certainly! Here are 30 two-mark questions based on the topics of Functions, Pointers,
Recursion, Structures, Unions, and Storage classes in C programming:

### Functions

1. What is a function in C? Why are functions used?

2. Explain the difference between function declaration and function definition.

3. How are parameters passed to functions in C? Explain with an example.

4. What is pass by value in function arguments? Provide an example.

5. Describe pass by reference in C functions using pointers. Give an example.

6. Explain the difference between `return 0;` and `return 1;` in a function.

7. How do you declare a function that returns a pointer in C?

8. What is function overloading? Does C support function overloading?

9. Write a function in C to swap two integers using call by reference.

10. How can a function return multiple values in C? Explain with an example.

### Recursion

11. Define recursion in C. Give an example of a recursive function.

12. Explain the base case and recursive case in recursion with an example.

13. What is the difference between direct recursion and indirect recursion?

14. Write a recursive function to calculate the factorial of a number.

### Pointers

15. What is a pointer in C? How is it different from a normal variable?

16. Explain the relationship between pointers and arrays in C.


17. How do you declare a pointer to a function in C?

18. Write a program to swap two integers using pointers.

19. Explain the significance of `NULL` pointer in C.

20. What are pointer arithmetic operations? Give examples.

21. How do you pass an array to a function using pointers in C?

### Structures and Unions

22. Define a structure in C. Provide an example declaration.

23. Explain the difference between a structure and a union in C.

24. Write a program to demonstrate nested structures in C.

25. How are members accessed in a structure and a union?

26. What is the size of a structure and a union in C?

27. How are structures passed as arguments to functions?

28. Write a C program to implement a stack using a structure.

Storage Classes and Pre-processor Directives

29. What are storage classes in C? Explain the difference between `auto`, `static`, and
`extern`.

30. Describe the purpose of pre-processor directives in C. Give examples of common


directives.

Certainly! Here are 15 small program-based questions focusing on functions, pointers,


recursion, structures, unions, storage classes, and pre-processor directives in C programming:

1. Write a C program to swap two numbers using call by value.

2. Implement a program to find the sum of elements in an array using a function.

3. Write a C program to reverse a string using a recursive function.

4. Create a program to demonstrate pointer arithmetic in C.

5. Write a function to check if a given number is palindrome or not.


6. Implement a program to concatenate two strings using pointers.

7. Write a C program to calculate the area of a circle using a function.

8. Create a program to demonstrate the use of `typedef` with structures.

9. Write a recursive function to compute the Fibonacci series up to n terms.

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.

13. Write a program to demonstrate the use of `static` variables in C functions.

14. Implement a C program to sort an array of structures based on a specific field.

15. Write a program to illustrate the use of pre-processor directives like `#define` and
`#ifdef`.

15 marks:

1. **Function with Structures**: Write a C program that uses a structure to represent a


student with fields for roll number, name, and marks in three subjects. Implement functions
to input data, display data, calculate total marks, and compute average marks of the student.

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.

4. **Sorting with Function Pointers**: Implement a C program that sorts an array of


structures where each structure contains a student's roll number and marks using a sorting
function that accepts a function pointer to compare two structures based on roll number or
marks.
5. **Union for Currency Conversion**: Design a C program using a union to represent
amounts in dollars and euros. Implement functions to convert amounts between dollars and
euros using the union and display the converted amount based on user input.

6. **Dynamic Memory Allocation**: Write a program to dynamically allocate memory for a


2D array of integers based on user input for dimensions. Implement functions to initialize the
array with random numbers, display the array, and compute the sum of all elements.

7. **Stack Implementation with Structures**: Implement a stack data structure using a


structure to represent each stack node. Include functions to push, pop, and display elements
of the stack using dynamic memory allocation and pointers.

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.

9. **Binary Search Tree Operations**: Write a C program to implement basic operations


(insertion, deletion, searching) on a Binary Search Tree (BST) using dynamic memory
allocation and recursion.

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.

11. **Handling Complex Numbers with Structures**: Implement a C program using


structures to represent complex numbers. Include functions to perform addition, subtraction,
multiplication, and division of two complex numbers.

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.

1. **Scenario 1 - Function and Pointers**:

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

2. **Scenario 2 - Recursion and File Handling**:

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.

3. **Scenario 3 - Structures and Unions**:

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.

4. **Scenario 4 - Storage Classes and Pre-processor Directives**:

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.

5. **Scenario 5 - Dynamic Memory Allocation and Pointers**:

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

Arrays and its Representations

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.

Prefix to Infix Conversion? (solution)

o For example, if the given expression is *-A/BC-/AKL then your program


should print ((A-(B/C))*((A/K)-L)).
o

Read more: https://javarevisited.blogspot.com/2022/02/-stack-and-


queue-data-structure-interview-questions.html#ixzz8g14EJH7H

Stacks and Queues

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

11. Define a linked list.


o A linked list is a linear data structure in which elements are stored in nodes,
with each node pointing to the next node via a reference or pointer.
12. What are the types of linked lists?
o The main types are singly linked lists, doubly linked lists, and circular linked
lists.
13. What is a doubly linked list?
o A doubly linked list is a linked list where each node has two references: one to
the next node and one to the previous node.
14. What is the advantage of using a linked list over an array?
o Linked lists offer dynamic memory allocation and ease of insertion and
deletion of elements.
15. How do you traverse a linked list?
o To traverse a linked list, start from the head node and follow the next pointers
until reaching the end.

Linked List-based Implementation of Stacks and Queues

16. How is a stack implemented using a linked list?


o A stack can be implemented using a linked list by using the head of the list as
the top of the stack for push and pop operations.
17. How is a queue implemented using a linked list?
o A queue can be implemented using a linked list by maintaining two pointers:
front and rear for enqueue and dequeue operations.
18. What is the benefit of implementing a stack using a linked list?
o Implementing a stack using a linked list allows for dynamic memory
allocation, avoiding overflow issues common in array-based stacks.
19. What is the benefit of implementing a queue using a linked list?
o Implementing a queue using a linked list allows for dynamic memory
allocation and efficient enqueue and dequeue operations without shifting
elements.
20. How do you check if a linked list-based stack is empty?
o A linked list-based stack is empty if the head node is null.

Evaluation of Expressions

21. What is an infix expression?


o An infix expression is a mathematical expression where operators are placed
between operands, e.g., A + B.
22. What is a postfix expression?
o A postfix expression is a mathematical expression where operators follow
their operands, e.g., AB+.
23. What is a prefix expression?
o A prefix expression is a mathematical expression where operators precede
their operands, e.g., +AB.
24. What is the advantage of using postfix notation?
o Postfix notation eliminates the need for parentheses and operator precedence
rules, simplifying expression evaluation.
25. What data structure is used for evaluating postfix expressions?
o A stack is typically used for evaluating postfix expressions.

Linked List-based Polynomial Addition

26. How are polynomials represented using linked lists?


o Polynomials are represented using linked lists where each node contains a
coefficient and an exponent.
27. What is the advantage of using linked lists for polynomial representation?
o Linked lists allow for dynamic storage of terms and efficient operations like
insertion and deletion of terms.
28. How do you add two polynomials using linked lists?
o Traverse both polynomial lists simultaneously, add coefficients of nodes with
the same exponent, and create new nodes for the result.
29. What is a term in the context of polynomial representation?
o A term is a pair consisting of a coefficient and an exponent, representing one
part of the polynomial.
30. How do you handle different exponents when adding polynomials using linked
lists?
o Align terms by their exponents, add coefficients for matching exponents, and
directly append non-matching terms to the result list.

1.Write a C program to find the largest element in an array.

include <stdio.h>

int main() {
int arr[] = {10, 20, 30, 40, 50};
int n = sizeof(arr) / sizeof(arr[0]);
int largest = arr[0];

for (int i = 1; i < n; i++) {


if (arr[i] > largest) {
largest = arr[i];
}
}

printf("Largest element: %d\n", largest);


return 0;
}

2.Write a C program to reverse an array.

#include <stdio.h>

void reverseArray(int arr[], int start, int end) {


int temp;
while (start < end) {
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}

int main() {
int arr[] = {1, 2, 3, 4, 5};
int n = sizeof(arr) / sizeof(arr[0]);

reverseArray(arr, 0, n-1);

printf("Reversed array: ");


for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
return 0;
}

3.Write a C program to implement stack operations using an array.

#include <stdio.h>
#define MAX 5

int stack[MAX], top = -1;

void push(int value) {


if (top == MAX - 1)
printf("Stack overflow\n");
else
stack[++top] = value;
}

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

3. 4. Write a C program to implement queue operations using an array.

#include <stdio.h>
#define MAX 5

int queue[MAX], front = -1, rear = -1;

void enqueue(int value) {


if (rear == MAX - 1)
printf("Queue overflow\n");
else {
if (front == -1) front = 0;
queue[++rear] = value;
}
}

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

5. Write a C program to create and display a singly linked list.

#include <stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node* next;
};

void display(struct Node* head) {


struct Node* temp = head;
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}

int main() {
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;

head = (struct Node*)malloc(sizeof(struct Node));


second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));

head->data = 1;
head->next = second;

second->data = 2;
second->next = third;

third->data = 3;
third->next = NULL;

display(head);
return 0;
}

6. Write a C program to insert a node at the beginning of a singly linked list.

#include <stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node* next;
};

void insertAtBeginning(struct Node** head, int newData) {


struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = newData;
newNode->next = *head;
*head = newNode;
}

void display(struct Node* head) {


struct Node* temp = head;
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}

int main() {
struct Node* head = NULL;

insertAtBeginning(&head, 1);
insertAtBeginning(&head, 2);
insertAtBeginning(&head, 3);

display(head);
return 0;
}

Linked List-based Implementation of Stacks and Queues

7. Write a C program to implement a stack using a linked list.

#include <stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node* next;
};
struct Node* top = NULL;

void push(int value) {


struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = value;
newNode->next = top;
top = newNode;
}

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

8. Write a C program to implement a queue using a linked list.

#include <stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node* next;
};
struct Node* front = NULL;
struct Node* rear = NULL;

void enqueue(int value) {


struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = value;
newNode->next = NULL;
if (rear == NULL) {
front = rear = newNode;
} else {
rear->next = newNode;
rear = newNode;
}
}

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

9. Write a C program to evaluate a postfix expression.


#include <stdio.h>
#include <ctype.h>
#define MAX 100

int stack[MAX];
int top = -1;

void push(int value) {


stack[++top] = value;
}

int pop() {
return stack[top--];
}

int evaluatePostfix(char* exp) {


for (int i = 0; exp[i]; i++) {
if (isdigit(exp[i])) {
push(exp[i] - '0');
} else {
int val1 = pop();
int val2 = pop();
switch (exp[i]) {
case '+': push(val2 + val1); break;
case '-': push(val2 - val1); break;
case '*': push(val2 * val1); break;
case '/': push(val2 /

Arrays and Its Representations

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?

### Stacks and Queues

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.

Linked List-Based Implementation of Stacks and Queues

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.

Linked List-Based Polynomial Addition

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.

Advanced Scenario (Combining Concepts)

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

Trees and Binary Trees

1. Define a binary tree.


2. What is the maximum number of nodes in a binary tree of height \(h\)?
3. Explain the difference between a full binary tree and a complete binary tree.
4. Describe the structure of a binary tree node.
5. What is a leaf node in a binary tree?
6. How do you calculate the height of a binary tree?
7. Explain the concept of tree traversal.

Binary Tree Representation and Traversals

8. Describe pre-order traversal of a binary tree.


9. Describe in-order traversal of a binary tree.
10. Describe post-order traversal of a binary tree.
11. How is a binary tree represented using an array?
12. How is a binary tree represented using linked lists?
13. Write the pre-order traversal sequence for the following binary tree:
```
A
/\
B C
/\ \
D E F
```
14. **Question:** Write the in-order traversal sequence for the following binary tree:
```
A
/\
B C
/\ \
D E F
```
15. Write the post-order traversal sequence for the following binary tree:
```
A
/\
B C
/\ \
D E F
```

Binary Search Trees (BSTs)

16. Define a binary search tree (BST).


17. What are the key properties of a binary search tree?
18. Describe how to insert a node into a binary search tree.
19. Describe how to delete a node from a binary search tree.
20. Explain how to search for a value in a binary search tree.
21.Describe how to find the minimum value in a binary search tree.
22. Describe how to find the maximum value in a binary search tree.

Applications of Trees

23. List two applications of binary trees in computer science.


24. How are binary search trees used in databases?
25. Explain how Huffman coding uses binary trees.
26. Describe the use of trees in the implementation of file systems.

Set Representations and Union-Find Operations

27. Explain the concept of disjoint-set data structure.


28. Describe the union operation in a disjoint-set data structure.
29. Describe the find operation in a disjoint-set data structure.
30. Explain the concept of path compression in union-find operations.

Graph and Its Representations

31. Define a graph in computer science.


32. What is the difference between a directed and an undirected graph?
33. How can a graph be represented using an adjacency matrix?
34. How can a graph be represented using an adjacency list?
35. Describe the term "degree" of a vertex in a graph.
36. Explain the concept of a weighted graph.

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.

Sure! Here are 10 problem-based questions based on the provided syllabus:

### Trees and Binary Trees


1. **Question:**
Given the following binary tree:
```
1
/\
2 3
/\ \
4 5 6
```
Write a function to perform a level-order traversal (breadth-first traversal) of the
tree and return the list of visited nodes.

### Binary Tree Representation and Traversals

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
```

### Binary Search Trees (BSTs)

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
```

### Applications of Trees

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

### Set Representations and Union-Find Operations

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)]
```

Graph and Its Representations

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.

Certainly! Here are 10 scenario-based questions based on the provided syllabus:

### Trees and Binary Trees

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.

### Binary Tree Representation and Traversals

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.

### Binary Search Trees (BSTs)

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.

### Applications of Trees

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.

### Set Representations and Union-Find Operations

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.

### Graph and Its Representations

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.

### Graph Traversals

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.

These scenario-based questions are designed to test practical understanding and


application of concepts in real-world situations.

UNIT-V

. Here are 30 two-mark questions based on the provided syllabus:

### Linear Search

1. **Question:** What is linear search?


2. **Question:** Write the time complexity of linear search in the best and worst
case.
3. **Question:** How does linear search differ from binary search?
4. **Question:** Implement a linear search algorithm to find an element in an
unsorted array.

### Binary Search

5. **Question:** Define binary search.


6. **Question:** What is the precondition for using binary search on a dataset?
7. **Question:** Write the time complexity of binary search in the best and worst
case.
8. **Question:** Explain how binary search can be implemented using recursion.
9. **Question:** Given a sorted array, implement an iterative binary search algorithm
to find an element.

### Bubble Sort

10. **Question:** Describe the bubble sort algorithm.


11. **Question:** Write the time complexity of bubble sort in the best and worst
case.
12. **Question:** Why is bubble sort not suitable for large datasets?
13. **Question:** Implement the bubble sort algorithm to sort an array of integers.

### Insertion Sort

14. **Question:** Explain the insertion sort algorithm.


15. **Question:** Write the time complexity of insertion sort in the best and worst
case.
16. **Question:** Describe a situation where insertion sort is preferable over other
sorting algorithms.
17. **Question:** Implement the insertion sort algorithm to sort an array of integers.

### Merge Sort

18. **Question:** Describe the merge sort algorithm.


19. **Question:** Write the time complexity of merge sort in the best and worst case.
20. **Question:** Explain how merge sort is different from bubble sort and insertion
sort.
21. **Question:** Implement the merge sort algorithm to sort an array of integers.

### Quick Sort

22. **Question:** Explain the quick sort algorithm.


23. **Question:** Write the time complexity of quick sort in the best and worst case.
24. **Question:** What is the pivot element in quick sort and how is it chosen?
25. **Question:** Implement the quick sort algorithm to sort an array of integers.

### Hash Tables

26. **Question:** Define a hash table.


27. **Question:** Explain the concept of a hash function.
28. **Question:** What are the advantages of using hash tables over arrays?
29. **Question:** Implement a simple hash table with separate chaining for collision
resolution.

### Overflow Handling

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.

### General Sorting and Searching

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.

Sure! Here are 10 problem-based questions based on the provided syllabus:


### Linear Search

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.

**Array:** `[3, 5, 1, 4, 2]`

**Element to find:** `4`

### Binary Search

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.

**Array:** `[1, 3, 5, 7, 9, 11, 13, 15]`

**Element to find:** `7`

### Bubble Sort

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.

**Array:** `[64, 34, 25, 12, 22, 11, 90]`

### Insertion Sort

4. **Problem:**
Write a function to sort an array of integers using insertion sort. Return the sorted
array.

**Array:** `[12, 11, 13, 5, 6]`

### Merge Sort

5. **Problem:**
Implement the merge sort algorithm to sort an array of integers in ascending order.
Print the array after each merge operation.

**Array:** `[38, 27, 43, 3, 9, 82, 10]`

### Quick Sort

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]`

### Hash Tables

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`

### Overflow Handling

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`

### Combined Sorting and Searching

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.

Array: `[29, 10, 14, 37, 13]`

Element to find: `14`

Practical Application of Sorting

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.

Records: `[("John", 75), ("Jane", 85), ("Dave", 80), ("Emily", 95)]`

These problem-based questions will test the understanding and application of


searching, sorting algorithms, and hash tables in practical scenarios.
Sure! Here are 10 scenario or real-time application-based questions based on the
provided syllabus:

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.

### Quick Sort

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.

Combined Sorting and Searching

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.

Practical Application of Sorting

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.

You might also like