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}; }