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

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

View Full Document Right Arrow Icon
CS2 Module 30 Category: CS Concepts Topic: Hashing Objectives Hashing
Image of page 1

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

View Full Document Right Arrow Icon
CS 2 Introduction to Object Oriented Programming Module 30 CS Concepts Hashing
Image of page 2
Hashing
Image of page 3

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

View Full Document Right Arrow Icon
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.
Image of page 4
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
Image of page 5

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

View Full Document Right Arrow Icon
0 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
Image of page 6
0 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? There’s a way There’s a way to reduce to reduce access time access time down to O(1), down to O(1), or nearly so or nearly so
Image of page 7

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

View Full Document Right Arrow Icon
Sanity Check 0 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 ....
Image of page 8
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. 
Image of page 9

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

View Full Document Right Arrow Icon
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?
Image of page 10
Example Social Security numbers come in patterns of: 123-45-6578 There are millions of potentially unique numbers. We might be tempted to use a social security number as an “index value” to some data set... 0
Image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern