implementing hash and
play

Implementing Hash and Data Structures and AVL Algorithms CSE 373 - PowerPoint PPT Presentation

Implementing Hash and Data Structures and AVL Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up CSE 373 SP 18 - KASEY CHAMPION 2 Announcements 1. Go look at your HW 1 scores, seems a lot are missing 2. Look at your HW 2 scores - If you


  1. Implementing Hash and Data Structures and AVL Algorithms CSE 373 SP 18 - KASEY CHAMPION 1

  2. Warm Up CSE 373 SP 18 - KASEY CHAMPION 2

  3. Announcements 1. Go look at your HW 1 scores, seems a lot are missing 2. Look at your HW 2 scores - 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 19 th 4:30-5:20 in Gug 220 - It’s a good time, come hang out CSE 373 SP 18 - KASEY CHAMPION 3

  4. Coming Up Monday day Wednesd esday ay Thur ursd sday ay Fr Friday ay 4/16 4/18 4/19 4/20 Lecture: Open Addressing Lecture: Implementing Section: AVL Trees and Lecture: How Memory in Hash Tables AVL Trees and Hash Tables Hash Tables Works HW2 PT2 due HW3: Midterm Review assigned 4/23 4/25 4/26 4/27 Midterm Lecture: B-Trees Lecture: Midterm Review Section: Midterm Review HW3: Midterm Review due TA Lead Review Session: TBA CSE 373 SP 18 - KASEY CHAMPION 4

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

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

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

  8. HashMap<K, V> LinkedList<E> Implementing a Hash Map state state LinkedList<E>[] ListNode<K, V> front size behavior ior behavior ior void add(key, value) void put(key, value) value get(key) v get(k key) { value get(key) void set(key, value) bucketAddress = get hash for key % table size void set(key, value) void remove(key) bucketList = data[bucketAddress] boolean contains(key) void remove(key) loop (bucketList) { if (this node’s key is what I am looking for) iterator<E> iterator() return this node’s value ListNode<K, V> } return not found :( state } K key V value void put(k key, v value) { ListNode<K, V> next create new Node behavior ior bucketAddress = get hash for key % table size Construct a new Node 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 8

  9. Implementing Tree Map TreeMap<K, V> ListNode<K, V> state state overallRoot<K,V> K key V value ListNode<K, V> left behavi avior or ListNode<K, V> right put() add node for new int height pair in correct location - Balance when appropriate behavi avior or get() value based on node Construct a new 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 9

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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend