CSCI 104 Abstract Data Types

Slides:



Advertisements
Similar presentations
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
Advertisements

Abstractions, Collections & Data Structures Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Data Abstraction: The Walls
CS Winter 2011 Abstract Data Types. Container Classes Over the years, programmers have identified a small number of different ways of organizing.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
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 in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
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 TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Can’t provide fast insertion/removal and fast lookup at the same time Vectors, Linked Lists, Stack, Queues, Deques 4 Data Structures - CSCI 102 Copyright.
1 Joe Meehean.  List of names  Set of names  Map names as keys phone #’s as values Phil Bill Will Phil Bill Will Phil Bill Will Phil: Bill:
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Thomas Kuehne.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
CSE 143 Lecture 11: Sets and Maps reading:
CPSC 252 Tables / Maps / Dictionaries Page 1 Tables, Maps and Dictionaries A table (or map or dictionary) is a collection of key/value pairs. In general.
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Advanced Data Structures Lecture 1
Introduction toData structures and Algorithms
CSCE 210 Data Structures and Algorithms
Using the Java Collection Libraries COMP 103 # T2
CSc 110, Autumn 2016 Lecture 26: Sets and Dictionaries
CSE 1342 Programming Concepts
Data Structures Using C, 2e
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.
September 29 – Stacks and queues
Now with a speaking professor! (hopefully...)
The Design and Analysis of Algorithms
CSCI 104 Searching and Sorted Lists
Wednesday Notecards. Wednesday Notecards Wednesday Notecards.
Containers and Lists CIS 40 – Introduction to Programming in Python
Data Abstraction: The Walls
C++ Standard Library.
Slides by Steve Armstrong LeTourneau University Longview, TX
Mark Redekopp David Kempe
JAVA COLLECTIONS LIBRARY
JAVA COLLECTIONS LIBRARY
Basic Data Structures.
Queues Queues Queues.
CSCI 104 Log Structured Merge Trees
CSc 110, Spring 2017 Lecture 28: Sets and Dictionaries
CSc 110, Spring 2018 Lecture 32: Sets and Dictionaries
CSc 110, Autumn 2017 Lecture 30: Sets and Dictionaries
Road Map CS Concepts Data Structures Java Language Java Collections
structures and their relationships." - Linus Torvalds
Abstract Data Types (ADTs)
CS313D: Advanced Programming Language
COSC 1323 – Computer Science Concepts I
Python Data Structures
Recitation Outline C++ STL associative containers Examples
Exercise Write a program that counts the number of unique words in a large text file (say, Moby Dick or the King James Bible). Store the words in a collection.
Data Abstraction: The Walls
Sorting "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
Array-Based Implementations
CSE 373 Java Collection Framework, Part 2: Priority Queue, Map
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
Queues and Priority Queue Implementations
CO4301 – Advanced Games Development Week 12 Using Trees
Sets CS3240, L. grewe.
structures and their relationships." - Linus Torvalds
Abstract Data Types Stacks CSCI 240
Dictionary.
Abstract Data Types (ADTs)
Introduction to Computer Science
Data Structures & Programming
Presentation transcript:

CSCI 104 Abstract Data Types Mark Redekopp David Kempe

XKCD #138 Courtesy of Randall Munroe @ http://xkcd.com

Abstract Data Types DAPS defines an abstract data type, or ADT, as: Specification/model for a group of values/data and the operations on those values The model allows us to separate… The decision of what data structure to use and how it will be used in our higher level application And the implementation of the specific data structure DAPS defines a data structure as: An implementation of an ADT in a given programming language Each ADT we will examine in this course has certain: Well defined operations and capabilities that are often useful Time & space advantages Time & space disadvantages You need to know those operations, advantages and disadvantages Data Abstraction & Problem Solving with C++, Carrano and Henry will henceforth be abbreviated as DAPS

3 Popular ADTs List Dictionary/Map Set (Possible 4th: Priority Queue)

Lists Ordered collection of items, which may contain duplicate values, usually accessed based on their position (index) Ordered = Each item has an index and there is a front and back (start and end) Duplicates allowed (i.e. in a list of integers, the value 0 could appear multiple times) Accessed based on their position ( list[0], list[1], etc. ) What are some operations you perform on a list? list[0] list[1] list[2]

List Operations Operation Description Input(s) Output(s) insert Add a new value at a particular location shifting others back Index : int Value remove Remove value at the given location Value at location get / at Get value at given location set Changes the value at a given location empty Returns true if there are no values in the list bool size Returns the number of values in the list int push_back / append Add a new value to the end of the list find Return the location of a given value Int : Index

Grade Inflation in the Ivy League!! Maps / Dictionaries Stores key,value pairs Example: Map student names to their GPA Keys must be unique (can only occur once in the structure) No constraints on the values What operations do you perform on a map/dictionary? No inherent ordering between key,value pairs Can't ask for the 0th item… "Billy Bruin" 2.5 "Harry Harvard" 4.3 "Tommy Trojan" 3.7 Grade Inflation in the Ivy League!! "Dale Duck" 2.5

Map / Dictionary Operations Description Input(s) Output(s) Insert / add Add a new key,value pair to the dictionary (assuming its not there already) Key, Value Remove Remove the key,value pair with the given key Key Get / lookup Lookup the value associated with the given key or indicate the key,value pair doesn't exist Value associated with the key In / Find Check if the given key is present in the map bool (or ptr to pair/NULL) empty Returns true if there are no values in the list size Returns the number of values in the list int

Set A set is a dictionary where we only store keys (no associated values) Example: All the courses taught at USC (ARLT 100, …, CSCI 104, MATH 226, …) Items (a.k.a. Keys) must be unique No duplicate keys (only one occurrence) Not accessed based on index but on value We wouldn't say, "What is the 0th course at USC?" In DAPS textbook Chapter 1, this is the 'bag' ADT What operations do we perform on a set? ARLT 100 CSCI 104 EE 101 MATH 226

Set Operations Operation Description Input(s) Output(s) Insert / add Add a new key to the set (assuming its not there already) Key Remove In / Find Check if the given key is present in the map bool (or ptr to item/NULL) empty Returns true if there are no values in the list size Returns the number of values in the list Int intersection Returns a new set with the common elements of the two input sets Set1, Set2 New set with all elements that appear in both set1 and set2 union Returns a new set with all the items that appear in either set New set with all elements that appear in either set1 and set2 difference Returns a set with all items that are just in set1 but not set2 New set with only the items in set1 that are not in set2

Intersection, Union, Difference May be familiar from CS 170 Set intersection S1  S2 Set Union S1  S2 Set Difference S1 – S2 EE 101 MATH 226 EE 101 WRIT 140 ARLT 100 CSCI 104 CSCI 170 CSCI 104 S1 S2 EE 101 CSCI 104 Intersection EE 101 MATH 226 WRIT 140 ARLT 100 CSCI 104 CSCI 170 Union MATH 226 ARLT 100 Difference

What's Your ADT? Scores on a test Students in a class Courses & their enrollment Temperature Reading at a location Usernames and password Index in a textbook Facebook friends Adjacent countries of a map List Set (maybe List) Map (Key = course, Value = enrollment) Map Set

Some Implementation Details List An array acts as a list Index provides ordering First at location 0 Last at location n-1 Set Can use an array Must check for duplicate on insertion O(n) solution Can we do better? Yes… Map Can also use an array Again check for duplicate key on insertion 1 2 3 4 5 6 7 8 9 10 11 30 51 30 53 30 10 1 2 3 4 5 6 7 8 9 10 11 30 51 53 10 struct Pair{ string key; double value;; }; 1 2 3 "Tommy" 3.7 "Billy" 2.5 "Harry" 4.3