0

Please could someone help by telling me a general algorithm for searching for entries using linear probing.

I have the following, but I think it is pseudo code instead of an algorithm: 1) use hash function to find index of where an item should be. 2) If it isn't there search records that records after that hash location until either it is found, or until an empty record is found. 3) If there is an empty spot in the table before record is found, it means that the the record is not there.

  • More information on what you need would be helpfull. What you got is pseudocode, but pseudocode is one kind of a description of an algorithm, so I'm not sure what you're asking for. Maybe [this description](http://www.cs.rmit.edu.au/online/blackboard/chapter/05/documents/contribute/chapter/05/linear-probing.html) can help? – Tobias Jun 05 '19 at 06:59
  • https://en.wikipedia.org/wiki/Linear_probing – user3386109 Jun 05 '19 at 07:04

1 Answers1

0

To search for a given key x, the cells of T are examined, beginning with the cell at index h(x) (where h is the hash function) and continuing to the adjacent cells h(x) + 1, h(x) + 2, ..., until finding either an empty cell or a cell whose stored key is x. If a cell containing the key is found, the search returns the value from that cell. Otherwise, if an empty cell is found, the key cannot be in the table, because it would have been placed in that cell in preference to any later cell that has not yet been searched. In this case, the search returns as its result that the key is not present in the dictionary

pio
  • 500
  • 5
  • 12
  • 1
    I really appreciate your answer, would you also be able to give an algorithm for removing entries using linear probing as well? – Jordan Hirson Jun 05 '19 at 07:21