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

Slides:



Advertisements
Similar presentations
JAVA Programming (Session 7) When you are willing to make sacrifices for a great cause, you will never be alone. Instructor:
Advertisements

Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
© 2006 Pearson Addison-Wesley. All rights reserved12 B-1 Chapter 12 (continued) Tables and Priority Queues.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
Data Structures: Lists i206 Fall 2010 John Chuang Some slides adapted from Glenn Brookshear, Brian Hayes, or Marti Hearst.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
CSSE221: Software Dev. Honors Day 13 Announcements Announcements Contractions throughout the night… Contractions throughout the night… Late day assignments.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
CSSE221: Software Dev. Honors Day 15 Announcements Announcements Pass in UML for Cars, Trucks, Trains Pass in UML for Cars, Trucks, Trains Homework 5 late.
Chapter 1 Introduction Definition of Algorithm An algorithm is a finite sequence of precise instructions for performing a computation or for solving.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Chapter 19 Java Data Structures
Java Collections. Collections, Iterators, Algorithms CollectionsIteratorsAlgorithms.
Java's Collection Framework
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Collections F The limitations of arrays F Java Collection Framework hierarchy  Use the Iterator interface to traverse a collection  Set interface, HashSet,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
DataStructures1 Barb Ericson Georgia Tech July 2008.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Information and Computer Sciences University of Hawaii, Manoa
Big Java Chapter 16.
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
1/ 124 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 18 Programming Fundamentals using Java 1.
1 CSE 1342 Programming Concepts Lists. 2 Basic Terminology A list is a finite sequence of zero or more elements. –For example, (1,3,5,7) is a list of.
Data structures Abstract data types Java classes for Data structures and ADTs.
Data structures and algorithms in the collection framework 1.
A data structure is a type of data storage ….similar to an array. There are many data structures in Java (Stacks, Queues, LinkedList, Sets, Maps, HashTables,
Sets and Maps Chris Nevison. Set Interface Models collection with no repetitions subinterface of Collection –has all collection methods has a subinterface.
Georgia Institute of Technology Workshop for CS-AP Teachers Data Structures Barb Ericson June 2006.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 6 Data Structures.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
1 Interfaces in Java’s Collection Framework Rick Mercer.
Interface: (e.g. IDictionary) Specification class Appl{ ---- IDictionary dic; dic= new XXX(); application class: Dictionary SortedDictionary ----
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Priority Queues. Priority Queue ADT A priority queue stores a collection of entries Each entry is a pair (key, value) Main methods of the Priority Queue.
Data-structure-palooza Checkout DataStructures from SVN.
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
COMP 103 Maps and Queues. RECAP  Iterators (for-each loop)  Bag, Sets, and Stacks - a class, not interface TODAY  Maps and Queues 2 RECAP-TODAY QUICK.
Java Collections Framework The client view. The Big Picture.
Introduction to Data Structure and Algorithms
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
QueueStack CS1020.
Heaps And Priority Queues
Chapter 12: Data Structures
Heaps & Priority Queues
Road Map CS Concepts Data Structures Java Language Java Collections
structures and their relationships." - Linus Torvalds
Java Collections Framework
ITEC 2620M Introduction to Data Structures
Dynamic Sets (III, Introduction)
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Workshop for CS-AP Teachers
CS 240 – Advanced Programming Concepts
structures and their relationships." - Linus Torvalds
Presentation transcript:

CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions on 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.

This week: Markov Monday: Monday: Stacks and Queues Stacks and Queues Sets, Maps, and PriorityQueues Sets, Maps, and PriorityQueues Tuesday: Tuesday: Some pros and cons of various data structures Some pros and cons of various data structures Brief example of file I/O Brief example of file I/O Introduction to Markov, a cool statistical text program with lots of data structures Introduction to Markov, a cool statistical text program with lots of data structures Thursday: Thursday: Exam 1 Exam 1

Stack 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 implementation of (recursive) method calls and “undo” functions. Many applications, such as the implementation of (recursive) 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?

Queue 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.

Array implementation of a queue What if we run out of room?

LinkedList implementation of a queue

Demo

A tale of two interfaces: Set … A collection with no duplicates A collection with no duplicates If obj1 and obj2 are both in the set, then obj1.equals(obj2) returns false. If obj1 and obj2 are both in the set, then obj1.equals(obj2) returns false. Subinterface: SortedSet Subinterface: SortedSet Not quite a mathematical set (no intersection or union methods) Not quite a mathematical set (no intersection or union methods) “Bob”, “Flo”, “Gary”, “Lisa”, “Marie”

…and Map …and Map An object that maps keys to values. Duplicates? A map cannot contain duplicate keys; each key can map to at most one value. V get(Object key) Multiple keys can have the same value Other operations: put(K key, V value) containsKey(Object key) containsValue(Object value) V remove(Object key) , , “Bill Smith”, “Darla Clive” NO HashMap map = new HashMap (); map.put( , “”Bill Smith”); map.put( , “Darla Clive”); Keys Values OK

TreeSets and TreeMaps …are java.util implementations of SortedSet and Map. 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 can also be O(log N) and with complex algorithms, worst case can also be O(log N) Also support taking ordered subsets from head, tail, or interior of set or map Also support taking ordered subsets from head, tail, or interior of set or map More details in CSSE230… More details in CSSE230…

HashSets and HashMaps …are java.util implementations of Set (not SortedSet) and Map. Average time for lookup, insertion, or deletion is O(1). Average time for lookup, insertion, or deletion is 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 is used to find an index into an array. hashCode function maps object to an integer, which is used to find an index into an array. Collision resolution. Collision resolution. Fast search, but unordered. Fast search, but unordered. Need to implement.equals() and.hashCode() Need to implement.equals() and.hashCode() More details in CSSE230… More details in CSSE230…

PriorityQueue class Similar to a queue, but each item has an associated priority. Similar to a queue, but each item has an associated priority. Only the item with minimum priority is accessible. Only the item with minimum priority is accessible. Allows an object to “cut” in line if lower priority Allows an object to “cut” in line if lower priority Elements need to be comparable Elements need to be comparable Operations: Operations: findMin(peek) (O(log n)) findMin(peek) (O(log n)) deleteMin(poll) (O(log n)) deleteMin(poll) (O(log n)) insert(offer) (O(1)) insert(offer) (O(1)) Underlying data structure: a binary heap (another shameless plug for CSSE230) Underlying data structure: a binary heap (another shameless plug for CSSE230)

Speaking of CSSE230 Given the choice, you should take CSSE230 after this Winter. Why? Given the choice, you should take CSSE230 after this Winter. Why? Less overlap with 221 and you’ll do a cool project Less overlap with 221 and you’ll do a cool project

Demo