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

Source: Internet
Author: User
Tags closure int size 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, to Xy→a if Y is redundant, the substitution of x→a for xy→a is equivalent. 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}


//for minimum coverage FM//Input: function dependency set f//output on the complete set of properties U,U: Minimum coverage FM 
for function dependency sets F
#include <iostream> #include <string> using namespace std;	
The struct functiondependence//function relies on the {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 (the determinants are left, the determinants are on the right)" <<endl;
		Input function Dependency set F for (i=0;i<n;i++) {cin>>x>>y; Fd[i].
		Y=y; Fd[i].	
	X=x; 
	} cout<< "function dependency collection";
	cout<< "f={"; for (i=0;i<n;i++) {//displays known function dependency set F Cout<<fd[i]. x<< "," <<fd[i ".
		Y	
	if (i<n-1) cout<< ","; 
} cout<< "}" <<endl;
	} 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, the number of times to store each factor} for (ii=0;ii<
	200;ii++) {if (a[ii]>=1) ss+= (char) II;
} return SS;
	the 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 X_fn (functiondependence fd[],int n,string &xx) {string yy=xx; for (int i=0;i<n;i++) {if (IsIn (Fd[i]). X,YY) ==true) {Xx+=fd[i].  
        Y  
    }} yy=cutandsort (yy);    
    Xx=cutandsort (XX);   
if (xx!=yy) {X_FN (FD,N,XX);//recursive} return xx;  
	} string Fd_fun (functiondependence fd[],int n,string xx) {//Ask X about F's closure//cout<<x_fn (FD,N,XX); 
Return X_fn (FD,N,XX); }//Remove a dependency from the function dependency set F left->right void 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" <<left<< "<<right;"
	cout<< "post-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<< "}" <<endl; } bool RA (functiondependence a,functiondependence B)//To determine the redundancy attribute {if ((IsIn (a.x,b.x) ==true) && (a.y==b.y)) {Retu
	RN true;
} else return false;  
    } string Stringcutchar (char F, string zz)//Remove a property {int len = Zz.length () from it;
    int k = 0;
    String TT; for (k = 0;k<len;k++) {if (f = = Zz[k]) {} else {Tt+=zz[k]
			;
}} return TT;
	} 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)//has a function dependency 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 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 dependent x→y start to remove it from F, Cut (Dyna1,count,dyna1[k]. X,DYNA1[K].
		Y,DYNA2); Then, in the remaining function dependencies, find the closure of X x+, see if x+ contains y cout<<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)//In the closure {cout<< "\ n" <<dyna1[k]. x<< "," <<dyna1[k ".
		y<< "Redundancy" <<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<< "\ nthe function dependency set f={after redundancy function is dependent"; for (i=0;i<count1;i++) {cout<<dyna3[i]. x<< "," <<dyna3[i ".
			Y
	if (i<count1-1) cout<< ",";
	} cout<< "}" <<endl; Remove the redundancy attribute for (i=0;i<count1;i++) {for (J=0;j<dyna3[i]. X.length (); j + +) {//X-BJ string Temp_x=stringcutchar ((dyna3[i). X) [J],dyna3[i].

			X); if (IsIn (dyna3[i). Y,fd_fun (dyna3,count1,temp_x)) ==true)//That is x->a,x=b1b2. Bm,a belongs to {x minus one of the attribute bi's closures} {Dyna3[i].

			X= temp_x;
			}}/*if (RA (dyna3[i],dyna3[j]) ==true) {break; }*/Dyna4[count2]. X=dyna3[i].
				X Dyna4[count2]. Y=dyna3[i].
				Y	
			
	count2++; 
	}//To obtain minimum coverage cout<<endl;
	cout<< "minimum cover fm=" << "{"; for (k=0;k<count2;k++) {cout<<dyna4[k]. x<< "," <<dyna4[k ".
			Y		
	if (k<count2-1) cout<< ",";
} cout<< "}" <<endl; } void Singler (Functiondependence fd[],int N)//make the right of all function dependencies of f decomposed 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 of 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 overwrite {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);
return 0;  }

Who can tell me, how suddenly can not upload pictures.


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.