hash tables
play

Hash Tables Bryce Boe 2013/08/20 CS24, Summer 2013 C - PowerPoint PPT Presentation

Hash Tables Bryce Boe 2013/08/20 CS24, Summer 2013 C Outline Lab 8 Solu@on Hash Tables Hash Tables ADT that has expected running @me


  1. Hash ¡Tables ¡ Bryce ¡Boe ¡ 2013/08/20 ¡ CS24, ¡Summer ¡2013 ¡C ¡

  2. Outline ¡ • Lab ¡8 ¡Solu@on ¡ • Hash ¡Tables ¡

  3. Hash ¡Tables ¡ • ADT ¡that ¡has ¡expected ¡running ¡@me ¡of ¡O(1) ¡ for ¡all ¡opera@ons ¡ • How ¡can ¡we ¡do ¡this? ¡ – Trade ¡space ¡for ¡running ¡@me ¡

  4. Hash ¡Func@on ¡ • Converts ¡a ¡key ¡into ¡an ¡index ¡that ¡fits ¡inside ¡of ¡ the ¡hash-­‑table ¡array ¡ • Ideally ¡should ¡be ¡uniformly ¡distributed ¡

  5. Collisions ¡ • What ¡should ¡we ¡do ¡when ¡collisions ¡occur? ¡ – Linear ¡Probing ¡ • new_hash ¡= ¡(old_hash ¡+ ¡c) ¡% ¡max_size ¡ • Can ¡result ¡in ¡clustering, ¡but ¡beXer ¡ locality ¡of ¡reference ¡ – Quadra@c ¡Probing ¡ • new_hash ¡= ¡(old_hash ¡+ ¡c*i 2 ) ¡% ¡max_size ¡ • May ¡not ¡examine ¡all ¡buckets ¡ – Buckets ¡and ¡chaining ¡ • Store ¡a ¡linked ¡list ¡at ¡each ¡loca@on ¡to ¡store ¡collisions ¡in ¡

  6. Dele@ons ¡and ¡probing ¡ • How ¡can ¡we ¡handle ¡dele@ons ¡of ¡items ¡when ¡ performing ¡probing? ¡ – Mark ¡the ¡“empty” ¡space ¡as ¡deleted ¡ • Frees ¡up ¡the ¡space ¡and ¡does ¡not ¡break ¡previous ¡entries ¡ • Becomes ¡inefficient ¡over@me ¡ – Acceptable ¡due ¡to ¡re-­‑sizing ¡the ¡hash ¡table ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend