search - Recursive algorithm to find the smallest element -


i want write recursive algorithm find smallest element. draw binary tree in leaf represents elements , internal nodes smallest elements after comparison.

input algo :

5 3 1 9 8 7 6 10

binary tree :

enter image description here

output : 1

i need find algorithm somehow incorporates binary tree. first compare pair of elements , reduced problem n/2 n/4 .. , when n become 1 answer.

use divide , conquer.

let m(i, j) denote minimum element of "subarray" [i...j]. m(i, j) = min(m(i, k), m(k + 1, j)), if i < j (i leave figure out suitable k).

additionally, need take care of case i = j.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -