Purchase Solution

Understanding a bad hash function

Not what you're looking for?

Ask Custom Question

12.16

Consider the given hashing function object for strings. What can you say about strings "aefghk" and "gaefkh"? Is this a good hashing function? Why?

class hFstr
{
public:
unsigned int operator () (const string& s) const
{
int i;
unsigned int hashval = 0;

for ( i = 0; i < s.length(); i++)
hashval += s[i];

return hashval;
}
};

Attachments
Purchase this Solution

Solution Summary

This solution explains why the provided hash function is a bad function.

Solution Preview

This hash function is simply summing the values of each of the ...

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Javscript Basics

Quiz on basics of javascript programming language.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.