SlideShare une entreprise Scribd logo
1  sur  12
The answer to your interview
question is probably a hash table
intro to hash tables
Amy Hua
Why hash tables?
Great for quickly looking something up. Usually faster than arrays or most anything else.
Big O Performance: O(1) to O(n)
Example applications
For example
• Say you have an array of ~100 items
– To look up item at position 3:
• myarray[3]
• O(1)
• But how do you know that the item you’re
looking for is in position 3?
For example
In a phone book, how do you know Jane Smith is on page 245?
You probably used an index (last name: Smith) to find the page or range of
pages Jane Smith would be located on.
For example
In a phone book, how do you know Jane Smith is on page 245?
LookUpPageByLastName(“Smith”) = page 245
hash function
If you know how to use a phone book,
you know how to use a hash table
Hash table: data structure for quickly looking things up.
Given some key, we can apply a hash function to it to find
the index in the array that we want to access.
hash function: takes a key  returns an index in the array
LookUpPageByLastName(“Smith”) = 245
hash function key index
Example hash function
Given keys
keys: Lizzie McGuire
Fiona Apple
James Bond
Index them by converting their names to integers
Lizzie McGuire  13223
Fiona Apple  12342
James Bond  23523
Divide their numbers by a large enough number (modulo)
Lizzie McGuire  3,223 % 1000 = 3 remainder 0.223
Fiona Apple  4,342 % 1000 = 4 remainder .342
James Bond  9,523 % 1000 = 9 remainder .523
Hash table: stores the key (used to find the index) along with the associated value we’re looking up.
Collisions
Sometimes, more than one name is on a given page: multiple elements can
have the same index. In other words, collisions can occur in our hash table.
How do you handle collisions?
Collisions
Well what do you do when you see multiple names on the same page in a
phone book?
You go through a
linked list
You now know how to use a phone
book.. again
Sources
• http://www.cs.uregina.ca/Links/class-
info/210/Hash/
References
• http://www.youtube.com/watch?v=MfhjkfocRR0&li
st=TLxupPRqcHJiw
• http://www.cs.uiuc.edu/~jeffe/teaching/algorithms/n
otes/07-hashing.pdf
• http://courses.csail.mit.edu/6.006/spring11/rec/rec
05.pdf

Contenu connexe

Tendances

Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms Sam Bowne
 
Using Salesforce as a Student Information System SIS
Using Salesforce as a Student Information System SISUsing Salesforce as a Student Information System SIS
Using Salesforce as a Student Information System SISSalesforce.org
 
Best Practices for RESTful Web Services
Best Practices for RESTful Web ServicesBest Practices for RESTful Web Services
Best Practices for RESTful Web ServicesSalesforce Developers
 
Practical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProPractical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProSam Bowne
 
Amazon A9 algorithm - Overview
Amazon A9 algorithm - OverviewAmazon A9 algorithm - Overview
Amazon A9 algorithm - OverviewAnand Bidarkar
 
salesforce-101-overview-training.pptx
salesforce-101-overview-training.pptxsalesforce-101-overview-training.pptx
salesforce-101-overview-training.pptxSwapanjeetSingh1
 
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...Sam Bowne
 
Vulnerability Assessment and Penetration Testing Report
Vulnerability Assessment and Penetration Testing Report Vulnerability Assessment and Penetration Testing Report
Vulnerability Assessment and Penetration Testing Report Rishabh Upadhyay
 
COPADO - Plateforme de DEVOPS pour Salesforce
COPADO - Plateforme de DEVOPS pour SalesforceCOPADO - Plateforme de DEVOPS pour Salesforce
COPADO - Plateforme de DEVOPS pour SalesforceThierry TROUIN ☁
 
Salesforce Lightning Design System
Salesforce Lightning Design SystemSalesforce Lightning Design System
Salesforce Lightning Design SystemDurgesh Dhoot
 
Designing Website on HubSpot's CMS
Designing Website on HubSpot's CMSDesigning Website on HubSpot's CMS
Designing Website on HubSpot's CMSHubSpot
 
Software evolution and Verification,validation
Software evolution and Verification,validationSoftware evolution and Verification,validation
Software evolution and Verification,validationArchanaMani2
 
CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)Sam Bowne
 

Tendances (20)

Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
 
Using Salesforce as a Student Information System SIS
Using Salesforce as a Student Information System SISUsing Salesforce as a Student Information System SIS
Using Salesforce as a Student Information System SIS
 
Salesforce 101
Salesforce 101Salesforce 101
Salesforce 101
 
Best Practices for RESTful Web Services
Best Practices for RESTful Web ServicesBest Practices for RESTful Web Services
Best Practices for RESTful Web Services
 
Practical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProPractical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA Pro
 
Amazon A9 algorithm - Overview
Amazon A9 algorithm - OverviewAmazon A9 algorithm - Overview
Amazon A9 algorithm - Overview
 
salesforce-101-overview-training.pptx
salesforce-101-overview-training.pptxsalesforce-101-overview-training.pptx
salesforce-101-overview-training.pptx
 
Top Benefits of Salesforce in Business
Top Benefits of Salesforce in BusinessTop Benefits of Salesforce in Business
Top Benefits of Salesforce in Business
 
Code review
Code reviewCode review
Code review
 
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
 
MARKETING SMACKDOWN: Hiring In-House Talent VS Hiring A Marketing Agency
MARKETING SMACKDOWN: Hiring In-House Talent VS Hiring A Marketing AgencyMARKETING SMACKDOWN: Hiring In-House Talent VS Hiring A Marketing Agency
MARKETING SMACKDOWN: Hiring In-House Talent VS Hiring A Marketing Agency
 
Vulnerability Assessment and Penetration Testing Report
Vulnerability Assessment and Penetration Testing Report Vulnerability Assessment and Penetration Testing Report
Vulnerability Assessment and Penetration Testing Report
 
Salesforce PPT.pptx
Salesforce PPT.pptxSalesforce PPT.pptx
Salesforce PPT.pptx
 
Security testing
Security testingSecurity testing
Security testing
 
COPADO - Plateforme de DEVOPS pour Salesforce
COPADO - Plateforme de DEVOPS pour SalesforceCOPADO - Plateforme de DEVOPS pour Salesforce
COPADO - Plateforme de DEVOPS pour Salesforce
 
Salesforce Lightning Design System
Salesforce Lightning Design SystemSalesforce Lightning Design System
Salesforce Lightning Design System
 
Designing Website on HubSpot's CMS
Designing Website on HubSpot's CMSDesigning Website on HubSpot's CMS
Designing Website on HubSpot's CMS
 
Software evolution and Verification,validation
Software evolution and Verification,validationSoftware evolution and Verification,validation
Software evolution and Verification,validation
 
How to use canva
How to use canva How to use canva
How to use canva
 
CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)
 

En vedette

Hash table and heaps
Hash table and heapsHash table and heaps
Hash table and heapsKatang Isip
 
Best for b trees
Best for b treesBest for b trees
Best for b treesDineshRaaja
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data StructureAnuj Modi
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashingRafi Dar
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
 
Hashing and Hash Tables
Hashing and Hash TablesHashing and Hash Tables
Hashing and Hash Tablesadil raja
 
Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2SHAKOOR AB
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and GraphsIntro C# Book
 
Trees data structure
Trees data structureTrees data structure
Trees data structureSumit Gupta
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 

En vedette (16)

Hash tables
Hash tablesHash tables
Hash tables
 
Ie
IeIe
Ie
 
Hash table and heaps
Hash table and heapsHash table and heaps
Hash table and heaps
 
Balanced Trees
Balanced TreesBalanced Trees
Balanced Trees
 
Best for b trees
Best for b treesBest for b trees
Best for b trees
 
Hashing
HashingHashing
Hashing
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashing
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Hashing and Hash Tables
Hashing and Hash TablesHashing and Hash Tables
Hashing and Hash Tables
 
Hashing PPT
Hashing PPTHashing PPT
Hashing PPT
 
Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2
 
Hashing
HashingHashing
Hashing
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 

Dernier

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Dernier (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

Intro to Hash tables

  • 1. The answer to your interview question is probably a hash table intro to hash tables Amy Hua
  • 2. Why hash tables? Great for quickly looking something up. Usually faster than arrays or most anything else. Big O Performance: O(1) to O(n)
  • 4. For example • Say you have an array of ~100 items – To look up item at position 3: • myarray[3] • O(1) • But how do you know that the item you’re looking for is in position 3?
  • 5. For example In a phone book, how do you know Jane Smith is on page 245? You probably used an index (last name: Smith) to find the page or range of pages Jane Smith would be located on.
  • 6. For example In a phone book, how do you know Jane Smith is on page 245? LookUpPageByLastName(“Smith”) = page 245 hash function
  • 7. If you know how to use a phone book, you know how to use a hash table Hash table: data structure for quickly looking things up. Given some key, we can apply a hash function to it to find the index in the array that we want to access. hash function: takes a key  returns an index in the array LookUpPageByLastName(“Smith”) = 245 hash function key index
  • 8. Example hash function Given keys keys: Lizzie McGuire Fiona Apple James Bond Index them by converting their names to integers Lizzie McGuire  13223 Fiona Apple  12342 James Bond  23523 Divide their numbers by a large enough number (modulo) Lizzie McGuire  3,223 % 1000 = 3 remainder 0.223 Fiona Apple  4,342 % 1000 = 4 remainder .342 James Bond  9,523 % 1000 = 9 remainder .523 Hash table: stores the key (used to find the index) along with the associated value we’re looking up.
  • 9. Collisions Sometimes, more than one name is on a given page: multiple elements can have the same index. In other words, collisions can occur in our hash table. How do you handle collisions?
  • 10. Collisions Well what do you do when you see multiple names on the same page in a phone book? You go through a linked list
  • 11. You now know how to use a phone book.. again
  • 12. Sources • http://www.cs.uregina.ca/Links/class- info/210/Hash/ References • http://www.youtube.com/watch?v=MfhjkfocRR0&li st=TLxupPRqcHJiw • http://www.cs.uiuc.edu/~jeffe/teaching/algorithms/n otes/07-hashing.pdf • http://courses.csail.mit.edu/6.006/spring11/rec/rec 05.pdf