issingUtil(int arr[], int low, int high, int diff) { if (high <= low) return INT_MAX; int mid = low + (high - low)/2; if (arr[mid+1] - arr[mid]
#include <stdio.h>
#include <limits.h>
int findMissingUtil(int arr[], int low, int high, int diff)
{
if (high <= low)
return INT_MAX;
int mid = low + (high - low)/2;
if (arr[mid+1] - arr[mid] != diff)
return (arr[mid] + diff);
if (mid > 0 && arr[mid] - arr[mid-1] != diff)
return (arr[mid-1] + diff);
if (arr[mid] == arr[0] + mid*diff)
return findMissingUtil(arr, mid+1, high, diff);
return findMissingUtil(arr, low, mid-1, diff);
}
int findMissing(int arr[], int n)
{
int diff = (arr[n-1] - arr[0])/n;
return findMissingUtil(arr, 0, n-1,diff);
}
int main()
{
int arr[] = {120001, 120013, 120025, 120037, 120049, 120061,120085,120097,120109,120121};
int n = sizeof(arr)/sizeof(arr[0]);
printf("The missing element is %d", findMissing(arr, n));
return 0;
}
______________________________________________________________________________
Convert the code above into Pseudocode
Step by step
Solved in 2 steps with 1 images