Jump to content

Hashing Algorithm

- - - - -

  • Please log in to reply
9 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Ok, im completly confused with this algorithm.
I have an algorithm which adds together the numeric values of the first three letters from array with 15 names. How i can find, how long does the storage array need to be?

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Without seeing or better explaining the algorithm it's hard to tell.

Out of your current text I deduct that you transform an array of names into a number...

#3
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
I have an array of 15 names

Arthur

Barry

Francis...

First create an index array whose elements refer to the position in my array of the first key which starts with a given letter.
Then create another array which holds pointers to chains holding keys for the different initial letters.
And now i have to improve the previous method by converting the key to an index using hashing function (adds together first 3 letters)
I have to find how long does the new storage array need to be

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java

Quote

First create an index array whose elements refer to the position in my array of the first key which starts with a given letter.
Then create another array which holds pointers to chains holding keys for the different initial letters.
And now i have to improve the previous method by converting the key to an index using hashing function (adds together first 3 letters)
I have to find how long does the new storage array need to be
I lost you at line 1 :P

#5
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Ok lets try again :P

At the beggining i have a simple array with 15 names(Arthur, Barry, Francis, Garry...)

Then using an index array that its element points to the first name of each first letter (ex. if i have Harry and Henry, index's array element will point only on Harry) So index array will have elements like (0,3,-1,-1,5...) where -1 is when names array doesnt has name which starting with that letter.
So..we can say
IndexArr[0]->A
IndexArr[1]->B
IndexArr[2]->C etc..

Now i have to use the hashing algorithm to improve the efficiency of method above. Each key converted to an index using a hashing function, which adds the numeric values of the first three letters.

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#6
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Okay assume 4 names only
Names array = {"dalc", "aalc", "balc", "calc"}
Index array = {1, 2, 3, 0, -1, -1, ...}
And now instead of doing it with 1 letter you wanna have 3?
So
IndexArr[0] -> AAA
IndexArr[1] -> AAB
IndexArr[2] -> AAC
....
And you need to know the total size of indexArr?

#7
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Names are in alphabetic row

Names array = {"aalc", "balc", "calc", "dalc"}
Index array = {0, 1, 2, 3, -1, -1, ...}

And are the three first letters each name (aal, bal, cal, dal)
Yes, asking the total size. Im really confused with hashing algorithm, so may be the way i understant it to be wrong

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#8
Warrior

Warrior

    Programmer

  • Members
  • PipPipPipPip
  • 130 posts
its unclear what you are trying to do?
maybe it will help if you post the whole program...perhaps there is an other way around
Be a joke unto yourself!
Check out my blog at Flashcore

#9
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Ok, i will try one more time. To store the first letter from a word, i need an array of size 26, now to store the first three letters from a word, what the size of the array will be using a simple hashing function?

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#10
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
So you need to create an array of
AAA

AAB

AAC

AAD

...

DEA

DEB

DEC

...

ZZZ
And you just need to know the total size of that?
I think that's just 26³




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users