
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Program to calculate Bitonicity of an Array
The bitonicity of an array is defined using the following syntax −
To find bitonicity of an array based on its elements is −
Bitonicity = 0 , initially arr[0] i from 0 to n Bitonicity = Bitonicity+1 ; if arr[i] > arr[i-1] Bitonicity = Bitonicity-1 ; if arr[i] < arr[i-1] Bitonicity = Bitonicity ; if arr[i] = arr[i-1]
Example
The code for finding the bitonicity of an array we have used a variable called bitonicity, that changes its based on the comparison of the current and previous elements of the array. The above logic updates the bitonicity of the array and final bitonicity can be found at the end of the array.
#include <iostream> using namespace std; int main() { int arr[] = { 1, 2, 4, 5, 4, 3 }; int n = sizeof(arr) / sizeof(arr[0]); int Bitonicity = 0; for (int i = 1; i < n; i++) { if (arr[i] > arr[i - 1]) Bitonicity++; else if (arr[i] < arr[i - 1]) Bitonicity--; } cout << "Bitonicity = " << Bitonicity; return 0; }
Output
Bitonicity = 1
- Related Articles
- C++ Program to calculate Bitonicity of an Array
- Java Program to calculate the time of sorting an array
- PHP program to calculate the total time given an array of times
- Program to calculate area of Circumcircle of an Equilateral Triangle
- Swift Program to Calculate the sum of Elements in a Given Array
- Program to calculate area of Circumcircle of an Equilateral Triangle in C++
- Program to print Sum Triangle of an array.
- Golang Program to Rotate Elements of an Array
- Program to calculate the area of an Circle inscribed in a Square
- Write a Golang program to calculate the sum of elements in a given array
- Program to calculate area of Enneagon
- Program to calculate Area Of Octagon
- Java program to reverse an array
- C# program to reverse an array
- Golang program to print an array?

Advertisements