Code to find inflation point in bitonic series (javascript)


#1

A bitonic series is series in which numbers increase and after one number they start decreasing,we have to find the number at which this happens.

var c = [10,12,14,18,10,4,5];

//1 2 3 20 30 40 19

//10 20 18 15 4 3 2

function maximaPoint(a)
{

var length = a.length;
var low = 0;
var high    = length -1;



while(low<=high)
{
	//console.log("low " + low + "high " + high + "mid " + mid);


	mid = low + Math.floor((high - low)/2);

	if(low == high)
	{
		return a[mid];
	}

	if(a[mid] - a[mid -1] >0 && a[mid+1] - a[mid] < 0)
	{
		return a[mid];
	}

	if(a[mid] - a[mid -1]> 0)
	{
		low = mid + 1;

	}

	else
	{
		high = mid - 1;
		
	}



}

}

console.log(minRotatedĀ©);


#2

what if it asks for the index to find the index ?


#3

you keep track of index through one more variable