Important- Practice Sheet Final ( Array, Stack, Queue, Linked List)
Important- Practice Sheet Final ( Array, Stack, Queue, Linked List)
LINKED LIST
Array:
1. WAC program to find the largest and second largest element in an
array.
2. WAC program to find the maximum and minimum number in an
array(Or find min and second min element).
3. WAC program to reverse an array.
4. WAC program to rotate an array.
5. WAC to generate all the subarrays that has a certain sum (sum may
be any number, you have to generate such pairs that makes up that
sum).
6. WAC to perform insertion and deletion of an element in array.
7. WAC program for removing duplicates from an array.
8. WAC program to sort an array.
9. WAC program for union and intersection of two arrays.
10. WAC program to merge two given arrays.
11. Write a program in C to count the frequency of each element of
an array.
Test Data:
Input the number of elements to be stored in the array :3
Input 3 elements in the array:
element - 0: 25
element - 1: 12
element - 2: 43
Expected Output:
The frequency of all elements of an array:
25 occurs 1 times
12 occurs 1 times
43 occurs 1 times
12. WAC program for addition of two matrices, transpose of a
matrix.
13. Write a program in C to find the sum of the right diagonals
of a matrix.
Hint: for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
printf("element - [%d],[%d] : ", i, j);
scanf("%d", &arr1[i][j]);
if (i == j) {
sum = sum + arr1[i][j];
}
}
}
14. WAC program to print the sum of rows and columns of a
given matrix.
Hint: Initialize two matrices first,
Then for calculation sum of rows:
for (i = 0; i < n; i++) {
rsum[i] = 0;
for (j = 0; j < n; j++) {
rsum[i] = rsum[i] + arr1[i][j];
}
}
Calculate sum of columns:
for (i = 0; i < n; i++) {
csum[i] = 0;
for (j = 0; j < n; j++) {
csum[i] = csum[i] + arr1[j][i];
}
}
15. Write a program in C to find the missing number in a given
array. There are no duplicates in the list.
Expected Output :
The given array is : 1 3 4 2 5 6 9 8
The missing number is : 7
Hint: int pickMissNumber(int *arr1, int ar_size) {
int i, sum = 0, n = ar_size + 1;
Output:
The given array is: 1 3 4 7 8 9 9 10
The ceiling of 5 is: 7
Hint:
void sort_stack() {
int temp;
int sortedTop = -1; - Top of the stack used for sorting
- Sorting logic
while (top != -1) {
temp = pop();
while (sortedTop != -1 && sorted_Stack[sortedTop] < temp) {
push(sorted_Stack[sortedTop]);
sortedTop--;
}
sortedTop++;
sorted_Stack[sortedTop] = temp;
}
return minStack[min_Top];
2. Write a C program to swap the Nth Node from beg with Nth
node for end.
Hint: Count the number of nodes in Linked List
Then;
if (k > n) return;
if (2 * k - 1 == n) return;
Initialise two pointers or beg and end;
struct Node *a = *head, *b = *head;
for (int i = 1; i < k; i++)
a = a->next;
for (int i = 1; i < n - k + 1; i++)
b = b->next;
Swap :
int t = a->data;
a->data = b->data;
b->data = t;
}