We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,763 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Quadratic Probing

Review for a final and I had a question...

You are give a hash function h(x) = x%11 and the size of the hash table is 11. The inputs are 4371,1323,6173,4199,4344,9679,1989. What would the resulting hash table be using quadratic probing.

Would I start with 4371 and then do the following

(h(x)+i^2)%size = location ?

h(x) = 4371mod11 = 4
size = 11
i = ???

Not sure thanks for any help (the book is confusing me even more ).

3
Contributors
3
Replies
12 Hours
Discussion Span
5 Months Ago
Last Updated
5
Views
Question
Answered
FUTURECompEng
Junior Poster in Training
50 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Think about it as an array index (with 0-index).

/*
There are 11 indices in your hash locations. Each index is determined by the result after mod.
Hashing 4371
i = 4371 % 11 = 4
    +---+
    | 0 |
    +---+
    | 1 |
    +---+
    | 2 |
    +---+
    | 3 |
    +---+
    | 4 |  => 4371
    +---+
    | 5 |
    +---+
    | 6 |
    +---+
    | 7 |
    +---+
    | 8 |
    +---+
    | 9 |
    +---+
    | 10|
    +---+

Hashing 1323
i = 1323 % 11 = 3
    +---+
    | 0 |
    +---+
    | 1 |
    +---+
    | 2 |
    +---+
    | 3 |  => 1323
    +---+
    | 4 |  => 4371
    +---+
    | 5 |
    +---+
    | 6 |
    +---+
    | 7 |
    +---+
    | 8 |
    +---+
    | 9 |
    +---+
    | 10|
    +---+

 and so on...
*/

PS: You will have to deal with collision as well (when the hash location value is the same for 2 or more numbers). There are rules for collision.

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17

The wikipedia article on quadratic probing starts with a really clear and simple explanation...

JamesCherrill
... trying to help
Moderator
8,510 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 30

Thanks!

FUTURECompEng
Junior Poster in Training
50 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Months Ago by JamesCherrill and Taywin

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0919 seconds using 2.73MB