Spoiler for Simple (and slow) algorithm using Beats lookup table
edit: gack, formatting.
Spoiler for
![]() |
Welcome to BrainDen.com - Brain Teasers Forum. Like most online communities you must register to post in our community, but don't worry this is a simple free process. To be a part of BrainDen Forums you may create a new account or sign in if you already have an account. As a member you could start new topics, reply to others, subscribe to topics/forums to get automatic updates, get your own profile and make new friends. Of course, you can also enjoy our collection of amazing optical illusions and cool math games. If you like our site, you may support us by simply clicking Google "+1" or Facebook "Like" buttons at the top. If you have a website, we would appreciate a little link to BrainDen. Thanks and enjoy the Den :-) |
Posted 07 September 2012 - 02:52 AM
Spoiler for Simple (and slow) algorithm using Beats lookup tableCall the Beats table B. If Q beats P, we'll say "Q B P"
Copy Beats table, call it B2. If Q beats someone who beats P, we'll say "Q B2 P"
For Q in 1...N
....For P in 1...N (skip Q)
........if Q B P
............for each R in 1...N (skip Q and P)
................if P B R
....................set Q B2 R
....count = 0
....For P in 1...N (skip Q)
........if Q B P | Q B2 P, increment count
....if count = N-1, Stop, declaring Q to be a TK. (or print is a TK)
If you want all TKs, then don't stop, just print and keep going through all Q in 1...N
The time is order of n^3 in either case.
Analogous algorithm on Lost-to lists is also n^3 for one TK.
I'm not proud...
edit: gack, formatting.
Posted 07 September 2012 - 02:56 AM
Spoiler for hmmm...
I ran every combination for N = [4,5,6]. There were no cases where the king didn't score against another player either directly or indirectly. I'm pretty sure that will hold for N > 6...
Can I cheat and use all three methods?
Use method 2 and method 3 for a given player with method 1 until a win is found against method 3 player or no win found.w = M2[p].count If w = 0 then k = false --- exit If w = N - 1 then k = true --- exit l = N - w - 1 k = true For i = 1 to w f = false For j = 1 to l r = M3[p][j] If M1[ M2[p][i] , r ] = r Then f = true j = l End If Next If f = false Then k = false j = w End if Next If k = true then "Congrats on being a TOURNEY KING"
I think this would work... what would the lookup count be?
Posted 07 September 2012 - 03:01 AM
Spoiler for
this is basically the same algorithm i came up with, for finding a single king.
I would use method II, which allows you to see who any given competitor defeated
while king not found
{
pick a competitor at random.
delete everyone that this competitor defeated (this should be proportional to n operations)
if competitor is last one
{
he is king
}else{
delete him too
}
}
on average, deleting everyone a competitor is defeated reduces the number of competitors left by some proportion.
Thus the number of times this must be done is proportional to the log of n.
Each time this is done, there are something proportional to n operations due to deletions.
The time complexity is there for O(n*log(n)), as phil stated.
I don't think there is an algorithm with better time complexity for finding a single tournament king.
This algorithm does not find all tournament kings though.
Nice work phil!
Edited by mmiguel, 07 September 2012 - 03:03 AM.
0 members, 0 guests, 0 anonymous users
Community Forum Software by IP.Board 3.4.4
Licensed to: BrainDen
