300 likes | 312 Views
Learn about hashing, hash code design, addressing collisions, Hash Table & Red-Black Tree in Java, Graph concepts, DFS & BFS traversal using Stack & Queue.
E N D
CS 112 - Fall 2012, Lab 11 Haohan Zhu
CS 112 - Fall 2012, Lab 11 Hashing • Space & Time Tradeoff • O(n/m) for searching • Design Hashing Function • Key • Hash Code => Table Index • Deal with Collisions: • Separate Chaining • Linear Probing
CS 112 - Fall 2012, Lab 11 Hashing in Java • Hash Code • hashCode() is a method in Java • String: s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] • Integer: equal to the primitive int value • Double: (int)(v^(v>>>32)) • Always an int value
CS 112 - Fall 2012, Lab 11 R-B Tree and Hash Table in Java • Red-Black Tree: • TreeMap<K,V> • http://docs.oracle.com/javase/7/docs/api/java/util/TreeMap.html • Hash Table: • HashMap<K,V> • http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html
CS 112 - Fall 2012, Lab 11 Graph • Vertices: V • Edges: E • Representation • Adjacency list • Adjacency matrix • Adjacency sets
CS 112 - Fall 2012, Lab 11 Graph Traversal • Depth-first traversal • Stack • Breadth-first traversal • Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal DFS B E C A F D G Stack
CS 112 - Fall 2012, Lab 11 Graph Traversal DFS B E C A F A D G Stack
CS 112 - Fall 2012, Lab 11 Graph Traversal DFS B E C A F B A D G Stack
CS 112 - Fall 2012, Lab 11 Graph Traversal DFS B E C A F C B A D G Stack
CS 112 - Fall 2012, Lab 11 Graph Traversal DFS B E D C A F C B A D G Stack
CS 112 - Fall 2012, Lab 11 Graph Traversal DFS B E D C A F C B A D G Stack
CS 112 - Fall 2012, Lab 11 Graph Traversal DFS B E C A F E B A D G Stack
CS 112 - Fall 2012, Lab 11 Graph Traversal DFS B E F C A F E B A D G Stack
CS 112 - Fall 2012, Lab 11 Graph Traversal DFS B E G F C A F E B A D G Stack
CS 112 - Fall 2012, Lab 11 Graph Traversal DFS B E G F C A F E B A D G Stack
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E B C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E B D C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E B D G C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E B D G C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E D G C C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E D G C C A F E D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E D G C C A F E D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E G C E C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E C E F C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E C E F C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E E F C A F D G Queue
CS 112 - Fall 2012, Lab 11 Graph Traversal BFS B E F C A F D G Queue