Bangladesh Bank
Post: Assistant Director (ICT),
Exam Date: 07.02.2025, Exam Taker: DU(CSE)
1. Convert the array (56,33,48,29,99,12 and 344) into min heap.
Initial array as a binary tree:
56
/ \
33 48
/ \ / \
29 99 12 344
Swap 48 and 12:
56
/ \
33 12
/ \ / \
29 99 48 344
Swap 33 and 29:
56
/ \
29 12
/ \ / \
33 99 48 344
Swap 56 and 12:
12
/ \
29 56
/ \ / \
33 99 48 344
Swap 56 and 48:
12
/ \
29 48
/ \ / \
33 99 56 344
Final Result
The array now satisfies the min heap property: every parent node is smaller than or equal to its children.
12
/ \
29 48
/ \ / \
33 99 56 344
2. Write the pseudocode/ program (in any language) to print the common element between two arrays and the total number of such elements found. [assume each element in an array distinct].
#include <iostream>
using namespace std;
int main() {
int size1, size2;
// Taking input size of first array
cout << "Enter size of first array: ";
cin >> size1;
int arr1[size1];
cout << "Enter elements of first array:\n";
for (int i = 0; i < size1; i++) {
cin >> arr1[i];
}
// Taking input size of second array
cout << "Enter size of second array: ";
cin >> size2;
int arr2[size2];
cout << "Enter elements of second array:\n";
for (int i = 0; i < size2; i++) {
cin >> arr2[i];
}
// To store common elements
int commonElements[size1 < size2 ? size1 : size2];
int count = 0;
// Check each element in arr1 against arr2
for (int i = 0; i < size1; i++) {
bool found = false;
for (int j = 0; j < size2; j++) {
if (arr1[i] == arr2[j]) {
found = true;
break;
}
}
if (found) {
// Check for duplicates
bool alreadyExists = false;
for (int k = 0; k < count; k++) {
if (commonElements[k] == arr1[i]) {
alreadyExists = true;
break;
}
}
if (!alreadyExists) {
commonElements[count] = arr1[i];
count++;
}
}
}
// Print common elements
cout << "Common elements: ";
for (int i = 0; i < count; i++) {
cout << commonElements[i] << " ";
}
cout << endl;
// Print total count
cout << "Total number of common elements: " << count << endl;
return 0;
}
Sample I/O:
Enter size of first array: 5
Enter elements of first array: 0 20 30 40 50
Enter size of second array: 6
Enter elements of second array: 10 2 20 30 60 90
Common elements: 20 30
Total number of common elements: 2
=== Code Execution Successful ===3.Given a logical function, find out the truth table of AB· (A+B).C

