CandidateKeys
SRM 386 · 2008-01-05 · by eleusive
Problem Statement
Return a
The input is described by a
Notes
- A proper subset of a superkey is a set of attributes that is formed by removing one or more attributes from the superkey.
Constraints
- table will contain between 2 and 50 elements, inclusive.
- Each element of table will contain between 1 and 10 characters, inclusive.
- Each element of table will contain the same number of characters.
- Each character in table will be an uppercase letter ('A'-'Z').
{
"ABC",
"ABC",
"ABC"
}
Returns: { }
Since all entries are the same, there is no set of attributes that can differentiate between them. Therefore, this table has no candidate superkeys.
{
"ABC",
"ABD",
"ABE"
}
Returns: {1, 1 }
There are four superkeys here: {column 0, column 1, column 2} {column 0, column 2} {column 1, column 2} {column 2} Note that the fourth superkey is a subset of all the other superkeys, so it is the only candidate superkey.
{
"ABC",
"ACD",
"BBE"
}
Returns: {1, 2 }
{"BDC", "AFC", "BFG", "GAD", "DBA", "BCB", "ACC"}
Returns: {2, 2 }
{"AABAA", "ABABA", "ABBAA", "BBBAA", "BBBAB", "ABBBB", "BBBAA", "AAABB"}
Returns: { }
{
"AAC",
"ABD",
"BAC",
"BBD"
}
Returns: {2, 2 }
bad greedy: min
{
"ACB",
"ACA",
"BDB",
"BDA"
}
Returns: {2, 2 }
bad greedy: min
{
"ACEB",
"ACEA",
"BDFB",
"BDFA"
}
Returns: {2, 2 }
bad greedy: min
{
"ABA",
"BAA",
"CAB",
"ACA",
"DBC",
"CAC"
}
Returns: {2, 2 }
bad greedy: min
{
"AA",
"AB",
"AC",
"BD"
}
Returns: {1, 1 }
bad greedy: max
Submissions are judged against all 151 archived test cases, of which 10 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CandidateKeys with a public method vector<int> getKeys(vector<string> table) · 151 test cases · 2 s / 256 MB per case