l08-more-trees

l08-more-trees - CS112: Data Structures Lecture 8 More...

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

View Full Document Right Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 8 CS112: Data Structures CS112: Data Structures Lecture 8 More About Trees
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 2 Lecture 8 Exam in 1 results Exam in 1 results :-( Tentatively adding 15 points (Out of 150) Sakai will stay the raw score
Background image of page 2
CS112: Slides for Prof. Steinberg ʼ s lecture 3 Lecture 8 Raw Scores Raw Scores 0 2 4 6 8 10 12 68 83 98 113 128 143 158
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 4 Lecture 8 Review: Hashing Review: Hashing Suppose we want to store a set of numbers add number to set, delete from set, test if in set should all be O(1) If range of numbers is small, e.g. 0 . . 9, we can use a boolean array 0 1 2 3 4 5 6 7 8 9 t f f f t t f t f f What if range of numbers is large, e.g. 0…500,0000? but only a small number of numbers, e.g. 10
Background image of page 4
CS112: Slides for Prof. Steinberg ʼ s lecture 5 Lecture 8 Hashing Hashing If we use array of 500,000 elements, they will nearly all be false. Idea: divide the range into 500 blocks of 1000 numbers Block 10: (numbers 9,001 to 10,000) Is any set element in this range? True Which one: 9,251 Block 9:
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 6 Lecture 8 Hashing Hashing Array of 500 objects Insert n: put in object at index n/1000 Lookup n: look in object at index n/1000 is any number in this object? is it the right number? All O(1)
Background image of page 6
CS112: Slides for Prof. Steinberg ʼ s lecture 7 Lecture 8 Hash Function Hash Function What if numbers not random, eg likely to be near each other? convert n to index in some other way, e.g. index = n mod 500 In general, function that makes each index equally likely: “makes hash out of any pattern in the numbers” - Hash function: converts data to hash code Mapping function: converts hash code to array index. (Why separate this?)
Background image of page 7

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

View Full DocumentRight Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 8 Lecture 8 Collisions Collisions Even with 500 indices for 10 numbers, it is possible that more than one number will hash to same index As we reduce number of indices probability of collision grows => must be some way to handle collisions
Background image of page 8
CS112: Slides for Prof. Steinberg ʼ s lecture 9 Lecture 8 Linear Probing
Background image of page 9

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

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

Page1 / 34

l08-more-trees - CS112: Data Structures Lecture 8 More...

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

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