Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ code for the Hash function, and a code that will resolve the collisi

ID: 3622409 • Letter: W

Question

Write a C++ code for the Hash function, and a code that will resolve the collision/clash in a Hash Table.

Explanation / Answer

Hashing - open addressing, linear probing # include # include //Hash function k=x%97 #define TABLE_SIZE 97 //gia su gia tri cac khoa can them la >0 //dung so 0 de bieu dien phan tu nay da bi xoa //so -1 bieu dien o nay trong int hash(int x) { return x % TABLE_SIZE; } //khoi tao bang bam void init(int HASH[]) { int i; for(i=0;i0) { i=(i+1)%TABLE_SIZE; if(i==k)//table is full { printf("Bang bam day !"); return -1; //loi } } HASH[i]=x; } return 0; //them thanh cong } //tim va tra ve vi tri phan tu neu co, nguoc lai tra ve -1 int search(int HASH[], int x) { int i; int k = hash(x); if(HASH[k]==x) return k; else { i=(k+1)%TABLE_SIZE; while(HASH[i]>=0 && HASH[i]!=x) i=(i+1)%TABLE_SIZE; if(HASH[i]=0) printf("Ton tai 294 "); if(search(HASH,295)>=0) printf("Ton tai 295 "); k=search(HASH,3); printf("%d %d %d ",3,hash(3),k); k=search(HASH,100); printf("%d %d %d ",100,hash(100),k); k=search(HASH,197); printf("%d %d %d ",197,hash(197),k); k=search(HASH,294); printf("%d %d %d ",294,hash(294),k); remove(HASH,100); if(search(HASH,197)>=0) printf("Ton tai 197 "); system("pause"); return 0; } Open addressing, Quaratic Probing # include # include //Hash function k=x%97 #define TABLE_SIZE 97 //gia su gia tri cac khoa can them la >0 //dung so 0 de bieu dien phan tu nay da bi xoa //so -1 bieu dien o nay trong int hash(int x) { return x % TABLE_SIZE; } //khoi tao bang bam void init(int HASH[]) { int i; for(i=0;i0) { j++; i=(k+j*j)%TABLE_SIZE; } HASH[i]=x; } return 0; //them thanh cong } //tim va tra ve vi tri phan tu neu co, nguoc lai tra ve -1 int search(int HASH[], int x) { int i,j; int k = hash(x); if(HASH[k]==x) return k; else { j=1; i=(k+j*j)%TABLE_SIZE; while(HASH[i]>=0 && HASH[i]!=x) { j++; i=(k+j*j)%TABLE_SIZE; } if(HASH[i]=0) printf("Ton tai 294 "); if(search(HASH,295)>=0) printf("Ton tai 295 "); k=search(HASH,3); printf("%d %d %d ",3,hash(3),k); k=search(HASH,100); printf("%d %d %d ",100,hash(100),k); k=search(HASH,197); printf("%d %d %d ",197,hash(197),k); k=search(HASH,294); printf("%d %d %d ",294,hash(294),k); remove(HASH,100); if(search(HASH,197)>=0) printf("Ton tai 197 "); system("pause"); return 0; } I compile the source code using Dev-C++ Full source code : http://www.mediafire.com/?9o37ki723cl2r8o
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote