Data Structures Overview/Practice FixedLengthQueue Introduction to Markov Chaining Check Checkout out DataStruc DataStructures ures project from SVN project from SVN
� It's nothing new – Curt did it last term. Most Minesweeper work will be out of class. Most Markov work in-class
� Markov has usually been a pair assignment (and that's probably ideal). � But I don't want you to have to flit between two teams, so I am having you do Markov with your same team. � This is potentially dangerous: ◦ Be sure that you and the rest of your team understand everything that is going on. More details on Markov later today.
� Array List � Linked List � Stack � Queue � Set � Map Implementations for all of these are provided by the Java Collections Framework in the java.util package.
Operations Operations Array List Array List Linked List Linked List Provided Provided Efficiency Efficiency Efficiency Efficiency Random access O(1) O(n) Add/remove item O(n) O(1) Next Week we will discuss implementations. Q1
� A last-in, first-out (LIFO) data structure � Real-world stacks ◦ Plate dispensers in the cafeteria ◦ Pez dispenser � Some uses: ◦ Tracking paths through a maze ◦ Providing “unlimited undo” in an application Implemented by Operations Operations Efficiency Efficiency Stack , Provided Provided LinkedList , and Push item O(1) ArrayDeque in Pop item O(1) Java Q1
� A first-in, first-out (FIFO) data structure � Real-world queues Can implement as a ◦ Waiting line at the BMV (growable) "circular" array ◦ Waiting for customer http://maven.smith.edu/~str service at Dell.com einu/Teaching/Courses/112/ Applets/Queue/myApplet.ht � Some uses: ml ◦ Scheduling access to shared resource (e.g., printer) Operations Operations Efficiency Efficiency Implemented by Provided Provided LinkedList and ArrayDeque in Java Enqueue item O(1) Dequeue item O(1) Q1
� Unordered Unordered collections without duplicates without duplicates � Real-world sets But the Java TreeSet ◦ Students implementation of the Set ◦ Collectibles interface does keep its items � Some uses: ordered. ◦ Quickly checking if an item is in a collection Operations Operations HashSet ashSet TreeSet TreeSet Add/remove item O(1) O(log n) Contains? O(1) O(log n) Q1 Can hog space Sorts items!
� Associate keys keys with values values � Real-world “maps” ◦ Dictionary ◦ Phone book � Some uses: ◦ Associating student ID with transcript ◦ Associating name with high scores Operations Operations Hash ashMap ap TreeMap TreeMap Insert key-value pair O(1) O(lg n) Look up value for key O(1) O(lg n) Q1 Can hog space Sorts items by key!
� In the DataS DataStructures ructures Project � Do the ToDo items � Talk with someone else � Get help from instructor/TA � If you don't finish now, finish for HW.
Demonstration
� Input: a text file the skunk jumped over the stump the stump jumped over the skunk the skunk said the stump stunk and the stump said the skunk stunk � Output: a randomly generated list of words that is “like” the original input in a well-defined way
� Gather statistics on word patterns by building an appropriate data structure � Use the data structure to generate random text that follows the discovered patterns
Prefix Prefix Suffixes Suffixes � Input: a text file NONWORD the the skunk jumped over the the skunk jumped over the stum stump the skunk (4), the stump jumped over the the stump jumped over the skunk skunk stump (4) the skunk said the stump stunk the skunk said the stump stunk jumped, said, skunk and the stump said the skunk stunk and the stump said the skunk stunk stunk, the jumped over (2) over the (2) stump jumped, said, stunk, the said the (2) and, stunk NONWORD and the
� Input: a text file Prefix Prefix Suffixes Suffixes the skunk jumped over the the skunk jumped over the stum stump NW NW the the stump jumped over the the stump jumped over the skunk skunk NW the skunk the skunk said the stump stunk the skunk said the stump stunk jumped, the skunk and the stump said the skunk stunk and the stump said the skunk stunk said, the, stunk skunk jumped over jumped over the stump, over the skunk the, jumped, the stump stunk, said …
� n=2: � n=1: the skunk said the the skunk the skunk stump stunk and the jumped over the stump jumped over skunk stunk the skunk jumped over the skunk stunk � Note: it’s also possible to hit the the skunk stunk max before you hit the last nonword.
� For the prefixes? Prefix Prefix Suffixes Suffixes NW NW the � For the set of suffixes? NW the skunk jumped, the skunk said, the, � To relate them? stunk skunk jumped over jumped over the stump, over the skunk the, jumped, the stump stunk, said …
� The Markov and FixedLengthQueue projects are in your team repository: � Check them out.
� FixedLengthQueue: a specialized data structure, useful for Markov problem � Work with your team to implement it in the next 25 minutes or so. � Then Then read (twice) and begin digesting the Markov assignment � It's in several inter-linked documents � Discuss it with your team
Review HW description, Teams work on FixedLengthQueue/Markov for rest of class
Recommend
More recommend