Announcements. Today s topic: Hashing (Ch. 10) Next topic: Graphs. Break around 11:45am

Size: px
Start display at page:

Download "Announcements. Today s topic: Hashing (Ch. 10) Next topic: Graphs. Break around 11:45am"

Transcription

1 Announcements Today s topic: Hashing (Ch. 10) Next topic: Graphs Break around 11:45am 1

2 Container structures so far Array lists O(1) access O(n) insertion/deletion (average case), better at end Linked lists O(n) access O(n) insertion/deletion (average case), better at front and back Binary search trees O(log n) access if balanced O(log n) insertion/deletion if balanced Heaps O(1) access of min/max O(log n) insertion O(log n) deletion (average case) Can we do even better? 2

3 Sets set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains) The client doesn't think of a set as having indices; we just add things to the set in general and don't worry about order set.contains("to") set.contains("be") "the" "if" "of" "to" "down" "from" "by" "she" "in" "you" "why" "him" true false set 3

4 IntSet ADT interface Let's think about how to write an implementation of a set. To simplify the problem, we only store ints in our set for now. As is (usually) done in the Java Collections Framework, we will define sets as an ADT by creating a Set interface. Core operations are: add, contains, remove. public interface IntSet { void add(int value); boolean contains(int value); void clear(); boolean isempty(); void remove(int value); int size(); 4

5 BST as a set We can implement a set as a binary search tree. O(log n) performance for: add contains Remove root But there are other ways to implement a set... perhaps with better performance. Is there a way to use an array s fast, O(1), access? 5

6 Unfilled array set? Consider storing a set in an unfilled array. It doesn't really matter what order the elements appear in a set, so long as they can be added and searched quickly. What would make a good ordering for the elements? If we store them in the next available index, as in a list,... set.add(9); set.add(23); set.add(8); set.add(-3); set.add(49); set.add(12); How efficient is add? contains? remove? O(1), O(n), O(n) index value size 6 6

7 Sorted array set? Suppose we store the elements in an unfilled array, but in sorted order rather than order of insertion. set.add(9); set.add(23); set.add(8); set.add(-3); set.add(49); set.add(12); index value size 6 How efficient is add? contains? remove? O(n), O(log n), O(n) 7

8 A strange idea Silly idea: When client adds value i, store it at index i in the array. Would this work? Problems/drawbacks of this approach? How to work around them? set.add(7); set.add(1); set.add(9);... set.add(18); set.add(12); index value size 3 index value size 5 8

9 Hashing Hash: To map a large domain of values to a smaller fixed domain. Typically, mapping a set of elements to integer indices in an array. Idea: Store any given element value in a particular predictable index. That way, adding/removing/looking for it are constant-time (O(1)). hash table: An array that stores elements via hashing. Hash function: An algorithm that maps values to indices. hash code: The output of a hash function for a given value. In previous slide, our "hash function" was: hash(i) i Potentially requires a large array. Doesn't work for negative numbers. Array could be very sparse, mostly empty (memory waste). 9

10 Hashing overview element hash() hash table (array, M buckets) hash code 3 (integer index) The hash function, hash(), maps a range of elements of arbitrary type into an integer range [0, M-1]. M-1 10

11 Improved hash function To deal with negative numbers: hash(i) abs(i) To deal with large numbers: hash(i) abs(i) % length set.add(37); // abs(37) % 10 == 7 set.add(-2); // abs(-2) % 10 == 2 set.add(49); // abs(49) % 10 == 9 index value size 3 // inside HashIntSet class private int hash(int i) { return Math.abs(i) % elements.length; 11

12 Sketch of implementation public class HashIntSet implements IntSet { private int[] elements; // the hash table... public void add(int value) { elements[hash(value)] = value; public boolean contains(int value) { return elements[hash(value)] == value; public void remove(int value) { elements[hash(value)] = 0; Runtime of add, contains, and remove: O(1) Are there any problems with this approach? 12

13 Hash function In general, any function that maps from the space of elements to the space of array indices is a valid hash function but a good hash function spreads the indices out over the entire hash table (array). A good hash function also tries to avoid collisions - multiple elements having the same index in the hash table. Uniform hashing assumption: Hashing is most efficient when index values spread throughout the table 13

14 Collisions Collision: When hash function maps 2 values to same index. set.add(11); set.add(49); set.add(24); set.add(37); set.add(54); // collides with 24! index value size 5 Collision resolution: An algorithm for fixing collisions Probing Separate chaining etc. 14

15 Probing Probing: Resolving a collision by moving to another index. Linear probing: Moves to the next available index (wraps if needed). set.add(11); set.add(49); set.add(24); set.add(37); set.add(54); // collides with 24; must probe index value size 5 variation: quadratic probing moves increasingly far away: +1, +4, +9,... 15

16 Implementing HashIntSet Let s implement an int set using a hash table with linear probing. For simplicity, assume that the set cannot store 0s for now. public class HashIntSet implements IntSet { private int[] elements; private int size; // constructs new empty set public HashIntSet() { elements = new int[10]; size = 0; // hash function maps values to indices private int hash(int value) { return Math.abs(value) % elements.length;... 16

17 The add operation How do we add an element to the hash table? Use the hash function to find the proper bucket index. If we see a 0, put it there, i.e., 0 means an available slot. If not, move forward until we find an empty (0) index to store it. If we see that the value is already in the table, don't re-add it. set.add(54); set.add(14); // client code index value size 6 17

18 Implementing add How do we add an element to the hash table? public void add(int value) { int h = hash(value); while (elements[h]!= 0 && elements[h]!= value) { // Linear probing h = (h + 1) % elements.length; // for empty slot. if (elements[h]!= value) { // Avoid duplicates. elements[h] = value; // Add it here. size++; index value size 5 18

19 The contains operation How do we search for an element in the hash table? Use the hash function to find the proper bucket index. Loop forward until we either find the value, or an empty index (0). If find the value, it is contained (true). If we find 0, it is not (false). We assume that the table is never full. set.contains(24) set.contains(14) set.contains(35) // true // true // false index value size 6 19

20 Implementing contains public boolean contains(int value) { int h = hash(value); while (elements[h]!= 0) { if (elements[h] == value) { return true; h = (h + 1) % elements.length; return false; // Linear probing // to search // not found index value size 5 20

21 The remove operation We cannot remove by simply zeroing out an element: set.remove(54); // set index 5 to 0 set.contains(14) // false??? oops index value size 5 Instead, we replace it by a special "removed" placeholder value (can be re-used on add, but keep searching on contains) index value XX size 5 21

22 Implementing remove public void remove(int value) { int h = hash(value); while (elements[h]!= 0 && elements[h]!= value) { h = (h + 1) % elements.length; if (elements[h] == value) { elements[h] = -999; // "removed" flag value size--; index value size 5 set.remove(54); set.remove(11); set.remove(34); // client code 22

23 Patching add, contains private static final int REMOVED = -999; // add needs patching. public void add(int value) { int h = hash(value); while (elements[h]!= 0 && elements[h]!= value && elements[h]!= REMOVED) { h = (h + 1) % elements.length; if (elements[h]!= value) { elements[h] = value; size++; // contains does not need patching; // it should keep going on a -999, which it already does public boolean contains(int value) { int h = hash(value); while (elements[h]!= 0 && elements[h]!= value) { h = (h + 1) % elements.length; return elements[h] == value; 23

24 Problem: full array Clustering: Clumps of elements at neighboring indexes. Slows down the hash table lookup; you must loop through them. set.add(11); set.add(49); set.add(24); set.add(37); set.add(54); // collides with 24 set.add(14); // collides with 24, then 54 set.add(86); // collides with 14, then 37 index value size 0 Where does each value go in the array? How many indices must be examined to answer contains(94)? What will happen if the array completely fills up? 24

25 Rehashing Rehash: Using a larger array when the table is too full. Cannot simply copy the old array to a new one. (Why not?) Load factor: ratio of (# of elements ) / (hash table length) Many collections rehash when load factor.75 index value size 8 index value size 8 25

26 Hash table sizes Can use prime numbers as hash table sizes to reduce collisions. Also improves spread / reduces clustering on rehash. set.add(11); // 11 % 13 == 11 set.add(39); // 39 % 13 == 0 set.add(21); // 21 % 13 == 8 set.add(29); // 29 % 13 == 3 set.add(71); // 81 % 13 == 6 set.add(41); // 41 % 13 == 2 set.add(101); // 101 % 13 == 10 index value size 7 Google: Why setting Hash Table length to a Prime Number is a good practice? 26

27 Iterator for a hash table How would you implement an iterator for a hash table using linear probing, e.g., HashIntSet? And also for one with separate chaining (next page)? How would we implement tostring on our HashIntSet? index value size 5 System.out.println(set); // [11, 24, 54, 37, 49] 27

28 Separate chaining Separate chaining: Solving collisions by storing a list at each index. add/contains/remove must traverse lists, but the lists are short impossible to "run out" of indices, unlike with probing. index value private class Node { public int data; public Node next;... Will see an alternative approach to implement chains later in MyHashMap.java Iterator for one with separate chaining?

29 Implementing HashIntSet Let s implement a hash set of ints using separate chaining. public class HashIntSet implements IntSet { // array of linked lists; // elements[i] = front of list #i (null if empty) private Node[] elements; private int size; // constructs new empty set public HashIntSet() { elements = new Node[10]; size = 0; // hash function maps values to indexes private int hash(int value) { return Math.abs(value) % elements.length;... 29

30 The add operation How do we add an element to the hash table? When you want to modify a linked list, you must either change the list s front reference, or the next field of a node in the list. Where in the list should we add the new element? Must make sure to avoid duplicates. index value set.add(24); new node

31 Implementing add public void add(int value) { if (!contains(value)) { int h = hash(value); // add to front Node newnode = new Node(value); // of list #h newnode.next = elements[h]; elements[h] = newnode; size++; 31

32 The contains operation How do we search for an element in the hash table? Must loop through the linked list for the appropriate hash index, looking for the desired value. index value set.contains(14) // true set.contains(84) // false set.contains(53) // false

33 Implementing contains public boolean contains(int value) { Node current = elements[hash(value)]; while (current!= null) { if (current.data == value) { return true; current = current.next; return false; 33

34 The remove operation How do we remove an element from the hash table? Cases to consider: front (24), non-front (14), not found (94), null (32) To remove a node from a linked list, you must either change the list's front reference, or the next field of the previous node in the list. index value set.remove(54); current

35 Implementing remove public void remove(int value) { int h = hash(value); if (elements[h]!= null && elements[h].data == value) { elements[h] = elements[h].next; // front case size--; else { Node current = elements[h]; // non-front case while (current!= null && current.next!= null) { if (current.next.data == value) { current.next = current.next.next; size--; return; current = current.next; 35

36 Rehashing with chaining Separate chaining handles rehashing similarly to linear probing. Loop over the list in each hash bucket; re-add each element. index value index value

37 Hash set of objects public class HashSet<E> implements Set<E> {... private class Node { public E data; public Node next; It is easy to hash an integer i (use index abs(i) % length ). How can we hash other types of values (such as objects)? 37

38 The hashcode method in Java All Java objects contain the following method (in Object): public int hashcode(); Returns an integer hash code for this object. We can call hashcode on any object to find its preferred index. HashSet, HashMap, and the other built-in "hash" collections call hashcode internally on their elements to store the data. We can modify our set s hash function to be the following: private int hash(e e) { return Math.abs(e.hashCode()) % elements.length; 38

39 Hash tables in Java HashTable class stores key/value pairs does not allow null for either key or value older, slower class (thread-safe, synchronized) HashSet class implements Set interface, internal storage container that is a hash table fast (unsynchronized) cf. TreeSet class, internal storage container is a Red Black Tree HashMap class Implements Map interface, internal storage container for keys is a hash table allows null for key or value fast (unsynchronized) cf. TreeMap class 39

40 Maps Also known as: table, search table, dictionary, associative array, or associative container A data structure optimized for a very specific kind of search / access with a bag we access by asking "is X present" with a list we access by asking "give me item number X" with a queue we access by asking "give me the item that has been in the collection the longest." In a map we access by asking "give me the value associated with this key." 40

41 Keys and values Dictionary analogy: The key in a dictionary is a word: foo The value in a dictionary is the definition: First on the standard list of metasyntactic variables used in syntax examples A key and its associated value form a pair that is stored in a map To retrieve a value the key for that value must be supplied A List can be viewed as a Map with integer keys (indices) Keys must be unique, meaning a given key can only represent one value but one value may be represented by multiple keys 41

42 Implementing a HashMap A hash map is like a set where the nodes store key/value pairs: public class HashMap<K, V> implements Map<K, V> {... index value // key value map.put("marty", 14); map.put("jeff", 21); map.put("kasey", 20); map.put("stef", 35); "Stef" 35 "Marty" 14 "Jeff" 21 "Kasey" 20 Must modify your Node class to store a key and a value 42

43 Map ADT interface Let s think about how to write our own implementation of a map. As is (usually) done in the Java Collections Framework, we will define map as an ADT by creating a Map interface. Core operations: put (add), get, containskey, remove public interface Map<K, V> { void clear(); boolean containskey(k key); V get(k key); boolean isempty(); void put(k key, V value); void remove(k key); int size(); 43

44 HashMap vs. HashSet The hashing is always done on the keys, not the values. The contains method is now containskey; and in remove, you search for a node whose key matches a given key. The add method is now put; if the given key is already there, you must replace its old value with the new one. map.put("bill", 66); // replace 49 with 66 index value "Stef" 35 "Marty" 14 "Jeff" 21 "Abby" 57 "Kasey" 20 "Bill"

45 Java s TreeMap Uses a Red - Black tree to implement a Map relies on the compareto method of the keys slower than HashMap keys stored in sorted order (cf. Are keys in HashMap in sorted order?) 45

46 Sample map problem Determine the frequency of words in a file. File f = new File(fileName); Scanner s = new Scanner(f); Map<String,Integer> counts = new HashMap<String,Integer>(); while(s.hasnext()){ String word = s.next(); if (!counts.containskey(word)) counts.put(word, 1); else counts.put(word, counts.get(word) + 1); 46

47 Implementing hashcode You can write your own hashcode methods in classes you write. All classes come with a default version based on memory address. Your overridden version should somehow "add up" the object's state. Often you scale/multiply parts of the result to distribute the results. public class Point { private int x; private int y;... public int hashcode() { // better than just returning (x + y); // spreads out numbers, fewer collisions return 137 * x + 23 * y; 47

48 Good hashcode behavior A well-written hashcode method should behave: Consistently with itself (must produce same results on each call): o.hashcode() == o.hashcode(), if o's state doesn't change Consistently with equality: a.equals(b) must imply a.hashcode() == b.hashcode(),!a.equals(b) does NOT necessarily imply that a.hashcode()!= b.hashcode() (why not?) When a class has an equals or hashcode, it should have both. Good distribution of hash codes: For a large set of objects with distinct states, they will generally return unique hash codes rather than all colliding into the same hash bucket. 48

49 Example: String hashcode The hashcode function inside a String class looks like this: public int hashcode() { int hash = 0; for (int i = 0; i < this.length(); i++) { hash = 31 * hash + this.charat(i); return hash; As with any general hashing function, collisions are possible. Example: "Ea" and "FB" have the same hash value. Early versions of Java examined only the first 16 characters. For some common data this led to poor hash table performance. 49

50 hashcode tricks If one of your object s fields is an object, call its hashcode: public int hashcode() { // Student return 531 * firstname.hashcode() +...; To incorporate a double or boolean, use the hashcode method from the Double or Boolean wrapper classes: public int hashcode() { // BankAccount return 37 * Double.valueOf(balance).hashCode() + Boolean.valueOf(isCheckingAccount).hashCode(); Guava includes an Objects.hashCode(...) method that takes any number of values and combines them into one hash code. public int hashcode() { // BankAccount return Objects.hashCode(name, id, balance); 50

51 Hash tables vs. BST vs. heaps on search BSTs: has complete ordering information Heaps: has incomplete ordering information Hash tables: has no order information 51

52 Example: using hash tables See UseHashSet.java, Student.java, StudentReader.java See UseHashMap.java See Hash.java 52

53 Example: implementing hash tables Using java.util.linkedlist as a chain in each bucket See MyHashSet.java See MyHashMap.java 53

54 Next topic Graphs 54

Announcements. Container structures so far. IntSet ADT interface. Sets. Today s topic: Hashing (Ch. 10) Next topic: Graphs. Break around 11:45am

Announcements. Container structures so far. IntSet ADT interface. Sets. Today s topic: Hashing (Ch. 10) Next topic: Graphs. Break around 11:45am Announcements Today s topic: Hashing (Ch. 10) Next topic: Graphs Break around 11:45am Container structures so far Array lists O(1) access O(n) insertion/deletion (average case), better at end Linked lists

More information

CSE 143. Lecture 28: Hashing

CSE 143. Lecture 28: Hashing CSE 143 Lecture 28: Hashing SearchTree as a set We implemented a class SearchTree to store a BST of ints: Our BST is essentially a set of integers. Operations we support: add contains remove... -3 overallroot

More information

Building Java Programs

Building Java Programs Building Java Programs Generics, hashing reading: 18.1 2 3 Wednesday Notecards Difference between int[] and List? How does HashSet get sorted? 4 Hashing hash: To map a value to an integer index.

More information

Review. CSE 143 Java. A Magical Strategy. Hash Function Example. Want to implement Sets of objects Want fast contains( ), add( )

Review. CSE 143 Java. A Magical Strategy. Hash Function Example. Want to implement Sets of objects Want fast contains( ), add( ) Review CSE 143 Java Hashing Want to implement Sets of objects Want fast contains( ), add( ) One strategy: a sorted list OK contains( ): use binary search Slow add( ): have to maintain list in sorted order

More information

Hash tables. hashing -- idea collision resolution. hash function Java hashcode() for HashMap and HashSet big-o time bounds applications

Hash tables. hashing -- idea collision resolution. hash function Java hashcode() for HashMap and HashSet big-o time bounds applications hashing -- idea collision resolution Hash tables closed addressing (chaining) open addressing techniques hash function Java hashcode() for HashMap and HashSet big-o time bounds applications Hash tables

More information

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS T E W H A R E W Ā N A N G A O T E Student ID:....................... Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2015 TRIMESTER 2 COMP103 INTRODUCTION

More information

Hash table basics mod 83 ate. ate. hashcode()

Hash table basics mod 83 ate. ate. hashcode() Hash table basics ate hashcode() 82 83 84 48594983 mod 83 ate Reminder from syllabus: EditorTrees worth 10% of term grade See schedule page Exam 2 moved to Friday after break. Short pop quiz over AVL rotations

More information

Data Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada

Data Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada CS102 Hash Tables Prof. Tejada 1 Vectors, Linked Lists, Stack, Queues, Deques Can t provide fast insertion/removal and fast lookup at the same time The Limitations of Data Structure Binary Search Trees,

More information

Hash table basics mod 83 ate. ate

Hash table basics mod 83 ate. ate Hash table basics After today, you should be able to explain how hash tables perform insertion in amortized O(1) time given enough space ate hashcode() 82 83 84 48594983 mod 83 ate 1. Section 2: 15+ min

More information

CSC 321: Data Structures. Fall 2016

CSC 321: Data Structures. Fall 2016 CSC : Data Structures Fall 6 Hash tables HashSet & HashMap hash table, hash function collisions Ø linear probing, lazy deletion, primary clustering Ø quadratic probing, rehashing Ø chaining HashSet & HashMap

More information

csci 210: Data Structures Maps and Hash Tables

csci 210: Data Structures Maps and Hash Tables csci 210: Data Structures Maps and Hash Tables Summary Topics the Map ADT Map vs Dictionary implementation of Map: hash tables READING: GT textbook chapter 9.1 and 9.2 Map ADT A Map is an abstract data

More information

Introducing Hashing. Chapter 21. Copyright 2012 by Pearson Education, Inc. All rights reserved

Introducing Hashing. Chapter 21. Copyright 2012 by Pearson Education, Inc. All rights reserved Introducing Hashing Chapter 21 Contents What Is Hashing? Hash Functions Computing Hash Codes Compressing a Hash Code into an Index for the Hash Table A demo of hashing (after) ARRAY insert hash index =

More information

Lecture 10: Introduction to Hash Tables

Lecture 10: Introduction to Hash Tables Lecture 10: Introduction to Hash Tables CSE 373: Data Structures and Algorithms CSE 373 19 WI - KASEY CHAMPION 1 Warm Up CSE 373 SP 18 - KASEY CHAMPION 2 Administrivia HW 2 part 1 grades went out HW 2

More information

Hash Open Indexing. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1

Hash Open Indexing. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Hash Open Indexing Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up Consider a StringDictionary using separate chaining with an internal capacity of 10. Assume our buckets are implemented

More information

Hash table basics. ate à. à à mod à 83

Hash table basics. ate à. à à mod à 83 Hash table basics After today, you should be able to explain how hash tables perform insertion in amortized O(1) time given enough space ate à hashcode() à 48594983à mod à 83 82 83 ate 84 } EditorTrees

More information

Introduction hashing: a technique used for storing and retrieving information as quickly as possible.

Introduction hashing: a technique used for storing and retrieving information as quickly as possible. Lecture IX: Hashing Introduction hashing: a technique used for storing and retrieving information as quickly as possible. used to perform optimal searches and is useful in implementing symbol tables. Why

More information

Hash table basics mod 83 ate. ate

Hash table basics mod 83 ate. ate Hash table basics After today, you should be able to explain how hash tables perform insertion in amortized O(1) time given enough space ate hashcode() 82 83 84 48594983 mod 83 ate Topics: weeks 1-6 Reading,

More information

Standard ADTs. Lecture 19 CS2110 Summer 2009

Standard ADTs. Lecture 19 CS2110 Summer 2009 Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2

More information

Abstract data types (again) Announcements. Example ADT an integer bag (next) The Java Collections Framework

Abstract data types (again) Announcements. Example ADT an integer bag (next) The Java Collections Framework Announcements Abstract data types (again) PS 5 ready Tutoring schedule updated with more hours Today s topic: The Java Collections Framework Reading: Section 7.5 An ADT is a model of a collection of data

More information

EXAMINATIONS 2016 TRIMESTER 2

EXAMINATIONS 2016 TRIMESTER 2 T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2016 TRIMESTER 2 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

More information

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 Trimester 2, MID-TERM TEST COMP103 Introduction

More information

CSC 321: Data Structures. Fall 2017

CSC 321: Data Structures. Fall 2017 CSC : Data Structures Fall 7 Hash tables HashSet & HashMap hash table, hash function collisions Ø linear probing, lazy deletion, clustering, rehashing Ø chaining Java hashcode method HW6: finite state

More information

Implementing Hash and AVL

Implementing Hash and AVL Implementing Hash and AVL Data Structures and 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

More information

EXAMINATIONS 2017 TRIMESTER 2

EXAMINATIONS 2017 TRIMESTER 2 T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2017 TRIMESTER 2 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

More information

Announcements. Submit Prelim 2 conflicts by Thursday night A6 is due Nov 7 (tomorrow!)

Announcements. Submit Prelim 2 conflicts by Thursday night A6 is due Nov 7 (tomorrow!) HASHING CS2110 Announcements 2 Submit Prelim 2 conflicts by Thursday night A6 is due Nov 7 (tomorrow!) Ideal Data Structure 3 Data Structure add(val x) get(int i) contains(val x) ArrayList 2 1 3 0!(#)!(1)!(#)

More information

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 MID YEAR COMP103 Introduction to Data

More information

Java HashMap Interview Questions

Java HashMap Interview Questions Java HashMap Interview Questions codespaghetti.com/java-hashmap-interview-questions/ HashMap Java HashMap Interview Questions, Algorithms and Programs. Table of Contents: CHAPTER 1: Java HashMap Interview

More information

EXAMINATIONS 2012 MID YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2012 MID YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2012 MID YEAR COMP103 Introduction to Data

More information

Mapping Structures. Chapter An Example: Language Dictionaries

Mapping Structures. Chapter An Example: Language Dictionaries Chapter 11 Mapping Structures Some data exhibit a sequential relationship between elements. Other data exhibit a hierarchical relationship between elements. And yet, some data exhibit a mapping relationship

More information

Lecture 16. Reading: Weiss Ch. 5 CSE 100, UCSD: LEC 16. Page 1 of 40

Lecture 16. Reading: Weiss Ch. 5 CSE 100, UCSD: LEC 16. Page 1 of 40 Lecture 16 Hashing Hash table and hash function design Hash functions for integers and strings Collision resolution strategies: linear probing, double hashing, random hashing, separate chaining Hash table

More information

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum Table ADT and Sorting Algorithm topics continuing (or reviewing?) CS 24 curriculum A table ADT (a.k.a. Dictionary, Map) Table public interface: // Put information in the table, and a unique key to identify

More information

Hashing as a Dictionary Implementation

Hashing as a Dictionary Implementation Hashing as a Dictionary Implementation Chapter 22 Contents The Efficiency of Hashing The Load Factor The Cost of Open Addressing The Cost of Separate Chaining Rehashing Comparing Schemes for Collision

More information

27/04/2012. Objectives. Collection. Collections Framework. "Collection" Interface. Collection algorithm. Legacy collection

27/04/2012. Objectives. Collection. Collections Framework. Collection Interface. Collection algorithm. Legacy collection Objectives Collection Collections Framework Concrete collections Collection algorithm By Võ Văn Hải Faculty of Information Technologies Summer 2012 Legacy collection 1 2 2/27 Collections Framework "Collection"

More information

The dictionary problem

The dictionary problem 6 Hashing The dictionary problem Different approaches to the dictionary problem: previously: Structuring the set of currently stored keys: lists, trees, graphs,... structuring the complete universe of

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 37 April 22, 2016 Encapsulation & Hashing How is the Game Project going so far? 1. not started 2. got an idea 3. submitted design proposal 4. started

More information

Hash Tables. Gunnar Gotshalks. Maps 1

Hash Tables. Gunnar Gotshalks. Maps 1 Hash Tables Maps 1 Definition A hash table has the following components» An array called a table of size N» A mathematical function called a hash function that maps keys to valid array indices hash_function:

More information

Data Structures and Object-Oriented Design VIII. Spring 2014 Carola Wenk

Data Structures and Object-Oriented Design VIII. Spring 2014 Carola Wenk Data Structures and Object-Oriented Design VIII Spring 2014 Carola Wenk Collections and Maps The Collection interface is for storage and access, while a Map interface is geared towards associating keys

More information

Model Solutions. COMP 103: Test May, 2013

Model Solutions. COMP 103: Test May, 2013 Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Instructions Time allowed: 45 minutes

More information

Topic HashTable and Table ADT

Topic HashTable and Table ADT Topic HashTable and Table ADT Hashing, Hash Function & Hashtable Search, Insertion & Deletion of elements based on Keys So far, By comparing keys! Linear data structures Non-linear data structures Time

More information

CS 310: Maps and Sets and Trees

CS 310: Maps and Sets and Trees CS 310: Maps and Sets and Trees Chris Kauman Week 8-2 Logistics Oce hours Wednesday normal: 4:30-5:30pm Thursday 2-3pm special oce hours Reading Weiss Ch. 6 (Java Library Classes/Interfaces) 6.7 Sets,

More information

COMP 103 RECAP-TODAY. Hashing: collisions. Collisions: open hashing/buckets/chaining. Dealing with Collisions: Two approaches

COMP 103 RECAP-TODAY. Hashing: collisions. Collisions: open hashing/buckets/chaining. Dealing with Collisions: Two approaches COMP 103 2017-T1 Lecture 31 Hashing: collisions Marcus Frean, Lindsay Groves, Peter Andreae and Thomas Kuehne, VUW Lindsay Groves School of Engineering and Computer Science, Victoria University of Wellington

More information

Topic 10: The Java Collections Framework (and Iterators)

Topic 10: The Java Collections Framework (and Iterators) Topic 10: The Java Collections Framework (and Iterators) A set of interfaces and classes to help manage collections of data. Why study the Collections Framework? very useful in many different kinds of

More information

11/27/12. CS202 Fall 2012 Lecture 11/15. Hashing. What: WiCS CS Courses: Inside Scoop When: Monday, Nov 19th from 5-7pm Where: SEO 1000

11/27/12. CS202 Fall 2012 Lecture 11/15. Hashing. What: WiCS CS Courses: Inside Scoop When: Monday, Nov 19th from 5-7pm Where: SEO 1000 What: WiCS CS Courses: Inside Scoop When: Monday, Nov 19th from -pm Where: SEO 1 Having trouble figuring out what classes to take next semester? Wish you had information on what CS course to take when?

More information

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures Collections CSE 143 Java Collections Most programs need to store and access collections of data Collections are worth studying because... They are widely useful in programming They provide examples of

More information

HashTable CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Fall 2018

HashTable CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Fall 2018 HashTable CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Fall 2018 Acknowledgement The set of slides have used materials from the following resources Slides for textbook by Dr. Y.

More information

CSE100. Advanced Data Structures. Lecture 21. (Based on Paul Kube course materials)

CSE100. Advanced Data Structures. Lecture 21. (Based on Paul Kube course materials) CSE100 Advanced Data Structures Lecture 21 (Based on Paul Kube course materials) CSE 100 Collision resolution strategies: linear probing, double hashing, random hashing, separate chaining Hash table cost

More information

Announcements. Hash Functions. Hash Functions 4/17/18 HASHING

Announcements. Hash Functions. Hash Functions 4/17/18 HASHING Announcements Submit Prelim conflicts by tomorrow night A7 Due FRIDAY A8 will be released on Thursday HASHING CS110 Spring 018 Hash Functions Hash Functions 1 0 4 1 Requirements: 1) deterministic ) return

More information

Lecture 18. Collision Resolution

Lecture 18. Collision Resolution Lecture 18 Collision Resolution Introduction In this lesson we will discuss several collision resolution strategies. The key thing in hashing is to find an easy to compute hash function. However, collisions

More information

CS 310: Maps and Sets

CS 310: Maps and Sets CS 310: Maps and Sets Chris Kauffman Week 9-1 Logistics Goals Today HW2 Discussion Maps and Sets HW2 Discussion Milestones due Thu 7/6 Discuss AdditiveList Iterator Implementation O(1) Undo/Redo Reading

More information

Lecture 13: AVL Trees and Binary Heaps

Lecture 13: AVL Trees and Binary Heaps Data Structures Brett Bernstein Lecture 13: AVL Trees and Binary Heaps Review Exercises 1. ( ) Interview question: Given an array show how to shue it randomly so that any possible reordering is equally

More information

CSE 143 Lecture 14 AnagramSolver and Hashing

CSE 143 Lecture 14 AnagramSolver and Hashing CSE 143 Lecture 14 AnagramSolver and Hashing slides created by Ethan Apter http://www.cs.washington.edu/143/ Ada Lovelace (1815-1852) Ada Lovelace is considered the first computer programmer for her work

More information

Family Name:... Other Names:... ID Number:... Signature... Model Solutions. COMP 103: Test 1. 9th August, 2013

Family Name:... Other Names:... ID Number:... Signature... Model Solutions. COMP 103: Test 1. 9th August, 2013 Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Model Solutions COMP 103: Test

More information

1.00 Lecture 32. Hashing. Reading for next time: Big Java Motivation

1.00 Lecture 32. Hashing. Reading for next time: Big Java Motivation 1.00 Lecture 32 Hashing Reading for next time: Big Java 18.1-18.3 Motivation Can we search in better than O( lg n ) time, which is what a binary search tree provides? For example, the operation of a computer

More information

Linked lists (6.5, 16)

Linked lists (6.5, 16) Linked lists (6.5, 16) Linked lists Inserting and removing elements in the middle of a dynamic array takes O(n) time (though inserting at the end takes O(1) time) (and you can also delete from the middle

More information

Collections, Maps and Generics

Collections, Maps and Generics Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.

More information

Announcements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am

Announcements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am Announcements Midterm exam 2, Thursday, May 18 Closed book/notes but one sheet of paper allowed Covers up to stacks and queues Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps

More information

CIT-590 Final Exam. Name: Penn Key (Not ID number): If you write a number above, you will lose 1 point

CIT-590 Final Exam. Name: Penn Key (Not ID number): If you write a number above, you will lose 1 point 1 CIT-590 Final Exam Name: Penn Key (Not ID number): If you write a number above, you will lose 1 point Instructions: You will have two hours to complete this exam. If you finish in the last 15 minutes,

More information

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2 CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2 Prof. John Park Based on slides from previous iterations of this course Today s Topics Overview Uses and motivations of hash tables Major concerns with hash

More information

Priority Queue Sorting

Priority Queue Sorting Priority Queue Sorting We can use a priority queue to sort a list of comparable elements 1. Insert the elements one by one with a series of insert operations 2. Remove the elements in sorted order with

More information

CS2110: Software Development Methods. Maps and Sets in Java

CS2110: Software Development Methods. Maps and Sets in Java CS2110: Software Development Methods Maps and Sets in Java These slides are to help with the lab, Finding Your Way with Maps This lab uses Maps, and Sets too (but just a little). Readings from textbook:

More information

EXAMINATIONS 2012 Trimester 1, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2012 Trimester 1, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2012 Trimester 1, MID-TERM TEST COMP103 Introduction

More information

Abstract Data Types (ADTs) Queues & Priority Queues. Sets. Dictionaries. Stacks 6/15/2011

Abstract Data Types (ADTs) Queues & Priority Queues. Sets. Dictionaries. Stacks 6/15/2011 CS/ENGRD 110 Object-Oriented Programming and Data Structures Spring 011 Thorsten Joachims Lecture 16: Standard ADTs Abstract Data Types (ADTs) A method for achieving abstraction for data structures and

More information

Hierarchical data structures. Announcements. Motivation for trees. Tree overview

Hierarchical data structures. Announcements. Motivation for trees. Tree overview Announcements Midterm exam 2, Thursday, May 18 Closed book/notes but one sheet of paper allowed Covers up to stacks and queues Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps

More information

WITH SOLUTIONS!!! WARNING: THIS COPY CONTAINS SOLUTIONS!!! COMP103 Introduction to Data Structures and Algorithms

WITH SOLUTIONS!!! WARNING: THIS COPY CONTAINS SOLUTIONS!!! COMP103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2007 SUMMER TRIMESTER COMP103 Introduction

More information

Data Structures And Algorithms

Data Structures And Algorithms Data Structures And Algorithms Hashing Eng. Anis Nazer First Semester 2017-2018 Searching Search: find if a key exists in a given set Searching algorithms: linear (sequential) search binary search Search

More information

COM1020/COM6101: Further Java Programming

COM1020/COM6101: Further Java Programming (1/19) COM1020/COM6101: Further Java Programming AKA: Object-Oriented Programming, Advanced Java Programming http://www.dcs.shef.ac.uk/ sjr/com1020/ Lecture 7: Collections Accessed by Content Steve Renals

More information

CSC 321: Data Structures. Fall 2016

CSC 321: Data Structures. Fall 2016 CSC 321: Data Structures Fall 2016 Balanced and other trees balanced BSTs: AVL trees, red-black trees TreeSet & TreeMap implementations heaps priority queue implementation heap sort 1 Balancing trees recall:

More information

CSC 321: Data Structures. Fall 2017

CSC 321: Data Structures. Fall 2017 CSC 321: Data Structures Fall 2017 Balanced and other trees balanced BSTs: AVL trees, red-black trees TreeSet & TreeMap implementations heaps priority queue implementation heap sort 1 Balancing trees recall:

More information

HASH TABLES. Hash Tables Page 1

HASH TABLES. Hash Tables Page 1 HASH TABLES TABLE OF CONTENTS 1. Introduction to Hashing 2. Java Implementation of Linear Probing 3. Maurer s Quadratic Probing 4. Double Hashing 5. Separate Chaining 6. Hash Functions 7. Alphanumeric

More information

Fall 2017 Mentoring 9: October 23, Min-Heapify This. Level order, bubbling up. Level order, bubbling down. Reverse level order, bubbling up

Fall 2017 Mentoring 9: October 23, Min-Heapify This. Level order, bubbling up. Level order, bubbling down. Reverse level order, bubbling up CSM B Heaps & Hashing Fall 0 Mentoring : October 3, 0 Min-Heapify This. In general, there are 4 ways to heapify. Which ways actually work? Level order, bubbling up Level order, bubbling down Reverse level

More information

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

CSE373 Fall 2013, Second Midterm Examination November 15, 2013 CSE373 Fall 2013, Second Midterm Examination November 15, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please

More information

Hash Tables. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Data Dictionary Revisited

Hash Tables. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Data Dictionary Revisited Unit 9, Part 4 Hash Tables Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Data Dictionary Revisited We've considered several data structures that allow us to store and search for data

More information

Linked Lists. References and objects

Linked Lists. References and objects Linked Lists slides created by Marty Stepp http://www.cs.washington.edu/143/ Modified by Sarah Heckman Reading: RS Chapter 16 References and objects In Java, objects and arrays use reference semantics.

More information

EXAMINATIONS 2010 END YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2010 END YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2010 END YEAR COMP103 Introduction to Data

More information

Hashing Techniques. Material based on slides by George Bebis

Hashing Techniques. Material based on slides by George Bebis Hashing Techniques Material based on slides by George Bebis https://www.cse.unr.edu/~bebis/cs477/lect/hashing.ppt The Search Problem Find items with keys matching a given search key Given an array A, containing

More information

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 2. O(n) 2. [1 pt] What is the solution to the recurrence T(n) = T(n/2) + n, T(1)

More information

Hash Tables. Hashing Probing Separate Chaining Hash Function

Hash Tables. Hashing Probing Separate Chaining Hash Function Hash Tables Hashing Probing Separate Chaining Hash Function Introduction In Chapter 4 we saw: linear search O( n ) binary search O( log n ) Can we improve the search operation to achieve better than O(

More information

CSE 214 Computer Science II Searching

CSE 214 Computer Science II Searching CSE 214 Computer Science II Searching Fall 2017 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction Searching in a

More information

mith College Computer Science Sets and Hashing CSC212 Fall 2014 Dominique Thiébaut

mith College Computer Science Sets and Hashing CSC212 Fall 2014 Dominique Thiébaut mith College Computer Science Sets and Hashing CSC22 Fall 204 Dominique Thiébaut dthiebaut@smith.edu The Problem: Large amount of live tweets Want the list of all tweeters Each only listed once What data

More information

CS 10: Problem solving via Object Oriented Programming. Info Retrieval

CS 10: Problem solving via Object Oriented Programming. Info Retrieval CS 10: Problem solving via Object Oriented Programming Info Retrieval ADT Overview Descrip+on List Keep items stored in order Common use Grow to hold any number of items Implementa+on op+ons Java provided

More information

CS 3410 Ch 20 Hash Tables

CS 3410 Ch 20 Hash Tables CS 341 Ch 2 Hash Tables Sections 2.1-2.7 Pages 773-82 2.1 Basic Ideas 1. A hash table is a data structure that supports insert, remove, and find in constant time, but there is no order to the items stored.

More information

CMSC 132: Object-Oriented Programming II. Hash Tables

CMSC 132: Object-Oriented Programming II. Hash Tables CMSC 132: Object-Oriented Programming II Hash Tables CMSC 132 Summer 2017 1 Key Value Map Red Black Tree: O(Log n) BST: O(n) 2-3-4 Tree: O(log n) Can we do better? CMSC 132 Summer 2017 2 Hash Tables a

More information

More on Hashing: Collisions. See Chapter 20 of the text.

More on Hashing: Collisions. See Chapter 20 of the text. More on Hashing: Collisions See Chapter 20 of the text. Collisions Let's do an example -- add some people to a hash table of size 7. Name h = hash(name) h%7 Ben 66667 6 Bob 66965 3 Steven -1808493797-5

More information

CSC263 Week 5. Larry Zhang.

CSC263 Week 5. Larry Zhang. CSC263 Week 5 Larry Zhang http://goo.gl/forms/s9yie3597b Announcements PS3 marks out, class average 81.3% Assignment 1 due next week. Response to feedbacks -- tutorials We spent too much time on working

More information

HO #13 Fall 2015 Gary Chan. Hashing (N:12)

HO #13 Fall 2015 Gary Chan. Hashing (N:12) HO #13 Fall 2015 Gary Chan Hashing (N:12) Outline Motivation Hashing Algorithms and Improving the Hash Functions Collisions Strategies Open addressing and linear probing Separate chaining COMP2012H (Hashing)

More information

COMP 103 Introduction to Data Structures and Algorithms

COMP 103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:..................... EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data

More information

CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course

CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course Today s Topics Review Uses and motivations of hash tables Major concerns with hash tables Properties Hash function Hash

More information

Hash[ string key ] ==> integer value

Hash[ string key ] ==> integer value Hashing 1 Overview Hash[ string key ] ==> integer value Hash Table Data Structure : Use-case To support insertion, deletion and search in average-case constant time Assumption: Order of elements irrelevant

More information

CSE 373. Java Collection Framework. reading: Weiss Ch. 3, 4.8. slides created by Marty Stepp

CSE 373. Java Collection Framework. reading: Weiss Ch. 3, 4.8. slides created by Marty Stepp CSE 373 Java Collection Framework reading: Weiss Ch. 3, 4.8 slides created by Marty Stepp http://www.cs.washington.edu/373/ 1 Arrays array: An object that stores many values of the same type. element:

More information

Lecture 7: Efficient Collections via Hashing

Lecture 7: Efficient Collections via Hashing Lecture 7: Efficient Collections via Hashing These slides include material originally prepared by Dr. Ron Cytron, Dr. Jeremy Buhler, and Dr. Steve Cole. 1 Announcements Lab 6 due Friday Lab 7 out tomorrow

More information

HASH TABLES. Goal is to store elements k,v at index i = h k

HASH TABLES. Goal is to store elements k,v at index i = h k CH 9.2 : HASH TABLES 1 ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM JORY DENNY AND

More information

Model Solutions. COMP 103: Test April, 2013

Model Solutions. COMP 103: Test April, 2013 Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Instructions Time allowed: 40 minutes

More information

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 PRACTICE EXAM

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 PRACTICE EXAM T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 PRACTICE EXAM Time Allowed: TWO HOURS ********

More information

Depth-wise Hashing with Deep Hashing Structures. A two dimensional representation of a Deep Table

Depth-wise Hashing with Deep Hashing Structures. A two dimensional representation of a Deep Table Proceedings of Student Research Day, CSIS, Pace University, May 9th, 2003 Depth-wise Hashing with Deep Hashing Structures Edward Capriolo Abstract The objective of this research is to implement a variation

More information

Java Collections Framework reloaded

Java Collections Framework reloaded Java Collections Framework reloaded October 1, 2004 Java Collections - 2004-10-01 p. 1/23 Outline Interfaces Implementations Ordering Java 1.5 Java Collections - 2004-10-01 p. 2/23 Components Interfaces:

More information

CSE 143. Lecture 7: Linked List Basics reading: 16.2

CSE 143. Lecture 7: Linked List Basics reading: 16.2 CSE 143 Lecture 7: Linked List Basics reading: 16.2 References vs. objects variable = value; a variable (left side of = ) is an arrow (the base of an arrow) a value (right side of = ) is an object (a box;

More information

CSE 332: Data Structures & Parallelism Lecture 10:Hashing. Ruth Anderson Autumn 2018

CSE 332: Data Structures & Parallelism Lecture 10:Hashing. Ruth Anderson Autumn 2018 CSE 332: Data Structures & Parallelism Lecture 10:Hashing Ruth Anderson Autumn 2018 Today Dictionaries Hashing 10/19/2018 2 Motivating Hash Tables For dictionary with n key/value pairs insert find delete

More information

Dynamic Dictionaries. Operations: create insert find remove max/ min write out in sorted order. Only defined for object classes that are Comparable

Dynamic Dictionaries. Operations: create insert find remove max/ min write out in sorted order. Only defined for object classes that are Comparable Hashing Dynamic Dictionaries Operations: create insert find remove max/ min write out in sorted order Only defined for object classes that are Comparable Hash tables Operations: create insert find remove

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 37 April 28, 2014 TreeSet and HashSet Announcements Game project due Wednesday at midnight (HARD deadline) Check your grades online, should be up-

More information

CS61B Spring 2016 Guerrilla Section 6 Worksheet

CS61B Spring 2016 Guerrilla Section 6 Worksheet Spring 2016 5 May 2016 Directions: In groups of 4-5, work on the following exercises. Do not proceed to the next exercise until everyone in your group has the answer and understands why the answer is what

More information