The minimum function dependency set (minimum coverage) for relation normalization

Source: Internet
Author: User
Tags terminates

Minimum function Dependency Set
I. Equivalence and coverage
Definition: The two dependency set F and G on the relational pattern r<u,f>, if f+=g+, is called F and g are equivalent, remember to do f≡g. If f≡g, then G is an overlay of f and vice versa. Two equivalent sets of function dependencies are identical in their expressive abilities.
  
Second, minimum function dependency set
Definition: If the function dependency set F satisfies the following conditions, it is said that f is the minimum function dependency set or minimum overwrite.
The right part of any of the functions in ①f has only one property;
There is no such function dependent x→a in ②f, which makes F and f-{x→a} equivalent;
There is no such function in ③f that the x→a,x has a true subset of Z so that f-{x→a}∪{z→a} is equivalent to F.
Algorithm: Calculates the minimum function dependency set.
Enter a function dependency set
An equivalent minimum function dependency set g for Output F
Step: ① Use the law of decomposition, so that any function in F is dependent on the right side of only one property;
② Remove redundant function dependencies: Starting from the first function depends on x→y to remove it from F, and then in the remaining function dependencies to find the closure of X x+, see if x+ contains Y, if, then remove x→y; Until the redundant function dependencies are not found;
The ③ removes extraneous attributes that depend on the left part. One by one checks that the function relies on the dependency of the left non-individual property. For example Xy→a, if Y is redundant, is it equivalent to X→a instead of xy→a? If a
(X) +, Y is an extra attribute and can be removed.
For example: Known relational pattern R<u,f>,u={a,b,c,d,e,g},f={ab→c,d→eg,c→a,be→c,bc→d,cg→bd,acd→b,ce→ag}, the minimum function dependency set for F is obtained.
  
Solution 1: Use the algorithm to solve, make it meet three conditions
  
① uses decomposition rules to turn all function dependencies into a function dependency of a single property on the right, with F: f={ab→c,d→e,d→g,c→a,be→c,bc→d,cg→b,cg→d,acd→b,ce→a,ce→g}

② Remove redundant function dependencies in F
  
A Set Ab→c as a redundant function dependency, then remove Ab→c, get: F1={d→e,d→g,c→a,be→c,bc→d,cg→b,cg→d,acd→b,ce→a,ce→g}
Calculation (AB) f1+: Set X (0) =ab
Calculation x (1): Scan F1 for function dependencies and find the function dependency on the left side of the AB or AB subset, because such a function cannot be found. So there are X (1) =x (0) =ab, the algorithm terminates.
(AB) f1+= AB does not contain C, so ab→c is not a redundant function dependency and cannot be removed from the F1.
  
B Set Cg→b as a redundant function dependency, then remove Cg→b, get: F2={ab→c,d→e,d→g,c→a,be→c,bc→d,cg→d,acd→b,ce→a,ce→g}
Calculation (CG) f2+: Set X (0) =CG
Calculation x (1): Scan the F2 in the various function dependencies, find the left part of the CG or CG subset of the function dependency, get a c→a function dependency. So there are X (1) =x (0) ∪A=CGA=ACG.
Calculation x (2): Scan the F2 in the various function dependencies, find the left part of the ACG or ACG subset of the function dependency, get a cg→d function dependency. So there are X (2) =x (1) ∪d=acdg.
Compute x (3): Scans the F2 for each function dependency, finds a function dependency on the left side of the ACDG or ACDG subset, and obtains two acd→b and d→e function dependencies. So there are X (3) =x (2) ∪be=abcdeg, because X (3) =u, the algorithm terminates.
(CG) F2+=abcdeg contains B, so cg→b is a redundant function dependency, removed from the F2.
  
C Set Cg→d as a redundant function dependency, then remove Cg→d, get: F3={ab→c,d→e,d→g,c→a,be→c,bc→d,acd→b,ce→a,ce→g}
Calculation (CG) f3+: Set X (0) =CG
Calculation x (1): Scan the F3 in the various function dependencies, find the left part of the CG or CG subset of the function dependency, get a c→a function dependency. So there are X (1) =x (0) ∪A=CGA=ACG.
Calculation x (2): Scan the individual function dependencies in the F3 to find a function dependency on the left part of the ACG or ACG subset, because such a function dependency cannot be found. So there are X (2) =x (1), the algorithm terminates. (CG) F3+=ACG.
(CG) F3+=ACG does not contain D, so cg→d is not a redundant function dependency and cannot be removed from F3.
  
D Set Ce→a as a redundant function dependency, then remove Ce→a, get: F4={ab→c,d→e,d→g,c→a,be→c,bc→d,cg→d,acd→b,ce→g}
Calculation (CG) f4+: Set X (0) =ce
Calculate x (1): Scan F4 for each function dependency, find the left part of the CE or CE subset of the function dependency, get a c→a function dependency. So there are X (1) =x (0) ∪a=cea=ace.
Calculation x (2): Scans the F4 for each function dependency, finds a function dependency on the left side of the Ace or ace subset, and obtains a ce→g function dependency. So there are X (2) =x (1) ∪g=aceg.
Compute x (3): Scans the F4 for each function dependency, finds a function dependency on the left side of the ACEG or ACEG subset, and obtains a cg→d function dependency. So there are X (3) =x (2) ∪d=acdeg.
Compute x (4): Scans the F4 for each function dependency, finds a function dependency on the left side of the acdeg or acdeg subset, and obtains a acd→b function dependency. So there are X (4) =x (3) ∪b=abcdeg. The algorithm terminates because X (4) =u.
(CE) F4+=abcdeg contains a, so ce→a is a redundant function dependency, removed from the F4.
  
③ remove each function in the F4 depends on the left redundant property (only check the left is not a single property of the function dependencies) because C→a, the function depends on the Acd→b property A is redundant, remove A cd→b.
So the minimum function dependency set is: F={ab→c,d→e,d→g,c→a,be→c,bc→d,cg→d,cd→b,ce→g}

  
Solution 2: Solving the inference rule using Armstrong axiom system
① assumes that cg→b is a redundant function dependency, then, after removing it from F, it can be exported according to the inference rules of the Armstrong axiom system.
Because Cg→d (known)
So CGA→AD,CGA→ACD (augmented law)
Because Acd→b (known)
So Cga→b (Transfer law)
Because C→a (known)
So Cg→b (pseudo-transitive law)
Therefore, the cg→b is redundant.
② the same: Ce→a is superfluous.
③ again because of c→a, the function depends on the acd→b attribute A is superfluous, remove A to cd→b.

So the minimum function dependency set is: F={ab→c,d→e,d→g,c→a,be→c,bc→d,cg→d,cd→b,ce→g}

Database programming Experiment//Find minimum overlay fm//Input: U,u function Dependency set f//output: function dependency set F minimum Coverage FM #include <iostream> #include <string>using Namespace Std;struct functiondependence//function depends on {string x;//determinant factor string Y;}; void Init (functiondependence fd[],int N) {//function dependency initialization int i;string x,y;cout<< "Please enter the function dependency in F (determining factor in left, determined factor at right)" < <endl; Input function Dependency set F for (i=0;i<n;i++) {cin>>x>>y; Fd[i]. X=x; Fd[i]. Y=y;} cout<< "function Dependency collection"; cout<< "f={"; for (i=0;i<n;i++) {//displays a known function dependency set F Cout<<fd[i]. x<< "," <<fd[i ". Y;if (i<n-1) cout<< ",";} cout<< "}" <<endl; }bool Match (string a,string b)//Determines whether two strings match {bool Flag=false;int length1=a.length (); int length2=b.length (); int count=0 if (length1==length2) {int i=0,j=0;//string each bit is equal for (i=0;i<length1;i++) {if (a[i]==b[i]) count++;} if (count==length1) flag=true;} return flag;} String Cutandsort (string mm)//removes the resulting closure from the repeating element and sorts {int size=mm.length (); string ss= "n"; int kk=0,ii=0; The int a[200]={0};//is used to record the number of occurrences of each proposition for (kk=0;kk<size;kk++) {A[(int) mm[kk]]++;//cast type, number of times to store each factor}for (ii=0;ii<200;ii++) {if (a[ii]>=1) ss+= (char) II;} return SS;} BOOL IsIn (String f,string zz)//can determine whether all the factors in F are in X, but this may result in duplicate {bool Flag1=false;int len1=f.length (); int len2= Zz.length (); int k=0,t=0,count1=0;for (k=0;k<len1;k++) {for (t=0;t<len2;t++) {if (F[k]==zz[t]) {//flag1=true; break;count1++;}}} if (count1==len1) {flag1=true;} else Flag1=false;return Flag1;} String Fd_fun (functiondependence fd[],int n,string xx) {int i;//asks X about F's closure for (i=0;i<n;i++) {if (Match (Fd[i]). X,XX) ==true) {Xx+=fd[i]. Y;} else if (IsIn (fd[i). X,XX) {==true) {if (IsIn (Fd[i]). Y,XX) ==false)//Avoid adding duplicate elements xx+=fd[i]. Y;} }cutandsort (XX); return Cutandsort (XX);} Remove a dependency from the function dependency set F left->rightvoid Cut (functiondependence fd[],int n,string left,string right,functiondependence Dyna[]) {int i=0,j=0,count=0;for (i=0;i<n;i++) {if (Fd[i]. X==left) && (Fd[i]. Y==right)) {}else{dyna[count]. X=fd[i]. X;dyna[count]. Y=fd[i]. y;count++;}} cout<< "\ n Remove" <<left<< "<<right";cout<< "After the function dependency set F:" <<endl;cout<< "f={"; for (j=0;j<count;j++) {cout<<dyna[j]. x<< "," <<dyna[j ". Y;if (j<count-1) cout<< ",";} cout<< "}" &LT;&LT;ENDL;} BOOL RA (functiondependence a,functiondependence B)//Determine redundant attribute {if ((IsIn (a.x,b.x) ==true) && (A.Y==B.Y)) {return true;} else return false;} void Cutsamefd (functiondependence fd[],int N)//Remove duplicate function dependencies {functiondependence dyna1[n+20]; Functiondependence DYNA2[N+20]; Functiondependence DYNA3[N+20]; Functiondependence dyna4[n+20];int i=0,j=0,k=0,count=0,count1=0,count2=0;for (i=0;i<n;i++) {for (j=0;j<count; J + +) {if (Fd[i]. X==FD[J]. X) && (Fd[i]. Y==FD[J]. Y)//There is a function dependent repetition {break;//skips the current function dependency}}if (J==count) {Dyna1[count]. X=fd[i]. X;dyna1[count]. Y=fd[i]. y;count++; }}cout<< "Remove the duplicate function dependency set f=" << "{"; for (k=0;k<count;k++) {//Remove the duplicate function dependency set cout<< dyna1[k]. x<< "," <<dyna1[k ". Y;if (k<count-1) cout<< ",";} cout<< "}" <<endl;for (k=0;k<count;k++) {//from the first function depends on x→y start it from FCut (Dyna1,count,dyna1[k]. X,DYNA1[K]. Y,DYNA2)///And then in the remaining function dependencies, find the closure x+ of X to see if x+ contains Ycout<<dyna1[k]. x<< "Closure on F:"; Cout<<fd_fun (Dyna2,count,dyna1[k). x);//The Closure x+if (IsIn (Dyna1[k]) for x in the remaining function dependencies. Y,fd_fun (Dyna2,count,dyna1[k]. X) ==true)//{cout<< "\ n" <<dyna1[k]//in the closure. x<< "," <<dyna1[k ". y<< "redundant" &LT;&LT;ENDL;} else {cout<< "\ n" <<dyna1[k]. x<< "," <<dyna1[k ". y<< "No redundancy" <<endl;dyna3[count1]. X=DYNA1[K]. X;DYNA3[COUNT1]. Y=DYNA1[K]. y;count1++;}} cout<< "redundant function dependent function dependency set f={"; for (i=0;i<count1;i++) {cout<<dyna3[i]. x<< "," <<dyna3[i ". Y;if (i<count1-1) cout<< ",";} cout<< "}" <<endl;//remove redundant attribute for (i=0;i<count1;i++) {for (j=0;j<count1;j++) {if (RA (Dyna3[i],dyna3[j]) ==true) {break;}} Dyna4[count2]. X=dyna3[i]. X;dyna4[count2]. Y=dyna3[i]. y;count2++;} To obtain the minimum coverage cout<<endl; cout<< "Minimum overlay fm=" << "{"; for (k=0;k<count2;k++) {cout<<dyna4[k]. x<< "," <<dyna4[k ". Y;if (K<count2-1) cout<< ",";} cout<< "}" &LT;&LT;ENDL;} void Singler (functiondependence fd[],int N)//causes F to decompose the right part of all function dependencies into a single attribute {int lengthr=0,i=0,j=0,k=0;static int d=n;int count=0; Functiondependence dynamicfd[d+20];//creates a new space to store all the function dependencies cout<< "right property single after the function dependency set F is:" <<endl;cout<< "f ={"; for (i=0;i<n;i++) {lengthr= (Fd[i]. Y). Size (); for (j=0;j<lengthr;j++)//breaks the right part into a single attribute, added to the property collection after {Dynamicfd[count]. X=fd[i]. X;dynamicfd[count]. Y= (Fd[i]. Y) [j];count++;}} for (k=0;k<count;k++) {cout<<dynamicfd[k]. x<< "," <<dynamicfd[k ". Y;if (k<count-1) cout<< ",";} cout<< "}" <<endl; D=count; CUTSAMEFD (dynamicfd,d);} void Fmin (functiondependence fd[],int N)//minimum coverage {Init (fd,n); Singler (fd,n);} int main () {int n;cout<< "Please enter the number of groups that the function depends on in F:"; cin>>n; Functiondependence Fd[n];  Fmin (fd,n);//singler (fd,n);//cutsamefd (fd,n);//fd (fd,n); return 0;}

Very regret not to use chain structure, resulting in increased deletion node is very troublesome, right when as a concept to understand the help it.



The minimum function dependency set (minimum coverage) for relation normalization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.