This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Assignment #3, CS/531 Due Date: Thur. Oct. 24, 2011 UNSUPPORTED SOLUTIONS RECEIVE NO CREDIT. Total points: 47 1. (2+6 = 8 pts) A local tennis club is going to have a tournament to decide the 1st and the 2nd place player among n players. The tournament is by elimination. Namely, when two players play a match, the loser will be dropped from the competition. (To make it simpler, we assume n is a power of 2, and no ties in any match). It is easy to see that n 1 matches are necessary and sufficient to decide the 1st place player. The harder question is how many additional matches are needed to decide the 2nd place player. (a) Describe how to decide the first place player using n 1 matches. (b) Describe how to decide the second place player using additional O (log n ) matches. Another description of the problem: We are given an unsorted array A [1 ..n ] of numbers. (a) Find the largest element in A using n 1 comparisons. (b) Then, find the second largest element in A using additional O (log n ) comparisons. Answer: (a) To decide the first player in n 1 matches we need to decide how to match players. During the first round, we divide the players into n/ 2 pairs and n/ 2 matches are played. The winners advance to the next round, and the losers are eliminated. During the second round, n/ 4 matches are played between n/ 2 players, and the winners advance to the next round, and so on. So the number of matches in each round will be half of the number in the previous round. During the k th round, where k = log 2 n , we reach the final round (with only 1 match). Thus, the total number of matches (assuming n is a power of 2) is: n 2 + n 4 + ... + 2 + 1 = n 1. (b) Knowing the 1st player, we will focus on possible 2nd players. The second player does not have to be the one who played final match but lost. The actual 2nd player can (only) be the one who played with and lost to the 1st player during any round. Thus, we need to find the 2nd player by matching players who played with the 1st player and lost. Since there are k = log 2 n rounds, we have log 2 n such players. We need to find the best among those players. Since we showed that the best of the t players can be found in t 1 matches, the best of log 2 n players can be found in log 2 n 1 additional matches. A B C D E F G H B C E H C H C Figure 1: Game Tree. For example, consider the game tree shown in Fig 1 of n = 8 players. Each internal node of the tree represent a match between two players, and is labeled by the winner of the match. In this example, after log 2 8 = 3 rounds, the player C is the 1st player. The possible 2nd players 1 are: D,B,H (who lost only the 1st player). Thus an additional 3-1=2 matches are played between D,B,H to decide the 2nd place player. a50 2. (7 pts) LCS problem re-visited....
View Full Document
- Fall '11