This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: DivideAndConquer Data Structures IE170: Algorithms in Systems Engineering: Lecture 7 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University January 29, 2007 Jeff Linderoth IE170:Lecture 7 DivideAndConquer Data Structures Taking Stock Last Time Master Theorem Practice Some Sorting Algs Beginning of Java Collections Interfaces This Time Hashes Trees and Binary Search Trees More on Java Collections Interfaces lab == fun Jeff Linderoth IE170:Lecture 7 DivideAndConquer Data Structures Master Theorem The Java Collections Interfaces In the remainder of the class, we will be using the Java Collections Interface: http://java.sun.com/docs/books/ tutorial/collections/TOC.html Important: Most of what I will say only works if you set the code level to Java 5.0 in eclipse! Preferences, Java Compiler : Set this to 5.0 The interfaces form a hierarchy: Jeff Linderoth IE170:Lecture 7 DivideAndConquer Data Structures Master Theorem (A subset of) the Collections Interface public interface Collection<E> extends Iterable<E> { // Basic operations int size(); boolean isEmpty(); boolean contains(Object element); boolean add(E element); //optional boolean remove(Object element); //optional Iterator<E> iterator(); // Array operations Object toArray(); <T> T toArray(T a); } Jeff Linderoth IE170:Lecture 7 DivideAndConquer Data Structures Master Theorem Set A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction. The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited. Set is still an interface. There are 3 implementations of Set in Java. HashSet TreeSet LinkedHashSet Jeff Linderoth IE170:Lecture 7 DivideAndConquer Data Structures Master Theorem Hash? No, Cheech. A hash table is a data structure in which we can look up (or search) for an element efficiently. The expected time to search for an element in a has table in O (1) . (Worst case time in ( n )) . Think of a hash table as an array With a regular array, we find the element whose key is j in position j of the array. j = 17; val = a[j]; . This is called direct addressing and it takes O (1) on your regular ol random access computer. This form of direct addressing works when we can afford to have an array with one position for every possible key Jeff Linderoth IE170:Lecture 7 DivideAndConquer Data Structures Master Theorem More on Hash In a hash table the number of keys stored is small relative to the number of possible keys A hash table is an array. Given a key k , we dont use k as the index into the array rather, we have a hash function h , and we use h ( k ) as an index into the array....
View Full
Document
 Spring '07
 Ralphs
 Systems Engineering

Click to edit the document details