Data structures
Data structures
2025-01-06
Types:
1. Linear:
Arrays, structure, union, Linked list, stack, queue
2. Non-Linear
Graph, tree, hash table
Question
implement a c program to store 5 integers read from the user and display the
same.
Todo
Assignments:
2025-01-07
Linked Lists
What is a linked list
It is a linear data structure
Types
node
4555
10 6000
6000
20 6420
6420
30 NULL
The first node is identified by a Head pointer.
the end of the pointer is identified by its link. It will be NULL.
struct SLL{
int data;
struct SLL *link;
}
Note
2025-01-08
void display(){
while(temp!=NULL){
printf("%d\n",temp->data);
temp=temp->link;
}
2025-01-09
Question
q. create a singly linked list with as many nodes as requested by the user and
search for the data if present in the linked list or not.
3 parts in a node
Data
*prev
*next
traversal is possible in forward and reverse direction
*head is used to indicate first node
*prev is NULL for first node
*next is NULL for last node
2025-01-15
Question
1. Write a c program to create a doubly linked list with as many nodes as the
user want. Insert the data read by the user. Implement a menu driven
program with operations with insert front, insert end, display, reverse.
2. Implement a c program to sort the linked list in ascending and descenting
order. Display before and after the sorting.
3. circular linked list
2025-01-20
Question
2025-01-21
Stack
What is a stack?
Linear data structure
Organizes data in a Last In First Out manner. (LIFO)
The data is inserted and removed through a top pointer
basic operations:
- push: Adding data to the stack
- pop: Remove data from the stack
Implemented using either arrays or linked lists
Queue
What is a Queue?
Linear data structure
organizes data in a FIFO manner or LILO manner.
Data is inserted through rear.
Data is removed through front.
Basic operations:
- enqueue: add data to queue
- dequeue: remove data from queue
implemented using either arrays or linked lists.
Question
2025-01-22
Question
2025-01-23
Question
1. Inorder Traversal:
Left ==> Root ==> Right
Always gives data in ascending order.
2. preorder Traversal:
Root ==> Left ==> Right
3. PostOrder Traversal:
Left ==> Right ==> Root
2025-01-28
Question
2025-01-29
Todo
Graph
Graph is a collection of vertices and edges.
Edge: connection between two vertices.
Vertex: it holds data.
Represented using adjacency matrix.
Directional graph is when an edge has a specific direction.
1 in the graph means one is connected to the other vertex but not the other
way around.
v0 v1 V2 V3
V0 0 1 1 1
V1 0 0 1 0
V2 0 0 0 1
V3 0 0 0 0
2025-01-30
Traversal
2025-01-31
Assignments:
2025-01-07
Question
1. Explain the structure of a node in a singly linked list. How do you initialie
it?
2. What is the difference between pass by value and pass by address in C.
Demonstrate with examples.
3. How are functions stored in memory? How is their execution handled
during run-time?
4. Differentiate between for, while and do-while loops. provide use cases for
each.
5. Explain the concept of nested loops. Write a program to print a
multiplication table using nested loops.
6. Explain the storage classes in C. Provide examples for each.
7. When should you use register storage class? Can you get the address of a
register variable? why or why not?
8. Write a program to demonstrate the use of static variables in a function.
2025-01-08
Todo
2025-01-21
Question
1. Write a C program to create a stack using linked lists and perform the push
and pop operations.
2. Write a C program to create a queue using linked lists and perform the
operations enqueue dequeue and display.
3. What is a stack and how does it differ from a queue?
4. Explain the LIFO principle of a stack with an example.
5. Write a program to implement a stack using dynamic array.
6. Explain the operations of a stack with examples.
7. What happens when a stack is full , how can it be handled?
8. Differentiate between static and dynamic stack implementations.
9. Explain thee FIFO principle of a Queue with an example.
10. What happens when a queue is full, how can it be handled?
11. Explain circular queue.
2025-01-23
Question
2025-01-28
Question
1. Explain the difference between a binary tree and a binary seach tree
2. what are the advantages of using binary seach tree over an array or a
linked list.
3. What is the height of a binary tree and how is it calculated.
4. Explain the difference between preorder, inorder and post order traversal.
5. What traversal of a binary search tree produces a sorted list of elements.
6. How do you insert a node into a binary search tree. Describe the algorithm.
7. How do you delete a node from a binary search tree: with no child node,
one child and with two children. Explain the algorithm.
2025-01-29
Todo
2025-01-30
Question
2025-02-05
Question
2025-02-07
Todo
Questions
1. What are the differences between printf and puts
2. Explain the difference between static and extern storage classes in C
3. What is the output of the following code snippet?
int a = 10;
printf("%d %d %d", a++, ++a, a);
4. How does pointer arithmetic work in C. Provide an example.
5. Malloc and calloc.
6. Explain function pointers in C with an example.
7. How does realloc function work in DMA.
8. Why is free() function necessary in C and what happens if it is not used?
9. What is the difference between pass by value and pass by address in C?
10. Can you return a local variable from a function. Why or why not?
11. How can you implement a 2D array dynamically using pointers?
12. Explain the difference between array name and pointer in C.
13. Can a function modify an array passed to it? Demonstrate with code.
14. What is a null pointer and hoe is it different from an uninitialized pointer?
15. What are the advantages of using structures over arrays?
16. How do you compare two structures in C?
17. What is the key difference between struct and union?
18. How is memory allocated for a structure with bit fields?
19. Can you create a self referential structure? Provide an example.
20. Write a function to detect a loop in a linked list.
21. How do you reverse a singly linked list?
22. Compare singly and doubly linked lists in terms of operations
23. Explain how to delete a node in a linked list given only a pointer to that node.
24. What are the advantages of circular linked lists over singly linked lists
25. How do you implement a stack using an array.
26. Implement a Queue using two stacks
27. What is the advantage of a circular queue over a linear queue
28. How can you detect stack overflow in a recursive function
29. How does merge sort use the divide and conquer approach?
30. Compare linear search and binary search in terms of efficiency
31. Implement a sorting algorithm and explain its working
32. What is the difference between a binary tree and a binary search tree?
33. Write a function to find the height of a binary tree
34. How does breadth first search differ from depth first search.
35. How would you detect a cycle in an undirected graph?
36. You have an array where each element represents the maximum steps that can be
jumped forward. Find the minimum jumps required to reach the last index.
37. Find the missing number in an array containing numbers from one to n with one
missing number.
38. You are given an array where every element appears twice except one. Find the
unique element.
39. Given a string check if it is palindrome or not.
40. A person has two hour glasses. one runs for 7 minutes and the other for 11
minutes. How can they time exactly 15 minutes.
41. You have 3 bulbs in a room and 3 switches outside. You can only enter the room
once. How do you determine which switch controls which bulb
42. A train leaves station A at 6am and reach station B at 10am. another train leave B
at 11am and reaches A at 12pm at what time will the two trains meet.
43. There are 100 lockers and 100 students. The first student opens all the lockers.
Toggles all the 2nd locker. The 3rd student toggles every 3rd locker and so on.
Which lockers remain opened at the end.
44. You have a 3 litre jug and a 5 litre jug. How do you measure exactly 4 litres using
these jugs?