Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
C++ Data Structures and Algorithms

You're reading from  C++ Data Structures and Algorithms

Product type Book
Published in Apr 2018
Publisher Packt
ISBN-13 9781788835213
Pages 322 pages
Edition 1st Edition
Languages
Author (1):
Wisnu Anggoro Wisnu Anggoro
Profile icon Wisnu Anggoro

Table of Contents (16) Chapters

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Learning Data Structures and Algorithms in C++ Storing Data in Lists and Linked Lists Constructing Stacks and Queues Arranging Data Elements Using a Sorting Algorithm Finding out an Element Using Searching Algorithms Dealing with the String Data Type Building a Hierarchical Tree Structure Associating a Value to a Key in a Hash Table Implementation of Algorithms in Real Life Other Books You May Enjoy Index

Implementing the open addressing technique


As we discussed earlier at beginning of this chapter, an open addressing technique stores all elements in the hash table itself. A collision will not happen, since there is a calculation that will be performed if a collision is about to happen. Based on this calculation, we can have three types of open addressing technique—Linear probing, quadratic probing, and double hashing. The difference between the three is the formula for finding the next free space if the hash key of the given element has been occupied:

  • In linear probing, if the hash key has been occupied by another element, we use the following formula to find the next free space—(HashFunction(key) + n) % TABLE_SIZE, then increase n from 0 until a free slot is found. Here is the explanation—If HashFunction(key) % TABLE_SIZE is occupied, then try (HashFunction(key) + 1) % TABLE_SIZE. If the slot is still occupied, try (HashFunction(key) + 2) % TABLE_SIZE. Repeat it by increasing n until a...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}