Tushar AP4.
Tushar AP4.
Experiment 4
Student Name: Tushar Singh UID: 22BCS15923
Branch:CSE Section/Group:622/B
Semester: 5 Date of Performance:20/8/24
Subject Name: Advanced Programming Lab-1 Subject Code: 22CSP-314
2. Aim: Given a list of unsorted integers, arr, find the pair of elements that have
the smallest absolute difference between them. If there are multiple pairs, find
the mall.
3. Objective:
4. Algorithm:
4. Collect all pairs with this minimum difference into the result vector.
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;
delete[] arr;
return 0;
}
6. Output:
7. Learning Outcomes:
▪ Learn how to use std::sort to arrange elements in ascending order.
Problem - 2
3. Objective:
4. Algorithm:
#include <iostream>
#include <unordered_map>
#include <set>
#include <memory>
void findMissing(const int arr[], int arrSize, const int brr[], int brrSize, int result[], int& resultSize) {
unordered_map<int, int> countArr, countBrr;
set<int> missingNumbers;
resultSize = 0;
for (int num : missingNumbers) result[resultSize++] = num;
}
int main() {
int n, m;
cin >> n;
auto arr = make_unique<int[]>(n);
for (int i = 0; i < n; ++i) cin >> arr[i];
cin >> m;
auto brr = make_unique<int[]>(m);
for (int i = 0; i < m; ++i) cin >> brr[i];
for (int i = 0; i < resultSize; ++i) cout << result[i] << " ";
cout << endl;
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
6. Output:
7. Learning Outcomes:
o Learn to use hash maps to efficiently count and compare element
frequencies in arrays.