Skip to Content
A Common-Sense Guide to Data Structures and Algorithms
book

A Common-Sense Guide to Data Structures and Algorithms

by Jay Wengrow
August 2017
Intermediate to advanced
222 pages
5h 3m
English
Pragmatic Bookshelf
Content preview from A Common-Sense Guide to Data Structures and Algorithms

Chapter 7Blazing Fast Lookup with Hash Tables

Imagine that you’re writing a program that allows customers to order food to go from a fast-food restaurant, and you’re implementing a menu of foods with their respective prices. You could, of course, use an array:

 menu = [ [​"french fries"​, 0.75], [​"hamburger"​, 2.5],
 [​"hot dog"​, 1.5], [​"soda"​, 0.6] ]

This array contains several subarrays, and each subarray contains two elements. The first element is a string representing the food on the menu, and the second element represents the price of that food.

As we learned in Chapter 2, Why Algorithms Matter, if this array were unordered, searching for the price of a given food would take O(N) steps since the computer would have to perform a linear ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition

A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition

Jay Wengrow

Publisher Resources

ISBN: 9781680502794Errata Page