CSCI 104 Abstract Data Types. Mark Redekopp David Kempe

Similar documents
CSCI 104 Abstract Data Types. Mark Redekopp David Kempe

CSCI 104 Templates. Mark Redekopp David Kempe

CSCI 104 Templates. Mark Redekopp David Kempe

CSCI 104. Rafael Ferreira da Silva. Slides adapted from: Mark Redekopp and David Kempe

EE 355 Unit 13 C++ STL; Iterators, Maps, Sets. Mark Redekopp

CSCI 104 C++ STL; Iterators, Maps, Sets. Mark Redekopp David Kempe

CSCI 104 Hash Tables & Functions. Mark Redekopp David Kempe

CSCI 104 Searching and Sorted Lists. Mark Redekopp David Kempe

CSCI 104. Rafael Ferreira da Silva. Slides adapted from: Mark Redekopp and David Kempe

CS 104 (Spring 2014) Final Exam 05/09/2014

Data Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada

Sets and Maps. Set Commands Set ADT Set ADT implementation Map ADT Map ADT implementation

Abstract Data Types. CS 234, Fall Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples

Programming Languages and Techniques (CIS120)

CSCI 104 Inheritance. Mark Redekopp David Kempe

CS2110: Software Development Methods. Maps and Sets in Java

Programming Languages and Techniques (CIS120)

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Lecture 21. Chapter 12 More Python Containers

CSCI 104 C++ STL; Iterators, Maps, Sets. Mark Redekopp David Kempe

CS150 - Final Cheat Sheet

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:

Intro To HTML & Web & Relational Queries Individual Assignment 30 Points

CS 455 Final Exam Fall 2015 [Bono] Dec. 15, 2015

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2).

Working with recursion

CS2110: Software Development Methods. Maps and Sets in Java

CSCI 104 Classes. Mark Redekopp David Kempe

MyELT STUDENT QUICK START GUIDE

CSCI Trees. Mark Redekopp David Kempe

Abstract Data Types Chapter 1

PRACTICE MIDTERM EXAM #2

CSCI 104 Searching and Sorted Lists. Mark Redekopp David Kempe Sandra Batista

CS302 - Data Structures using C++

cd h: mkdir -p CS101 cd CS101 curl -O unzip zipfile cd CS101_Exam4

Linked Data Structures. Linked lists. Readings: CP:AMA The primary goal of this section is to be able to use linked lists and trees.

If a b or a c, then a bc If a b and b c, then a c Every positive integer n > 1 can be written uniquely as n = p 1 k1 p 2 k2 p 3 k3 p 4 k4 p s

Topic 10: The Java Collections Framework (and Iterators)

Storage and Indexing, Part I

CS 1110 Prelim 2 April 22, 2014

CS302 Data Structures using C++

CS 1114: Implementing Search. Last time. ! Graph traversal. ! Two types of todo lists: ! Prof. Graeme Bailey.

Tables, Priority Queues, Heaps

COM2001 Advanced Programming Techniques. Mike Stannett Department of Computer Science The University of Sheffield

CS24 Week 4 Lecture 2

Abstract Data Types (ADTs) & Design

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Homework 1: RA, SQL and B+-Trees (due September 24 th, 2014, 2:30pm, in class hard-copy please)

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter 2012

1 (10) 2 (8) 3 (12) 4 (14) 5 (6) Total (50)

CSE373: Data Structures & Algorithms Lecture 4: Dictionaries; Binary Search Trees. Kevin Quinn Fall 2015

CP222 Computer Science II. Linked Lists

CSE 332: Data Structures & Parallelism Lecture 10:Hashing. Ruth Anderson Autumn 2018

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

Entity Attribute STUDENT TABLE tuples single domain

Linked Data Structures. Linked lists. Readings: CP:AMA The primary goal of this section is to be able to use linked lists and trees.

CSI33 Data Structures

PRACTICE FINAL EXAM 2

Tutorial notes on. Object relational structural patterns

CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017

Lecture 7. Log into Linux New documents posted to course webpage

CSE143 Midterm Summer Name of Student: Section (e.g., AA): Student Number:

CS 261: Data Structures. Sorted Dynamic Array Bag and Set

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018

Module 9: Binary trees

Today s Topics. What is a set?

CS 103 Six Degrees of Kevin Bacon

Getting Started in the Online Lab

CS Homework 4 Lifeguard Employee Ranker. Due: Tuesday, June 3rd, before 11:55 PM Out of 100 points. Files to submit: 1. HW4.py.

Hashing. October 19, CMPE 250 Hashing October 19, / 25

EE 355 Unit 17. Python. Mark Redekopp

ECE 2400 Computer Systems Programming Fall 2017 Topic 9: Abstract Data Types

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

PROGRAMMING IN HASKELL. CS Chapter 6 - Recursive Functions

CSCI 104 Overview. Mark Redekopp David Kempe

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures

SETS AND MAPS. Chapter 9

CSCI 104 Log Structured Merge Trees. Mark Redekopp

PRACTICE FINAL EXAM 3

Computer Science 9608 (Notes) Chapter: 4.1 Computational thinking and problem-solving

CS 103: Introduction to Programming Fall Written Final Exam 12/11/16, 4:30PM 6:30PM

CS 112 Final May 8, 2008 (Lightly edited for 2011 Practice) Name: BU ID: Instructions GOOD LUCK!

INTERNATIONAL EDITION. Problem Solving with C++ Data Abstraction & SIXTH EDITION. Walls and Mirrors. Frank M. Carrano Timothy Henry

Linked Lists. Gaddis Ch. 17. CS 2308 :: Spring 2016 Molly O'Neil

Dr. Chuck Cartledge. 19 Nov. 2015

ECE 2400 Computer Systems Programming Fall 2018 Topic 9: Abstract Data Types

Algorithm Design and Analysis

Programming Languages and Techniques (CIS120)

Exam Data structures DIT960/DAT036

CS 455 Final Exam Fall 2016 [Bono] December 13, 2016

ORACLE Reference. 2. Modify your start-up script file using Option 1 or 2 below, depending on which shell you run.

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

Do not write in this area TOTAL. Maximum possible points: 75

CS 103 The Social Network

Functions. Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein

Quiz 1, January 15, minutes; ½ pt/answer; 2½ pts total. 1. In what decade was the oldest language still in use created?

Data Structures And Algorithms

Symbol Tables. Computing 2 COMP x1

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

2

Transcription:

CSCI 104 Abstract Data Types Mark Redekopp David Kempe

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

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

3 Popular ADTs List Dictionary/Map Set 4

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] 5

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

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 do on a map/dictionary? No inherent ordering between key,value pairs Can't ask for the 0 th item "Billy Bruin" 2.5 "Tommy Trojan" 3.7 "Harry Harvard" 4.3 "Dale Duck" 2.5 7

Map / Dictionary Operations Operation 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 Lookup / Get Lookup the value associated with the given key or indicate the key,value pair doesn't exist Key Value associated with the key In / Find Check if the given key is present in the map Key Int: value at location empty Returns true if there are no values in the list bool size Returns the number of values in the list int 8

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 0 th course at USC?" In DAPS textbook Chapter 1, this is the 'bag' ADT What operations do we perform on a set? EE 101 ARLT 100 MATH 226 CSCI 104 9

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

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

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) List Map Map Set Set 12

Some Implementation Details List Set An array acts as a list Index provides ordering First at location 0 Last at location n-1 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 0 1 2 3 4 5 30 51 30 53 30 10 6 7 8 9 10 11 0 1 2 3 4 5 6 7 8 9 10 11 30 51 53 10 struct Pair{ string key; double value;; }; 0 1 2 3 "Tommy" 3.7 "Billy" 2.5 "Harry" 4.3 13