Implementing Hash and AVL

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Hash Tables1  
Advertisements

CSE 373 Data Structures and Algorithms Lecture 18: Hashing III.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Searching Tables Table: sequence of (key,information) pairs (key,information) pair is a record key uniquely identifies information, so no duplicate records.
Week 15 – Monday.  What did we talk about last time?  Tries.
Data Structures and Algorithms I
Hash Tables 1/28/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
May 3rd – Hashing & Graphs
October 2nd – Dictionary ADT
Hashing CSE 2011 Winter July 2018.
Week 8 - Wednesday CS221.
Week 8 - Friday CS221.
Week 15 – Monday CS221.
October 30th – Priority QUeues
Week 11 - Friday CS221.
Cse 373 April 26th – Exam Review.
November 1st – Exam Review
Efficiency add remove find unsorted array O(1) O(n) sorted array
Data Structures and Algorithms
Lecture 3: Working with Data Structures
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Road Map CS Concepts Data Structures Java Language Java Collections
structures and their relationships." - Linus Torvalds
CSE 326: Data Structures: Midterm Review
Introduction to Hash Tables
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Data Structures and Algorithms
Data Structures and Algorithms
Lecture 3: Queues, Testing, and Working with Code
Building Java Programs
Data Structures and Algorithms
Hashing CS2110.
Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Chapter 21 Hashing: Implementing Dictionaries and Sets
B-Tree Insertions, Intro to Heaps
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Data Structures and Algorithms
Lecture 5: Master Theorem, Maps, and Iterators
slides created by Marty Stepp and Hélène Martin
CSE 373: Data Structures and Algorithms
slides adapted from Marty Stepp and Hélène Martin
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
CSE 143 Lecture 25 Set ADT implementation; hashing read 11.2
Lecture 9: Self Balancing Trees
CSE 373 Separate chaining; hash codes; hash maps
Lecture 3: Maps and Iterators
Lecture 14: Midterm Review
Ch Hash Tables Array or linked list Binary search trees
slides created by Marty Stepp
Lecture 4: Introduction to Code Analysis
Hashing based on slides by Marty Stepp
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
slides created by Marty Stepp and Hélène Martin
Lecture 3: Maps and Iterators
Lecture 10: BST and AVL Trees
Lecture 14: Midterm Review
Lecture 9: Intro to Trees
Instructor: Dr. Michael Geiger Spring 2019 Lecture 34: Exam 3 Preview
CS 240 – Advanced Programming Concepts
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
structures and their relationships." - Linus Torvalds
Lecture 16: Midterm recap + Heaps ii
Sets and Maps Chapter 7 CS 225.
Week 6 - Monday CS221.
Data Structures and Algorithms I
Presentation transcript:

Implementing Hash and AVL Data Structures and Algorithms CSE 373 SP 18 - Kasey Champion

Warm Up CSE 373 SP 18 - Kasey Champion

Announcements 1. Go look at your HW 1 scores, seems a lot are missing If you got 0/5 for check style, you can get those points back If you got 0/12 for delete tests, your tests didn’t pass on working input Regrade policy: when resubmitted you can earn up to ½ missed points back 3. Must use same partners for part 2 of project Can pick new partners for next project EXTREMELY HIGH overlap between those working alone and late submitted projects 4. Kasey is presenting the “No BS CS Career Talk” for 14X on Thursday April 19th 4:30-5:20 in Gug 220 It’s a good time, come hang out CSE 373 SP 18 - Kasey Champion

Coming Up Monday Wednesday Thursday Friday 4/16 Lecture: Open Addressing in Hash Tables 4/18 Lecture: Implementing AVL Trees and Hash Tables 4/19 Section: AVL Trees and Hash Tables 4/20 Lecture: How Memory Works HW2 PT2 due HW3: Midterm Review assigned 4/23 Lecture: B-Trees 4/25 Lecture: Midterm Review 4/26 Section: Midterm Review 4/27 Midterm HW3: Midterm Review due TA Lead Review Session: TBA CSE 373 SP 18 - Kasey Champion

What’s going to be on the Midterm? ADTs and data structures Difference between an ADT and a data structure. Stacks, queues, lists, dictionaries: common implementations, runtimes, and when to use them. Iterators: what they are, how to implement basic ones (e.g. for array lists and linked lists). Asymptotic analysis Big-O, Big-Omega, and Big-Theta. Finding c and n0 to show that one function is in Big-O, Big-Omega, or Big-Theta of another Modeling runtime of a piece of code as a function possibly including a summation or a recurrence. Understand the difference between best-case, average-case, and worst-case runtime. Trees How to implement and manipulate trees including Binary Search and AVL types Runtimes for tree operations. Performing AVL rotations when inserting values Hash tables Closed vs open addressing. Collision resolution: separate chaining, linear probing, quadratic probing, double hashing. Basics of good hash function design. Load factor. Runtimes (best, average, and worst-case). Testing How to construct different test cases Reading and evaluating code to debug NOT on the exam Java generics and Java interfaces JUnit Java syntax Finding the closed form of summations and recurrences CSE 373 SP 18 - Kasey Champion

Implementing a Dictionary Dictionary ADT Add pair to collection Count of data pairs state behavior Set of Key, Value pairs Keys must be unique! No required order Get value for given key Change value for given key Remove data pair from collection public interface Dictionary { void put(key, value) unspecified state behavior value get(key) void set(key, value) void remove(key) HashMap<K, V> put() pair into array based on hash - Resize when appropriate Pair<K, V>[] LinkedList<E>[] size state behavior Data[] get() value from array index based given key’s hash set() update value in pair for given key’s hash to array index remove() take data out of array TreeMap<K, V> put() add node for new pair in correct location - Balance when appropriate state behavior overallRoot<K,V> get() value based on node location in tree set() update value in pair for given key remove() delete given node - replace with appropriate existing node CSE 373 SP 18 - Kasey Champion

Implementing Hash Map HashMap<K, V> ListNode<K, V> put() pair into array based on hash - Resize when appropriate LinkedList<E>[] size state behavior get() value from array index based given key’s hash set() update value in pair for given key’s hash to array index remove() take data out of array LinkedList<E> Add() add a new node that stores Key and Value to list ListNode<K, V> front state behavior get() return value from node with given key remove() deletes node with given key from list set() changes value in node with given key Contains() is the given key stored in list iterator() returns an iterator to move over list ListNode<K, V> Construct a new Node ListNode<K, V> next state behavior K key V value CSE 373 SP 18 - Kasey Champion

Implementing a Hash Map HashMap<K, V> LinkedList<E>[] size state behavior void put(key, value) value get(key) void set(key, value) void remove(key) LinkedList<E> void add(key, value) ListNode<K, V> front state behavior value get(key) void remove(key) void set(key, value) boolean contains(key) iterator<E> iterator() Implementing a Hash Map v get(k key) { bucketAddress = get hash for key % table size bucketList = data[bucketAddress] loop (bucketList) { if (this node’s key is what I am looking for) return this node’s value } return not found :( ListNode<K, V> Construct a new Node ListNode<K, V> next state behavior K key V value void put(k key, v value) { create new Node bucketAddress = get hash for key % table size bucketList = data[bucketAddress] loop(bucketList) if (this node’s key is what I am trying to add) replace this node with new pair stop work if (load factor is about 1) increase array capacity to next prime number rehash existing values into new array add node to bucket update size } CSE 373 SP 18 - Kasey Champion

Implementing Tree Map TreeMap<K, V> state behavior put() add node for new pair in correct location - Balance when appropriate state behavior overallRoot<K,V> get() value based on node location in tree set() update value in pair for given key remove() delete given node - replace with appropriate existing node ListNode<K, V> Construct a new Node ListNode<K, V> left state behavior K key V value ListNode<K, V> right int height CSE 373 SP 18 - Kasey Champion

Implementing Tree Map TreeMap<K, V> ListNode<K, V> state behavior overallRoot<K,V> Implementing Tree Map v get(k key) { start at top of tree } ListNode<K, V> getHelper(key, Node) { if(node is null) data isn’t in collection if data at current node > what I’m looking for go left if data at current node < what I’m looking for go right else found it! void put(key, value) value get(key) void set(key, value) void remove(key) ListNode<K, V> Construct a new Node ListNode<K, V> left state behavior K key V value ListNode<K, V> right int height CSE 373 SP 18 - Kasey Champion