+ All Categories
Home > Documents > CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in...

CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in...

Date post: 21-Dec-2015
Category:
View: 217 times
Download: 3 times
Share this document with a friend
Popular Tags:
14
CSSE221: Software Dev. Honors CSSE221: Software Dev. Honors Day 14 Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Questions on Cars, Trucks, Trains Cars, Trucks, Trains ? ? Homework 6 and Markov posted soon: Homework 6 and Markov posted soon: do team sign-up for Markov. do team sign-up for Markov.
Transcript
Page 1: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

CSSE221: Software Dev. Honors CSSE221: Software Dev. Honors Day 14Day 14 AnnouncementsAnnouncements

Pass in Homework 5 nowPass in Homework 5 now Questions on Questions on Cars, Trucks, TrainsCars, Trucks, Trains?? Homework 6 and Markov posted soon: Homework 6 and Markov posted soon:

do team sign-up for Markov.do team sign-up for Markov.

Page 2: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

This week: MarkovThis week: Markov

Monday:Monday: Stacks and QueuesStacks and Queues Sets, Maps, and PriorityQueuesSets, Maps, and PriorityQueues

Tuesday:Tuesday: Some pros and cons of various data Some pros and cons of various data

structuresstructures Brief example of file I/OBrief example of file I/O Introduction to Introduction to MarkovMarkov, a cool statistical , a cool statistical

text program with lots of data structurestext program with lots of data structures Thursday:Thursday:

Exam 1Exam 1

Page 3: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

StackStack LIFO (last-in-first-out).LIFO (last-in-first-out). Push [addBack] Push [addBack] pop [removeBack/“topAndPop”] pop [removeBack/“topAndPop”] peek [get(back--); ]peek [get(back--); ] Many applications, such as the Many applications, such as the

implementation of (recursive) implementation of (recursive) method calls and “undo” functions.method calls and “undo” functions.

push, pop, and peek are all constant-time O(1) operations.

Can be implemented using an ArrayList (last element in ArrayList is top of Stack) or a LinkedList (first element in LinkedList is top of stack). Which is better?

Page 4: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

QueueQueue Operations: offer [enqueue], poll [dequeue], peek.Operations: offer [enqueue], poll [dequeue], peek. FIFO (first-in-first-out).FIFO (first-in-first-out). Applications include simulations and operating systems.Applications include simulations and operating systems.

offer, poll, and peek are all constant-time operations.

Can be implemented using an ArrayList (treat positions as a circle) or a LinkedList (first element in LinkedList is front of queue, last element is rear of Queue). More details next slide.

Page 5: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

Array Array implementatimplementat

ion of a ion of a queuequeue

What if we run out of room?

Page 6: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

LinkedList LinkedList implementation of a implementation of a

queuequeue

Page 7: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

DemoDemo

Page 8: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

A tale of two interfaces: A tale of two interfaces: Set<E>…Set<E>…

A collection with A collection with no duplicatesno duplicates If If obj1obj1 and and obj2obj2 are both in the set, are both in the set,

then then obj1.equals(obj2)obj1.equals(obj2) returns returns falsefalse..

Subinterface: SortedSetSubinterface: SortedSet Not quite a mathematical set (no Not quite a mathematical set (no

intersection or union methods)intersection or union methods)

“Bob”, “Flo”, “Gary”, “Lisa”, “Marie”

Page 9: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

……and Map<K,V>and Map<K,V> An object that maps keys to An object that maps keys to

values. Duplicates? values. Duplicates? A map cannot contain A map cannot contain

duplicate keys; each key duplicate keys; each key can map to at most one can map to at most one value. value. V get(Object key)V get(Object key)

Multiple keys Multiple keys can can have the have the same value same value

Other operations: Other operations: put(K key, V value) put(K key, V value) containsKey(Object kcontainsKey(Object k

ey) ey) containsValue(Object containsValue(Object 

value)value) V remove(Object key)V remove(Object key)

123456789, 987654321, 102934857

“Bill Smith”, “Darla Clive”

NO

HashMap<Integer, String> map = new HashMap<Integer, String>();

map.put(123456789, “”Bill Smith”);map.put(987654321, “Darla Clive”);

Keys

Values

OK

Page 10: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

TreeSets and TreeMapsTreeSets and TreeMaps

……are are java.utiljava.util implementations of implementations of SortedSetSortedSet and and MapMap..

Ordered elements. Ordered elements. In a tree, average time is O(log n), In a tree, average time is O(log n),

and with complex algorithms, worst case and with complex algorithms, worst case can also be O(log N)can also be O(log N)

Also support taking ordered subsets Also support taking ordered subsets from head, tail, or interior of set or from head, tail, or interior of set or mapmap

More details in CSSE230…More details in CSSE230…

Page 11: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

HashSets and HashMapsHashSets and HashMaps

……are are java.utiljava.util implementations of implementations of SetSet (not (not SortedSetSortedSet) and ) and MapMap..

Average time for lookup, insertion, or Average time for lookup, insertion, or deletion is deletion is O(1)O(1).. but worst case is O(N).but worst case is O(N). A quick view of how it works:A quick view of how it works:

hashCode function maps object to an integer, which hashCode function maps object to an integer, which is used to find an index into an array.is used to find an index into an array.

Collision resolution.Collision resolution. Fast search, but Fast search, but unorderedunordered..

Need to implement Need to implement .equals().equals() and and .hashCode().hashCode()

More details in CSSE230…More details in CSSE230…

Page 12: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

PriorityQueue classPriorityQueue class

Similar to a queue, but each item has an Similar to a queue, but each item has an associated priority. associated priority.

Only the item with minimum priority is Only the item with minimum priority is accessible. accessible.

Allows an object to “cut” in line if lower priorityAllows an object to “cut” in line if lower priority Elements need to be comparableElements need to be comparable Operations: Operations:

findMin(peek) findMin(peek) (O(log n))(O(log n)) deleteMin(poll)deleteMin(poll) (O(log n)) (O(log n)) insert(offer) insert(offer) (O(1))(O(1))

Underlying data structure: a binary heap Underlying data structure: a binary heap (another shameless plug for CSSE230)(another shameless plug for CSSE230)

Page 13: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

Speaking of CSSE230Speaking of CSSE230

Given the choice, you should take Given the choice, you should take CSSE230 CSSE230 after after this Winter. Why? this Winter. Why?

Less overlap with 221 and you’ll do a Less overlap with 221 and you’ll do a cool projectcool project

Page 14: CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.

DemoDemo


Recommended