recursion - Java Recursive efficiency analysis -
i need creating efficiency analysis method 1 below. need come with:
- factors influence runtime
- what being counted(comparisons, operations)?
- best/worst case
- big o notation
here's have far:
- array length
- math operations
- worst case , best case same, method run whole array, regardless of contents
- no idea
let me know think.
thanks
double sum(double[] array) { return recursivesum(array, 0, array.length - 1); } double recursivesum(double[] array, int lo, int hi) { if (lo == hi) { return array[lo]; } int mid = (lo + hi) / 2; double leftsum = recursivesum(array, lo, mid); double rightsum = recursivesum(array, mid+1, hi); return leftsum + rightsum; }
my answer:
- array length
- no idea
- worst case , best case same, method run whole array, regardless of contents
- o(nlogn) (f(n)=2*f(n/2) -> f(n)=o(nlogn))
Comments
Post a Comment