David Luebke 1 6/7/2014 CS 332: Algorithms Skip Lists Introduction to Hashing.

Slides:



Advertisements
Similar presentations
Chapter 11. Hash Tables.
Advertisements

David Luebke 1 6/1/2014 CS 332: Algorithms Medians and Order Statistics Structures for Dynamic Sets.
CS16: Introduction to Data Structures & Algorithms
CS 225 Lab #11 – Skip Lists.
The Dictionary ADT: Skip List Implementation
David Luebke 1 6/7/2014 ITCS 6114 Skip Lists Hashing.
Hash Tables Introduction to Algorithms Hash Tables CSE 680 Prof. Roger Crawfis.
Hashing.
David Luebke 1 8/25/2014 CS 332: Algorithms Red-Black Trees.
Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
Lecture 6 Hashing. Motivating Example Want to store a list whose elements are integers between 1 and 5 Will define an array of size 5, and if the list.
CS 332: Algorithms Binary Search Trees. Review: Dynamic Sets ● Next few lectures will focus on data structures rather than straight algorithms ● In particular,
David Luebke 1 5/4/2015 Binary Search Trees. David Luebke 2 5/4/2015 Dynamic Sets ● Want a data structure for dynamic sets ■ Elements have a key and satellite.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Expected Running Times and Randomized Algorithms Instructor Neelima Gupta
Universal Hashing When attempting to foil an malicious adversary, randomize the algorithm Universal hashing: pick a hash function randomly when the algorithm.
BST Data Structure A BST node contains: A BST contains
Review for Test 2 i206 Fall 2010 John Chuang. 2 Topics  Operating System and Memory Hierarchy  Algorithm analysis and Big-O Notation  Data structures.
Hashing COMP171 Fall Hashing 2 Hash table * Support the following operations n Find n Insert n Delete. (deletions may be unnecessary in some applications)
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
Lecture 10: Search Structures and Hashing
David Luebke 1 7/2/2015 ITCS 6114 Binary Search Trees.
David Luebke 1 7/2/2015 Medians and Order Statistics Structures for Dynamic Sets.
Skip Lists1 Skip Lists William Pugh: ” Skip Lists: A Probabilistic Alternative to Balanced Trees ”, 1990  S0S0 S1S1 S2S2 S3S3 
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Data Structures Hashing Uri Zwick January 2014.
Symbol Tables Symbol tables are used by compilers to keep track of information about variables functions class names type names temporary variables etc.
David Luebke 1 9/18/2015 CS 332: Algorithms Red-Black Trees.
Brought to you by Max (ICQ: TEL: ) February 5, 2005 Advanced Data Structures Introduction.
Introduction to Algorithms Jiafen Liu Sept
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 4: Data Structures.
TECH Computer Science Dynamic Sets and Searching Analysis Technique  Amortized Analysis // average cost of each operation in the worst case Dynamic Sets.
Data Structures Hash Tables. Hashing Tables l Motivation: symbol tables n A compiler uses a symbol table to relate symbols to associated data u Symbols:
David Luebke 1 10/25/2015 CS 332: Algorithms Skip Lists Hash Tables.
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
1 Searching Searching in a sorted linked list takes linear time in the worst and average case. Searching in a sorted array takes logarithmic time in the.
David Luebke 1 11/26/2015 Hash Tables. David Luebke 2 11/26/2015 Hash Tables ● Motivation: Dictionaries ■ Set of key/value pairs ■ We care about search,
1 Hashing - Introduction Dictionary = a dynamic set that supports the operations INSERT, DELETE, SEARCH Dictionary = a dynamic set that supports the operations.
Week 8 - Wednesday.  What did we talk about last time?  Level order traversal  BST delete  2-3 trees.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Hashing Suppose we want to search for a data item in a huge data record tables How long will it take? – It depends on the data structure – (unsorted) linked.
Review for Final Exam – cs411/511 Definitions (5 questions, 2 points each) Algorithm Analysis (3 questions, 3 points each) General Questions (3 questions,
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
Hashing 1 Hashing. Hashing 2 Hashing … * Again, a (dynamic) set of elements in which we do ‘search’, ‘insert’, and ‘delete’ n Linear ones: lists, stacks,
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Midterm Midterm is Wednesday next week ! The quiz contains 5 problems = 50 min + 0 min more –Master Theorem/ Examples –Quicksort/ Mergesort –Binary Heaps.
Red-Black Trees. Review: Binary Search Trees ● Binary Search Trees (BSTs) are an important data structure for dynamic sets ● In addition to satellite.
Instructor Neelima Gupta Expected Running Times and Randomized Algorithms Instructor Neelima Gupta
Hashing COMP171. Hashing 2 Hashing … * Again, a (dynamic) set of elements in which we do ‘search’, ‘insert’, and ‘delete’ n Linear ones: lists, stacks,
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
CSC 413/513: Intro to Algorithms Hash Tables. ● Hash table: ■ Given a table T and a record x, with key (= symbol) and satellite data, we need to support:
David Luebke 1 3/19/2016 CS 332: Algorithms Augmenting Data Structures.
David Luebke 1 3/20/2016 CS 332: Algorithms Skip Lists.
CS6045: Advanced Algorithms Data Structures. Dynamic Sets Next few lectures will focus on data structures rather than straight algorithms In particular,
Prof. Amr Goneid, AUC1 CSCI 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 5. Dictionaries(2): Hash Tables.
Hashing.
CS 332: Algorithms Hash Tables David Luebke /19/2018.
CS 332: Algorithms Red-Black Trees David Luebke /20/2018.
Dynamic Order Statistics
CS200: Algorithms Analysis
CS6045: Advanced Algorithms
Advanced Implementation of Tables
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
CS 5243: Algorithms Hash Tables.
Binary SearchTrees [CLRS] – Chap 12.
CS 3343: Analysis of Algorithms
Lecture-Hashing.
Presentation transcript:

David Luebke 1 6/7/2014 CS 332: Algorithms Skip Lists Introduction to Hashing

David Luebke 2 6/7/2014 Review: Red-Black Trees Red-black trees: Binary search trees augmented with node color Operations designed to guarantee that the height h = O(lg n) We described the properties of red-black trees We proved that these guarantee h = O(lg n) We described operations on red-black trees Only tricky operations: insert, delete Use rotation to restructure tree

David Luebke 3 6/7/2014 Review: Skip Lists A relatively recent data structure A probabilistic alternative to balanced trees A randomized algorithm with benefits of r-b trees O(lg n) expected time for Search, Insert O(1) time for Min, Max, Succ, Pred Much easier to code than r-b trees Fast!

David Luebke 4 6/7/2014 Review: Linked Lists Think about a linked list as a structure for dynamic sets. What is the running time of: Min() and Max() ? Successor() ? Delete() ? How can we make this O(1)? Predecessor() ? Search() ? Insert() ? Goal: make these O(lg n) time in a linked-list setting These all take O(1) time in a doubly linked list. Can you think of a way to do these in O(1) time in a red-black tree? A: threaded red-black tree w/ doubly linked list connecting nodes in sorted order Idea: keep several levels of linked lists, with high-level lists skipping some low-level items

David Luebke 5 6/7/2014 Skip Lists The basic idea: Keep a doubly-linked list of elements Min, max, successor, predecessor: O(1) time Delete is O(1) time, Insert is O(1)+Search time During insert, add each level-i element to level i+1 with probability p (e.g., p = 1/2 or p = 1/4) level level 2 level 3

David Luebke 6 6/7/2014 Skip List Search To search for an element with a given key: Find location in top list Top list has O(1) elements with high probability Location in this list defines a range of items in next list Drop down a level and recurse O(1) time per level on average O(lg n) levels with high probability Total time: O(lg n)

David Luebke 7 6/7/2014 Skip List Insert Skip list insert: analysis Do a search for that key Insert element in bottom-level list With probability p, recurse to insert in next level Expected number of lists = 1+ p + p 2 + … = ??? = 1/(1-p) = O(1) if p is constant Total time = Search + O(1) = O(lg n) expected Skip list delete: O(1)

David Luebke 8 6/7/2014 Skip Lists O(1) expected time for most operations O(lg n) expected time for insert O(n 2 ) time worst case (Why?) But random, so no particular order of insertion evokes worst-case behavior O(n) expected storage requirements (Why?) Easy to code

David Luebke 9 6/7/2014 Review: Hashing Tables Motivation: symbol tables A compiler uses a symbol table to relate symbols to associated data Symbols: variable names, procedure names, etc. Associated data: memory location, call graph, etc. For a symbol table (also called a dictionary), we care about search, insertion, and deletion We typically dont care about sorted order

David Luebke 10 6/7/2014 Review: Hash Tables More formally: Given a table T and a record x, with key (= symbol) and satellite data, we need to support: Insert (T, x) Delete (T, x) Search(T, x) We want these to be fast, but dont care about sorting the records The structure we will use is a hash table Supports all the above in O(1) expected time!

David Luebke 11 6/7/2014 Hashing: Keys In the following discussions we will consider all keys to be (possibly large) natural numbers How can we convert floats to natural numbers for hashing purposes? How can we convert ASCII strings to natural numbers for hashing purposes?

David Luebke 12 6/7/2014 Review: Direct Addressing Suppose: The range of keys is 0..m-1 Keys are distinct The idea: Set up an array T[0..m-1] in which T[i] = xif x T and key[x] = i T[i] = NULLotherwise This is called a direct-address table Operations take O(1) time! So whats the problem?

David Luebke 13 6/7/2014 The Problem With Direct Addressing Direct addressing works well when the range m of keys is relatively small But what if the keys are 32-bit integers? Problem 1: direct-address table will have 2 32 entries, more than 4 billion Problem 2: even if memory is not an issue, the time to initialize the elements to NULL may be Solution: map keys to smaller range 0..m-1 This mapping is called a hash function