October 2nd – Dictionary ADT

Slides:



Advertisements
Similar presentations
CSE Lecture 3 – Algorithms I
Advertisements

CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Complexity Analysis (Part I)
Complexity Analysis (Part I)
Algorithm Efficiency and Sorting
Elementary Data Structures and Algorithms
Abstract Data Types (ADTs) Data Structures The Java Collections API
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
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.
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Lauren Milne Summer 2015.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Searching Topics Sequential Search Binary Search.
CSE373: Data Structures & Algorithms Lecture 5: Dictionary ADTs; Binary Trees Lauren Milne Summer 2015.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Advanced Data Structures Lecture 1
Complexity Analysis (Part I)
CSE373: Data Structures and Algorithms Lecture 2: Math Review; Algorithm Analysis Kevin Quinn Fall 2015.
CSE373: Data Structures & Algorithms Lecture 5: Dictionary ADTs; Binary Trees Linda Shapiro Winter 2015.
CSC317 Selection problem q p r Randomized‐Select(A,p,r,i)
Course Developer/Writer: A. J. Ikuomola
Data Structures and Algorithms for Information Processing
May 17th – Comparison Sorts
Algorithmic complexity: Speed of algorithms
April 19th – Avl Operations
CSE373: Data Structures & Algorithms Lecture 6: Hash Tables
CSE 373: Data Structures and Algorithms Pep Talk; Algorithm Analysis
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Catie Baker Spring 2015.
Cse 373 April 24th – Hashing.
Cse 373 May 15th – Iterators.
COMP 103 SORTING Lindsay Groves 2016-T2 Lecture 26
Algorithm Analysis CSE 2011 Winter September 2018.
March 31 – Priority Queues and the heap
Cse 373 April 12th – TreEs.
Cse 373 April 26th – Exam Review.
November 1st – Exam Review
Searching.
Data Structures and Algorithms
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Road Map CS Concepts Data Structures Java Language Java Collections
CSE373: Data Structures & Algorithms Lecture 5: Dictionary ADTs; Binary Trees Catie Baker Spring 2015.
structures and their relationships." - Linus Torvalds
Introduction to Hash Tables
Algorithm design and Analysis
CSE332: Data Abstractions Lecture 5: Binary Heaps, Continued
CSE373: Data Structures and Algorithms Lecture 2: Math Review; Algorithm Analysis Dan Grossman Fall 2013.
MSIS 655 Advanced Business Applications Programming
CSE 373: Data Structures and Algorithms
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Implementing Hash and AVL
Searching CLRS, Sections 9.1 – 9.3.
Algorithmic complexity: Speed of algorithms
CS2110: Software Development Methods
Searching, Sorting, and Asymptotic Complexity
CSE 373: Data Structures & Algorithms
CSE 373 Data Structures and Algorithms
Introduction to Data Structure
Algorithmic complexity: Speed of algorithms
Data Structures & Algorithms
Data Structures and Algorithms
CO4301 – Advanced Games Development Week 12 Using Trees
CSE 326: Data Structures Lecture #14
Complexity Analysis (Part I)
structures and their relationships." - Linus Torvalds
Week 6 - Monday CS221.
Complexity Analysis (Part I)
Presentation transcript:

October 2nd – Dictionary ADT Cse 373 October 2nd – Dictionary ADT

Today’s Lecture Project 1 JUnit Generics Iterators Dictionary ADT Implementations Analysis

Overload Overload form is out https://goo.gl/forms/2pFBteeXg5L7wdC12 Many of you have already been added If you haven’t fill out this form ASAP and we’ll fill our remaining seats

Project 1 Checkpoint 1 due Wednesday Remember, 50% of lost points back Teams of up to 2, specify clearly

JUnit: Testing Framework A Java library for unit testing, comes included with Eclipse JUnit is distributed as a "JAR" which is a compressed archive containing Java .class files import org.junit.Test; import static org.junit.Assert.*; public class name { ... @Test public void name() { // a test case method } A method with @Test is flagged as a JUnit test case and run

JUnit Asserts and Exceptions A test will pass if the assert statements all pass and if no exception thrown. Examples of assert statements: assertTrue(value) assertFalse(value) assertEquals(expected, actual) assertNull(value) assertNotNull(value) fail() Tests can expect exceptions @Test(expected = ExceptionType.class) public void name() { ... }

JUNIT Use assertions to prescribe expected behavior If a test “asserts” something should happen, the test will fail if it doesn’t Use the testing cases from Friday to create good test cases

JUNIT This is new for you, but it is important to learn now. Projects will have more testing later in the quarter Checkpoint 1 is a good opportunity to experiment and learn the framework on low stakes

Generics Projects in this course will use Java generics Allows implementation of data structures for non-specific data types https://docs.oracle.com/javase/tutorial/java/generics/index.html Oracle tutorial is pretty good here

Iterators An iterator is a Java object that goes over a collection of data Supports two functions boolean hasNext(): returns true if the iterator has another object E next(): returns the next object from the data structure “E” is a Java generic and it represents whatever data is actually in the data structure.

Iterators What is “next”? Depends on how we want to iterate through the elements Examples: BFSIterator PathIterator DuplicateIterator SortedIterator

Dictionary ADT New abstract data type

Dictionary ADT New abstract data type

Dictionary ADT New abstract data type Dictionary (aka Map) Data – Key and Value pairs

Dictionary ADT New abstract data type Dictionary (aka Map) Data – Key and Value pairs Keys: must be comparable, used for lookup

Dictionary ADT New abstract data type Dictionary (aka Map) Data – Key and Value pairs Keys: must be comparable, used for lookup Values: the actual data itself

Dictionary ADT New abstract data type Dictionary (aka Map) Data – Key and Value pairs Keys: must be comparable, used for lookup Values: the actual data itself Example (Store inventory):

Dictionary ADT New abstract data type Dictionary (aka Map) Data – Key and Value pairs Keys: must be comparable, used for lookup Values: the actual data itself Example (Store inventory): Keys: IDs (barcodes) Values: Product information

Dictionary ADT Operations

Dictionary ADT Operations insert(key, value): inserts the key, value pair into the dictionary. Overwrites the old value if the key is already in the dictionary.

Dictionary ADT Operations insert(key, value): inserts the key, value pair into the dictionary. Overwrites the old value if the key is already in the dictionary. find(key): returns the stored value for a particular key in the dictionary, returns null if not found.

Dictionary ADT Operations insert(key, value): inserts the key, value pair into the dictionary. Overwrites the old value if the key is already in the dictionary. find(key): returns the stored value for a particular key in the dictionary, returns null if not found. delete(key): removes the key, value pair denoted by the key from the dictionary.

Set ADT Slightly different from Dictionary

Set ADT Slightly different from Dictionary No values, the set only cares if a key is present or not

Set ADT Slightly different from Dictionary No values, the set only cares if a key is present or not Find, insert and delete have few differences

Set ADT Slightly different from Dictionary No values, the set only cares if a key is present or not Find, insert and delete have few differences Possible to implement other functions from sets

Set ADT Slightly different from Dictionary No values, the set only cares if a key is present or not Find, insert and delete have few differences Possible to implement other functions from sets Union, intersection, difference

Applications Store information in key, value pairs Very common usage pattern

Applications Store information in key, value pairs Very common usage pattern Phone directories Indexing OS page tables Databases

Implementations Important to allow fast operations over the keys

Implementations Important to allow fast operations over the keys Dependent on what the client uses most

Implementations Important to allow fast operations over the keys Dependent on what the client uses most Could be many lookups and few inserts

Implementations Important to allow fast operations over the keys Dependent on what the client uses most Could be many lookups and few inserts Keys and Values should be stored together in some way

Implementations Important to allow fast operations over the keys Dependent on what the client uses most Could be many lookups and few inserts Keys and Values should be stored together in some way Both objects in one node Paired arrays (one stores keys and the other values)

Simple Implementations Linked Lists How would this work? What other properties can we utilize here?

Simple Implementations Linked Lists How would this work? What other properties can we utilize here? Sortedness? Singly or doubly-linked? Duplicate finding?

Simple Implementations Arrays Sortedness? Resizing? <Key, Value> Pairing?

Simple Implementations Are there benefits of one over the other? Need methods of analytical analysis

Algorithm analysis Important topic. Why? Show that an implementation is better.

Algorithm analysis Important topic. Why? Show that an implementation is better. What do we mean by better? Fewer clock cycles More efficient memory usage Correctness

Algorithm analysis Math review Logarithms log2 x = y when x = 2y How does this grow?

Algorithm analysis Math review Logarithms log2 x = y when x = 2y How does this grow? Slowly A balanced tree has a height ~log2 n logk x differs from logj x by a constant factor

Algorithm analysis Operations log(A*B) = log(A) + log(B) log(AB) = B * log(A)

Algorithm analysis Floor and ceiling

Algorithm analysis Floor and ceiling Integer rounding, computers operate in integer quantities Clock cycles Memory bytes

Algorithm analysis Floor and ceiling Integer rounding, computers operate in integer quantities Clock cycles Memory bytes Floor : ⎣X⎦ denotes largest integer < x Ceiling: ⎡X⎤ denotes smallest integer > x

Algorithm analysis Operations

Algorithm analysis Operations Arithmetic Comparisons Memory reads/writes Loops and functions are just chains of these operations.

Algorithm analysis Int value = 0; for(int i; i = 0; i < 10){ }

Algorithm analysis Int value = 0; for(int i; i = 0; i < 10){ } How long does this take?

Algorithm analysis Int value = 0; for(int i; i = 0; i < N){ } How long does this take?

Algorithm analysis Principles of analysis

Algorithm analysis Principles of analysis Determining performance behavior

Algorithm analysis Principles of analysis Determining performance behavior How does an algorithm react to new data or changes?

Algorithm analysis Principles of analysis Determining performance behavior How does an algorithm react to new data or changes? Independent of language or implementation

Algorithm analysis Example: find() Suppose an array with 5 elements One implementation has a sorted array, the other is unsorted For which one will find() be faster? How long will it take?

Algorithm analysis Find(1) 1 2 3 4 5 4 2 5 3 1

Algorithm analysis Find(1) How many operations? 1 2 3 4 5 4 2 5 3 1

Algorithm analysis Find(4)? 1 2 3 4 5 4 2 5 3 1

Algorithm analysis Not a good representation of how the algorithm actually behaves. Want to access the algorithm on the whole, not just over a few inputs

Algorithm analysis Not a good representation of how the algorithm actually behaves. Want to access the algorithm on the whole, not just over a few inputs This is why testing alone isn’t enough

Algorithm analysis Possible solutions?

Algorithm analysis Possible solutions? Average case: find the average performance over all inputs

Algorithm analysis Possible solutions? Average case: find the average performance over all inputs Worst case: how long the program takes to complete the worst case problems.

Algorithm analysis Possible solutions? Average case: can be difficult to compute

Algorithm analysis Possible solutions? Average case: can be difficult to compute What is the average case for binary search?

Algorithm analysis Possible solutions? Worst case: is most commonly used

Algorithm analysis Possible solutions? Worst case: is most commonly used Easily compared and gives a good estimate of the robustness of an algorithm

Next Class Asymptotic Analysis Efficiency and runtime bigO notation Array and LinkedList dictionaries