Abstractions, Collections & Data Structures Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.

Slides:



Advertisements
Similar presentations
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Advertisements

Computer Science 112 Fundamentals of Programming II Overview of Collections.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Fundamentals of Python: From First Programs Through Data Structures
CHAPTER 4 Queues. Queue  The queue, like the stack, is a widely used data structure  A queue differs from a stack in one important way  A stack is.
CHAPTER 4 Queues MIDTERM THURSDAY, OCTOBER 17 IN LAB.
Data Structures & Java Generics Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Linked list More terminology Singly-linked lists Doubly-linked lists DLLs compared to SLLs Circular Lists.
Queues Chapter 6. Chapter Objectives  To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface for insertion.
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Chapter 12: Data Structures
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
Heaps & Priority Queues Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Data Structures & Java Collections Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
COMP 110 Introduction to Programming Mr. Joshua Stough.
Queues Chapter 6. Chapter 6: Queues2 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface.
TCSS 342, Winter 2005 Lecture Notes
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
COMP 121 Week 14: Queues. Objectives Learn how to represent a queue Learn how to use the methods in the Queue interface Understand how to implement the.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Lists ADT (brief intro):  Abstract Data Type  A DESCRIPTION of a data type  The data type can be anything: lists, sets, trees, stacks, etc.  What.
Stacks and Queues Introduction to Computing Science and Programming I.
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
C++ STL CSCI 3110.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
Data structures Abstract data types Java classes for Data structures and ADTs.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Queues Chapter 6. Chapter 6: Queues Chapter Objectives To learn how to represent a waiting line (queue) and how to use the five methods in the Queue interface:
Holding Your Objects Generics and type-safe containers One of the problems of using pre-Java SE5 containers was that the compiler allowed.
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,
Chapter Objectives  Learn how to represent a waiting line (queue)  Become proficient using the methods in the Queue  Understand how to implement the.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
Queue What is a queue?. Queues A queue is similar to waiting in line for a service, e.g., at the bank, at the bathroom –The first item put on the queue.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
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.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Linear Data Structures
Topic 2 Collections. 2-2 Objectives Define the concepts and terminology related to collections Discuss the abstract design of collections.
Week 4 - Friday.  What did we talk about last time?  Continued doubly linked list implementation  Linked lists with iterators.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Data Structure & Algorithms
Understanding General Software Development Lesson 3.
Cpt S 122 – Data Structures Abstract Data Types
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
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.
Lecture 7 Queues Stacks Trees.
Chapter 15 Lists Objectives
structures and their relationships." - Linus Torvalds
Arrays and Linked Lists
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Introduction to Data Structure
Stacks, Queues, and Deques
structures and their relationships." - Linus Torvalds
Presentation transcript:

Abstractions, Collections & Data Structures Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park

Abstractions and Collections Programs represent and manipulate abstractions, or chunks of information a Sudoku board the moves legal for a particular square a media player a deck of cards The most universal of these is a collection lots of different kinds of collections list, set, ordered set, bag, map For each kind of collection, operations you can perform on them

Collections and Data Structures A collection can typically implemented using several different data structures a data structure is a way of implementing an abstraction and operations on it Different implementations or data structures for an abstraction will provide different efficiencies for different operations we will see more of this in a moment

Collection The base interface of most collections Operations supported: add elements remove elements determine size of collection (# of elements) iterate through elements

Linear Data Structures Total order over elements Each element has unique predecessor Each element has unique successor For any two distinct elements x and y, either x comes before y or y comes before x

Linear Data Structures Core operations Find first element (head) Find next element (successor) Find last element (tail) Terminology Head  no predecessor Tail  no successor Duplicates allowed the same value can appear at different places in the list

Operations on lists add an element where? at beginning/front at rear/end after a particular element remove an element remove first element remove last element remove the String value “Happy” what happens if “Happy” occurs more than once

Accessing elements How do you name an element you want to manipulate first/head last/tail by position (e.g, the 5th element) also a bad movie by walking/iterating through the next, and talking about relative position the next element the previous element

Restricted abstractions Restricting the operations an abstraction supports can be a good thing efficiently supporting only a few operations efficiently is easier if a limited abstraction suits your needs, easily to reason about the limited abstraction than a more general one Restricted list abstractions: queue (aka FIFO queue) stack (aka LIFO queue) dequeue (aka double ended queue)

Queue Can add items to the end of the queue remove them from the front of the queue First-in, first-out order (FIFO) Represented as a list total order over elements But no access to middle of the list Example use: songs to be played jobs to be printed customers to be served

Stack Can add an item to the top of the stack can remove the item on top of the stack No access to elements other than the top Just a list where you can add/remove elements only at one end whether the top of the stack is the front or beginning of the list doesn’t really matter Examples: keep track of pending calculations in a calculator parsing

Double ended queue List/queue where you can add or remove at either end

General list operations get/set/insert/remove value at a particular index get/set/insert/remove value at head/tail iterate through list, and get/set/insert/remove values as you go use a java.util.ListIterator

List implementations Two basic implementation techniques for any kind of list store elements in an array store each element in a separate object, and link them together (a linked list representation)

Array implementations Advantages: Space efficient (just space to hold reference to each element) Can efficiently access elements at any position Disadvantages Has to grow/shrink in spurts Can’t efficiently insert/remove elements in the middle inserting/removing elements at both ends is tricky

Linked implementation Advantages can efficiently insert/remove elements anywhere Disadvantages can’t efficiently access elements at arbitrary positions space overhead (one or two additional pointers per element)