Home > Back-end >  2020-11-13: write code: local minimum problem. A disorderly array, the adjacent elements. How to eva
2020-11-13: write code: local minimum problem. A disorderly array, the adjacent elements. How to eva

Time:11-14

2020-11-13: write code: local minimum problem, disorderly array, the adjacent elements, how to evaluate the minimum? # # f greatly architects a daily topic

CodePudding user response:

Dichotomy implementation
Int getLocalMinValue (int [] a, int the begin, int the end) {
If (begin==end) return a (begin);
Int mid=(begin + end)/2;
If (a/min & lt; A [mid + 1]) {
MinValueOfLeft=getLocalMinValue (a, begin, mid);
}
Else if (a/min & gt; A [mid + 1]) {
MinValueOfLeft=getLocalMinValue (a, mid + 1, end);
}
Return min {minValueOfLeft minValueOfRigth};
}

CodePudding user response:

reference 1st floor KeepSayingNo response:
dichotomy implementation
Int getLocalMinValue (int [] a, int the begin, int the end) {
If (begin==end) return a (begin);
Int mid=(begin + end)/2;
If (a/min & lt; A [mid + 1]) {
MinValueOfLeft=getLocalMinValue (a, begin, mid);
}
Else if (a/min & gt; A [mid + 1]) {
MinValueOfLeft=getLocalMinValue (a, mid + 1, end);
}
Return min {minValueOfLeft minValueOfRigth};
}

Feeling a little problem

CodePudding user response:

A minimum value, declare an int variable minValue, initial value assignment for MAX_INTEGER,
Iterate through group and compare each element and minValue, less than the minValue, update the minValue values for the current element,
Traverse the minValue is minimum,

If is minimum, there may be multiple, as long as an element of two adjacent elements is greater than he, and should be minimum.
  • Related