🌹Attapur⬅️ Vip Call Girls Hyderabad 📱9352852248 Book Well Trand Call Girls In...
Lab 6 (1)
1. Student: Ali Zangar
Group: SE – 1905
Topic: Exponential Search
#include <bits/stdc++.h>
using namespace std;
int binarySearch(int arr[], int, int, int);
int exponentialSearch(int arr[], int n, int x)
{
if (arr[0] == x)
return 0;
int i = 1;
while (i < n && arr[i] <= x)
i = i*2;
return binarySearch(arr, i/2,
min(i, n-1), x);
}
int binarySearch(int arr[], int l, int r, int x)
{
if (r >= l)
{
int mid = l + (r - l)/2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarySearch(arr, l, mid-1, x);
return binarySearch(arr, mid+1, r, x);
}
return -1;
}
// Driver code
int main(void)
{
int z;
cin >> z;
int arr[z];
for(int i = 0; i < z; i++)
2. cin >> arr[i];
int n = sizeof(arr)/ sizeof(arr[0]);
int x;
cout << "Search: n";
cin >> x;
int result = exponentialSearch(arr, n, x);
(result == -1)? cout <<"Element is not present in array"
: cout <<"Element is present at index " <<
result;
return 0;
}
Test plan:
1) Test objectives:
1. Check that whether function is working as expected without any errors and bugs
2. Check that user’s inputs are stored properly and as expected
All path:
Path1: 1, 2, 3, 11;
Path2: 1, 2, 4, 6, 7, 8, 11;
Path3: 1, 2, 4, 6, 7, 9, 10, 11;
Here are the 3 paths that need to be tested to get the output.
Test cases
3. Procedure Data Expected result
Enter the size of array 0 Invalid input
Enter the size of array 1 Invalid input
Enter the size of array 2 The two elements whose sum
is minimum are x and y
Enter the size of array -5 Invalid input
Enter the elements of array a Please, enter only integers