Document 1
Document 1
Question #1:
#include <iostream>
int xor1 = 1;
xor1 ^= i;
xor2 ^= arr[i];
int main() {
int arr[] = {5, 4, 2, 1};
cout << "The missing number is: " << missingNumber << endl;
return 0;
Question #2:
#include <iostream>
#include <vector>
int index = 0;
int count = 1;
count++;
} else {
counts[index++] = count;
count = 1;
}
int main() {
countInstances(arr, n, counts);
cout << arr[i] << ": " << counts[i] << endl;
return 0;
Question #3:
#include <iostream>
a = a ^ b;
b = a ^ b;
a = a ^ b;
int main() {
cout << "num1 = " << num1 << ", num2 = " << num2 << endl;
swapNumbers(num1, num2);
cout << "num1 = " << num1 << ", num2 = " << num2 << endl;
return 0;
Question #4:
#include <iostream>
// So, we can use the bitwise AND operation with (num - 1).
int main() {
int num;
cout << "Enter a number: ";
if (isPowerOfTwo(num)) {
} else {
cout << num << " is not a power of 2." << endl;
return 0;
Question# 8:
Part a:
#include <iostream>
maxIndex = i;
return maxIndex;
int main() {
cout << "Roll number of student with highest GPA: " << maxIndex << endl;
return 0;
Part b:
1. 1. START
2. 2 A sorted array arr of floating-point numbers.
3. 3 An integer size indicating the size of the array arr.
4. 4 A floating-point target to find within the array.
PROCEDURE
1. 1 Initialize two pointers low and high at the beginning and end of the array,
respectively.
2. While low is less than or equal to high:
3. Determine the index of the middle element as mid = (low + high) / 2.
4. If arr[mid] equals target, return mid.
5. If arr[mid] is less than target, update low = mid + 1 to search in the right half.
6. If arr[mid] is greater than target, update high = mid - 1 to search in the left half.
7. If the target isn't found, return -1.
8.
3. OUTPUT
This algorithm efficiently discovers a target value within a sorted array by repeatedly dividing
the search space in half until the target is located or the search range is exhausted.
Part c:
#include <iostream>
if (arr[mid] == target) {
return mid;
low = mid + 1;
} else {
high = mid - 1;
int main() {
float cgpa[] = {3.7, 3.8, 3.9, 4.0}; // Sample sorted CGPA array
if (index != -1) {
cout << "Roll number of student with GPA 4.0: " << index << endl;
} else {
cout << "Student with GPA 4.0 not found." << endl;
return 0;
Part d:
GRAPH
Linear Search:
| *
| *
| *
| *
| *
| *
| *
| *
| *
| *