IDSA Assignment 5
IDSA Assignment 5
Department of
Artificial Intelligence and Data
Science
Student Name: Aditya
Sirsat
#include <algorithm>
bool linearSearch(int arr[], int n, int key) { // Function to perform linear search
if (arr[i] == key) {
return true;
}}
return false;
bool binarySearch(int arr[], int n, int key) { // Function to perform binary search (assumes array is sorted)
if (arr[mid] == key) {
return true;}
else {
right = mid - 1; }
} return false;
}}}}
int main() {
int rollNumbers[maxSize];
int n;
cin >> n;
int key;
cout << "Roll number " << key << " found using linear search.\n";
} else {
cout << "Roll number " << key << " not found using linear search.\n";
if (binarySearch(rollNumbers, n, key)) {
cout << "Roll number " << key << " found using binary search.\n";
} else {
cout << "Roll number " << key << " not found using binary search.\n";
return 0;
}
Output: