search - Increasing algorithm efficiency using divide and conquer paradigm -
i want find minimum , maximum integer within array. relatively inefficient method consider first integer max\min. compare other integers , if greater/smaller integer compared current minimum or maximum integer replaced. takes place until end of array. have worked out complexity (based on worst case) n -1 (n size of array). question how use divide , conquer paradigm make more efficient? have tried dividing array 2 parts , doing same algorithm above both divisions although makes less efficient? calculations complexity becomes n + 1.
i consider you're using 1 thread
if array not sorted, complexity o(n)
. however, in opinion, should check need max number? or second max well, , third max ..
if that's case, you'd better build max heap (min heap counterpart case), takes o(nlogn)
time, , check peek of heap.
Comments
Post a Comment