home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.math
- Path: sparky!uunet!seas.gwu.edu!chihy
- From: chihy@seas.gwu.edu (Chih-Hsun Yao)
- Subject: comparison problem
- Message-ID: <1992Nov18.161028.11906@seas.gwu.edu>
- Sender: news@seas.gwu.edu
- Organization: George Washington University
- Distribution: usa
- Date: Wed, 18 Nov 1992 16:10:28 GMT
- Lines: 29
-
- Hi, everyone:
- I got problem with following question:
-
- Describe an algorithm that finds the largest and second largest integer in a
- set of (2^m) integers using at most m+(2^m)-2 comparisons.
- (Hint: Consider binary tree tournament)
-
- My problem is following: if I use the way of binary tree tournament,
- there is no doubt I can find the largest number at (2^m)-1 comparisons, but
- how can I find the second largest number at (m-1) comparisons?
- My friend give me an example: the set {9,2,4,5,6,3,1,8}
- 9 compares to 2, 9 stands out. 4 compares to 5, 5 stands out. 6 compares to
- 3, 6 stands out. 1 compares to 8, 8 stands out. Then 9 compares to 5, 9
- stands out. 6 compares to 8, 8 stands out. The final step, 9 compares to 8,
- 9 stands out. We get the largest number, and the total comparisons are
- 7 times = (2^m-1). To get the second largest number, we just use 8 to
- compare to 6 and 5, just 2 comparisons = (m-1).
- I find it only works in this example. If I put the 8 at the second
- position such as {9,8,2,4,5,6,3,1}, I can still get the largest number at
- (2^m)-1 comparisons, but I cannot get the second largest number at m-1
- comparisons. As you see, I will lose the second largest number 8 at first
- comparison. In that case, I have to recompare form the beginning, and the
- result will not be m+(2^m)-2 comparisons.
- Any idea? Thanks in advance.
-
-
- Chih-Hsun Yao
-
-
-