MIS 215 Module 5 Binary Trees - PowerPoint PPT Presentation

About This Presentation
Title:

MIS 215 Module 5 Binary Trees

Description:

A function that takes an object and generates a number (or some form of an ... Hash functions must usually be custom-designed for the kind of keys used for ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 14
Provided by: WrightStat2
Category:
Tags: mis | binary | module | trees

less

Transcript and Presenter's Notes

Title: MIS 215 Module 5 Binary Trees


1
MIS 215 Module 5 Binary Trees
2
Where are we?
MIS215
Basic Algorithms
Introduction
List Structures
Advanced structures
Search Techniques
Intro to Java, Course
Sorting Techniques
Java lang. basics
Hashtables
Linked Lists
Binary Search
Graphs, Trees
Stacks, Queues
Arrays
Bubblesort
Fast Sorting algos (quicksort, mergesort)
Newbie
Programmers
Developers
Professionals
Designers
3
Todays buzzwords
  • Key
  • A component of an object that is typically used
    for quick retrieval of the object
  • Hashing function
  • A function that takes an object and generates a
    number (or some form of an address) to a location
    where the object should be placed
  • Hash Table
  • A data structure that stores items in designated
    places using hashing functions for speeding up
    key-based search

4
Hash TablesA New Data Structure
  • Start with an array that holds the hash table.
  • Use a hash function to take a key and map it to
    some index in the array. This function will
    generally map several different keys to the same
    index.
  • If the desired record is in the location given by
    the index, then were finished, otherwise we must
    use some method to resolve the collision that may
    have occurred between two records wanting to go
    to the same location.
  • This process is called hashing. To use hashing
    we must
  • find good hash functions
  • determine how to resolve collisions

5
Hash Function Requirements
  • Hash functions must
  • Be fast computed in O(1) time
  • Distribute keys evenly over the hash table
  • Preferably
  • All location of hash table should have equal
    probability of being filled

6
Collision Resolution with Open Addressing
  • Linear Probing
  • Linear probing starts with the hash address
    and searches sequentially for the target key or
    an empty position. The array should be considered
    circular, so that when the last location is
    reached, the search proceeds to the first
    location of the array.

7
Collision Resolution with Open Addressing(Contd.)
  • Quadratic Probing
  • If there is a collision at hash address h,
    quadratic probing goes to location h1, h4,
    h9,, that is, at locations h i2 for i1,2,...
  • Other Methods
  • Key-dependent increments
  • Random probing

8
Chained Hash Tables
9
Issues with Chaining
  • Worst case all elements map to the same cell
    all operations O(N)!
  • Load factor
  • Ratio of actual number of elements to maximum
    possible number of elements
  • Turns out at high load factors (gt0.7) open
    addressing performs worse than chaining.

10
Avoid High Load factors!
  • Start with a large enough hash table compared to
    expected number of entries
  • Rehashing
  • Once a high load factor is detected, create a new
    hash table and rehash all elements to the new
    table

11
Birthday Surprise How Collisions are Possible?
  • If 24 or more randomly chosen people are in a
    room, then it is likely that at least two will
    share their birthday. For hashing, the birthday
    surprise says that for any problem of reasonable
    size, collisions will almost certainly occur.

12
Comparison of data structures
13
Summary Discussion
  • In using a hash table, let the nature of the data
    and the required operations help you decide
    between chaining and open addressing.
  • Hash functions must usually be custom-designed
    for the kind of keys used for accessing the hash
    table.
  • Recall from the analysis of hashing that some
    collisions will almost inevitably occur.
  • For open addressing, clustering is unlikely to be
    a problem until the hash table is more than half
    full.
Write a Comment
User Comments (0)
About PowerShow.com