CS2_30_Hashing

CS2_30_Hashing - CS2 Module 30 Category: CS Concepts Topic:...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS2 Module 30 Category: CS Concepts Topic: Hashing Objectives Hashing CS 2 Introduction to Object Oriented Programming Module 30 CS Concepts Hashing Hashing Desire We want to store objects in some structure and be able to retrieve them extremely quickly. The number of items to store might be big. Hashing--Why? Motivation: Motivation: Linked lists work well enough for most applications, but provide slow service for large data sets. 835 835 835 835 837 837 837 837 4 4 4 4 3 3 3 3 Ordered insertion takes too long for large sets. 836 836 836 836 5 10 5 10 15 15 20 O(log N) O(N) O(N 2 ) # Items # S t e p s Why it matters Why it matters 5 10 5 10 15 15 20 O(log N) O(N) O(N 2 ) # Items # S t e p s Big Uh Oh The O(logN) performance of trees is good, but what if we have lots of data and need to be really fast? Theres a way Theres a way to reduce to reduce access time access time down to O(1), down to O(1), or nearly so or nearly so Sanity Check 5 10 5 10 15 15 20 O(log N) O(N) O(N 2 ) # Items # S t e p s A search time A search time of O(1)? of O(1)? How is this How is this possible? possible? Introducing. ... Corned Beef Hash(ing) A classic use for leftover corned beef. If you don't have enough leftover potatoes, you can use frozen hash brown potatoes in this dish. 2 tablespoons vegetable oil 1 onion, finely chopped 1 cup peeled, cubed, cooked potatoes 2 cups finely diced cooked corned beef 1/2 teaspoon thyme salt and pepper to taste dash Tabasco sauce 1/2 cup heavy cream 3 poached or fried eggs Heat oil in a heavy skillet and saut onions until tender. Add potatoes, meat, thyme, salt, pepper and Tabasco. Stir well and press mixture down with a spatula to form a large pancake. Pour cream over and press mixture down again. Cook for about 20 minutes, until the hash has a slight crust on the bottom. Flip it over. To do this easily, place a large dinner plate face down over hash and turn the skillet and plate over. Slide the hash from the plate back into the skillet to cook the over side. Continue cooking for an addition 10 - 15 minutes. Slice hash into three wedges. Top each wedge with an egg and serve immediately. Yield: 3 servings. Hashing! Naive Solution: Imagine we had to create a large table, sized to the range of possible social security numbers. Data[ ] myRecord = new Data[ 999999999 ]; /* 123 45 6789 * NOTE: Here, we assume there are * approximately a billion social security * numbers */ Perhaps not the best? Example Social Security numbers come in patterns of: 123-45-6578 There are millions of potentially unique numbers....
View Full Document

Page1 / 105

CS2_30_Hashing - CS2 Module 30 Category: CS Concepts Topic:...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online