# Find bitonic point in given bitonic sequence

• Difficulty Level : Easy
• Last Updated : 13 Oct, 2021

You are given a bitonic sequence, the task is to find Bitonic Point in it. A Bitonic Sequence is a sequence of numbers which is first strictly increasing then after a point strictly decreasing.
A Bitonic Point is a point in bitonic sequence before which elements are strictly increasing and after which elements are strictly decreasing. A Bitonic point doesn’t exist if array is only decreasing or only increasing.
Examples :

```Input : arr[] = {6, 7, 8, 11, 9, 5, 2, 1}
Output: 11
All elements before 11 are smaller and all
elements after 11 are greater.

Input : arr[] = {-3, -2, 4, 6, 10, 8, 7, 1}
Output: 10```

Become a success story instead of just reading about them. Prepare for coding interviews at Amazon and other top product-based companies with our Amazon Test Series. Includes topic-wise practice questions on all important DSA topics along with 10 practice contests of 2 hours each. Designed by industry experts that will surely help you practice and sharpen your programming skills. Wait no more, start your preparation today!

A simple solution for this problem is to use linear search. Element arr[i] is bitonic point if both i-1’th and i+1’th both elements are less than i’th element. Time complexity for this approach is O(n).
An efficient solution for this problem is to use modified binary search

• If arr[mid-1] < arr[mid] and arr[mid] > arr[mid+1] then we are done with bitonic point.
• If arr[mid] < arr[mid+1] then search in right sub-array, else search in left sub-array.

## C++

 `// C++ program to find bitonic point in a bitonic array.``#include``using` `namespace` `std;`` ` `// Function to find bitonic point using binary search``int` `binarySearch(``int` `arr[], ``int` `left, ``int` `right)``{``    ``if` `(left <= right)``    ``{``        ``int` `mid = (left+right)/2;`` ` `        ``// base condition to check if arr[mid] is``        ``// bitonic point or not``        ``if` `(arr[mid-1]arr[mid+1])``            ``return` `mid;`` ` `        ``// We assume that sequence is bitonic. We go to``        ``// right subarray if middle point is part of``        ``// increasing subsequence. Else we go to left``        ``// subarray.``        ``if` `(arr[mid] < arr[mid+1])``            ``return` `binarySearch(arr, mid+1,right);``        ``else``            ``return` `binarySearch(arr, left, mid-1);``    ``}`` ` `    ``return` `-1;``}`` ` `// Driver program to run the case``int` `main()``{``    ``int` `arr[] = {6, 7, 8, 11, 9, 5, 2, 1};``    ``int` `n = ``sizeof``(arr)/``sizeof``(arr);``    ``int` `index = binarySearch(arr, 1, n-2);``    ``if` `(index != -1)``       ``cout << arr[index];``    ``return` `0;``}`

## Java

 `// Java program to find bitonic``// point in a bitonic array.`` ` `import` `java.io.*;`` ` `class` `GFG ``{``    ``// Function to find bitonic point ``    ``// using binary search``    ``static` `int` `binarySearch(``int` `arr[], ``int` `left,``                                       ``int` `right)``    ``{``        ``if` `(left <= right)``        ``{``            ``int` `mid = (left + right) / ``2``;``     ` `            ``// base condition to check if arr[mid] ``            ``// is bitonic point or not``            ``if` `(arr[mid - ``1``] < arr[mid] && ``                   ``arr[mid] > arr[mid + ``1``])``                   ``return` `mid;``     ` `            ``// We assume that sequence is bitonic. We go to``            ``// right subarray if middle point is part of``            ``// increasing subsequence. Else we go to left``            ``// subarray.``            ``if` `(arr[mid] < arr[mid + ``1``])``                ``return` `binarySearch(arr, mid + ``1``, right);``            ``else``                ``return` `binarySearch(arr, left, mid - ``1``);``        ``}``     ` `        ``return` `-``1``;``    ``}``     ` `    ``// Driver program ``    ``public` `static` `void` `main (String[] args) ``    ``{``        ``int` `arr[] = {``6``, ``7``, ``8``, ``11``, ``9``, ``5``, ``2``, ``1``};``        ``int` `n = arr.length;``        ``int` `index = binarySearch(arr, ``1``, n - ``2``);``        ``if` `(index != -``1``)``        ``System.out.println ( arr[index]);``             ` `    ``}``}`` ` `// This code is contributed by vt_m`

## Python3

 `# Python3 program to find bitonic ``# point in a bitonic array.`` ` `# Function to find bitonic point ``# using binary search``def` `binarySearch(arr, left, right):`` ` `    ``if` `(left <``=` `right):`` ` `        ``mid ``=` `(left ``+` `right) ``/``/` `2``;`` ` `        ``# base condition to check if ``        ``# arr[mid] is bitonic point ``        ``# or not``        ``if` `(arr[mid ``-` `1``] < arr[mid] ``and` `arr[mid] > arr[mid ``+` `1``]):``            ``return` `mid;`` ` `        ``# We assume that sequence ``        ``# is bitonic. We go to right ``        ``# subarray if middle point ``        ``# is part of increasing ``        ``# subsequence. Else we go ``        ``# to left subarray.``        ``if` `(arr[mid] < arr[mid ``+` `1``]):``            ``return` `binarySearch(arr, mid ``+` `1``,right);``        ``else``:``            ``return` `binarySearch(arr, left, mid ``-` `1``);`` ` `    ``return` `-``1``;`` ` `# Driver Code``arr ``=` `[``6``, ``7``, ``8``, ``11``, ``9``, ``5``, ``2``, ``1``];``n ``=` `len``(arr);``index ``=` `binarySearch(arr, ``1``, n``-``2``);``if` `(index !``=` `-``1``):``        ``print``(arr[index]);`` ` `# This code is contributed by mits`

## C#

 `// C# program to find bitonic``// point in a bitonic array.``using` `System;`` ` `class` `GFG ``{``    ``// Function to find bitonic point ``    ``// using binary search``    ``static` `int` `binarySearch(``int` `[]arr, ``int` `left,``                                      ``int` `right)``    ``{``        ``if` `(left <= right)``        ``{``            ``int` `mid = (left + right) / 2;``     ` `            ``// base condition to check if arr[mid] ``            ``// is bitonic point or not``            ``if` `(arr[mid - 1] < arr[mid] && ``                ``arr[mid] > arr[mid + 1])``                ``return` `mid;``     ` `            ``// We assume that sequence is bitonic. We go``            ``// to right subarray if middle point is part of``            ``// increasing subsequence. Else we go to left subarray.``            ``if` `(arr[mid] < arr[mid + 1])``                ``return` `binarySearch(arr, mid + 1, right);``            ``else``                ``return` `binarySearch(arr, left, mid - 1);``        ``}``     ` `        ``return` `-1;``    ``}``     ` `    ``// Driver program ``    ``public` `static` `void` `Main () ``    ``{``        ``int` `[]arr = {6, 7, 8, 11, 9, 5, 2, 1};``        ``int` `n = arr.Length;``        ``int` `index = binarySearch(arr, 1, n - 2);``        ``if` `(index != -1)``        ``Console.Write ( arr[index]);``    ``}``}`` ` `// This code is contributed by nitin mittal`

## PHP

 ` ``\$arr``[``\$mid` `+ 1])``            ``return` `\$mid``;`` ` `        ``// We assume that sequence ``        ``// is bitonic. We go to right ``        ``// subarray if middle point ``        ``// is part of increasing ``        ``// subsequence. Else we go ``        ``// to left subarray.``        ``if` `(``\$arr``[``\$mid``] < ``\$arr``[``\$mid` `+ 1])``            ``return` `binarySearch(``\$arr``, ``\$mid` `+ 1,``\$right``);``        ``else``            ``return` `binarySearch(``\$arr``, ``\$left``, ``\$mid` `- 1);``    ``}`` ` `    ``return` `-1;``}`` ` `    ``// Driver Code``    ``\$arr` `= ``array``(6, 7, 8, 11, 9, 5, 2, 1);``    ``\$n` `= sizeof(``\$arr``);``    ``\$index` `= binarySearch(``\$arr``, 1, ``\$n``-2);``    ``if` `(``\$index` `!= -1)``        ``echo` `\$arr``[``\$index``];`` ` `// This code is contributed by nitin mittal``?>`

## Javascript

 ``

Output:

`11`

Time complexity : O(Log n)
This article is contributed by Shashank Mishra ( Gullu ). If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.