- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find bitonic point in given bitonic sequence in Python
Suppose we have a bitonic sequence, we have to find the Bitonic Point in it. As we know a Bitonic Sequence is a sequence of numbers which is first strictly increasing then after a certain point it is strictly decreasing. This point is bitonic point. For only increasing or only decreasing sequences, bitonic points are not available.
So, if the input is like [7, 8, 9, 12, 10, 6, 3, 2], then the output will be 12
To solve this, we will follow these steps −
- define a function binary_search(array, l, r)
- if l <= r, then −
- m := (l + r) / /2
- if array[m - 1] < array[m] and array[m] > array[m + 1], then −
- return m
- if array[m] < array[m + 1], then −
- return binary_search(array, m + 1, r)
- Otherwise
- return binary_search(array, l, m - 1)
- return -1
Example
Let us see the following implementation to get better understanding −
def binary_search(array, l, r): if (l <= r): m = (l + r) // 2; if (array[m - 1] < array[m] and array[m] > array[m + 1]): return m; if (array[m] < array[m + 1]): return binary_search(array, m + 1,r); else: return binary_search(array, l, m - 1); return -1; array = [7, 8, 9, 12, 10, 6, 3, 2] n = len(array); index = binary_search(array, 1, n-2); if (index != -1): print(array[index]);
Input
[7, 8, 9, 12, 10, 6, 3, 2]
Output
12
- Related Articles
- Bitonic Sort in C++
- Find longest bitonic sequence such that increasing and decreasing parts are from two different arrays in Python
- Queries on insertion of an element in a Bitonic Sequence in C++
- Longest Bitonic Subsequence
- Maximum sum bitonic subarray in C++
- Find longest bitonic sequence such that increasing and decreasing parts are from two different arrays in C++
- Java Program for Bitonic Sort
- Program to find length of longest bitonic subsequence in C++
- JavaScript Program to Find the Longest Bitonic Subsequence | DP-15
- Find element position in given monotonic sequence in Python
- Program to find nth sequence after following the given string sequence rules in Python
- Program to find last digit of the given sequence for given n in Python
- Find element position in given monotonic Sequence in C++
- Program to find sum of given sequence in C++
- Find maximum length Snake sequence in Python

Advertisements