배열의 bitonicity는 다음 구문을 사용하여 정의됩니다. -
요소를 기반으로 배열의 bitonicity를 찾는 것은 -
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]
예시
배열의 bitonicity를 찾기 위한 코드는 bitonicity라는 변수를 사용했습니다. 이 변수는 배열의 현재 요소와 이전 요소의 비교를 기반으로 변경됩니다. 위의 로직은 어레이의 bitonicity를 업데이트하고 최종 bitonicity는 어레이의 끝에서 찾을 수 있습니다.
#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;
} 출력
Bitonicity = 1