Show that the second smallest of
n elements can be found withn+⌈lgn⌉−2 comparisons in the worst case. (Hint: Also find the smallest element.)
We can compare the elements in a tournament fashion - we split them into pairs, compare each pair and then proceed to compare the winners in the same fashion. We need to keep track of each "match" the potential winners have participated in.
We select a winner in
Read full article from Exercise 9.1.1
No comments:
Post a Comment