Dictionary Implementations Chapter 18 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.

Slides:



Advertisements
Similar presentations
Lists Chapter 4 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Advertisements

Stacks Chapter 21 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
An Introduction to Sorting Chapter 8 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Dictionaries Chapter Chapter Contents Specifications for the ADT Dictionary Entries and methods Using the ADT Dictionary English Dictionary Telephone.
Dictionary Implementations Chapter Chapter Contents Array-Based Implementations The Entries An Unsorted Array-Based Dictionary A Sorted Array-Based.
A Bag Implementation that Links Data Chapter 3 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A List Implementation That Links Data Chapter 6 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Faster Sorting Methods Chapter 12 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Creating Classes from Other Classes Chapter 2 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Completing the Linked Implementation of a List Chapter 7 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Graphs Chapter 30 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
List Implementations That Use Arrays Chapter 5 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L16 (Chapter 22) Java Collections.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 48 Hashing.
Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Announcements.
Iterators Chapter 8 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Queue, Deque, and Priority Queue Implementations Chapter 24 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
The Efficiency of Algorithms Chapter 9 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Trees Chapter 25 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Stack Implementations Chapter 22 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Searching Chapter 16 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Inheritance and Lists Chapter 14 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Stack Implementations Chapter Chapter Contents A Linked Implementation An Array-Based Implementation A Vector-Based Implementation.
Mutable, Immutable, and Cloneable Objects Chapter 15 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Sorted Lists and Their Implementations Chapter 12 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Queue, Deque, and Priority Queue Implementations Chapter 11 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A Binary Search Tree Implementation Chapter 25 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Queues, Deques, and Priority Queues Chapter 23 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Searching Chapter 18 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
An Introduction to Sorting Chapter 11 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Hashing as a Dictionary Implementation Chapter 20 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Graph Implementations Chapter 31 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
A Binary Search Tree Implementation Chapter 27 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Dictionaries Chapter 17 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
111 © 2002, Cisco Systems, Inc. All rights reserved.
An Introduction to Sorting Chapter 8 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with.
Searching Chapter 18 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Lists Chapter 4 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Stack Implementations Chapter 6 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A Heap Implementation Chapter 26 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Iterators (short version) Chapter 15 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
A Bag Implementation that Links Data Chapter 3 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
Balanced Search Trees (partial) Chapter 29 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall - Edited by Nadia Al-Ghreimil.
Lists and Sorted Lists: various implementations Slides by Nadia Al-Ghreimil adopted from Steve Armstrong LeTourneau University Longview, TX  2007, 
A Binary Search Tree Implementation Chapter 25 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
Recursion Chapter 10 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
The Efficiency of Algorithms Chapter 9 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights.
Slides by Steve Armstrong LeTourneau University Longview, TX
Iterators (short version)
Slides by Steve Armstrong LeTourneau University Longview, TX
Slides by Steve Armstrong LeTourneau University Longview, TX
Slides by Steve Armstrong LeTourneau University Longview, TX
Iterators (partial) Chapter 8 Slides by Nadia Al-Ghreimil
List Implementations that Use Arrays
A List Implementation That Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Balanced Search Trees (partial)
Stack Implementations
A List Implementation That Links Data
List Implementations that Use Arrays
Stack Implementations
© 2016 Pearson Education, Ltd. All rights reserved.
A List Implementation that Uses An Array
A List Implementation that Links Data
Presentation transcript:

Dictionary Implementations Chapter 18 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Chapter Contents Array-Based Implementations  An Unsorted Array-Based Dictionary  A Sorted Array-Based Dictionary Vector-Based Implementation Linked Implementations  An Unsorted Linked Dictionary  A Sorted Linked Dictionary

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Array Based Implementations 1 Each entry consists of two parts  A search key  A value Strategies  Encapsulate the two parts into an object  Use two parallel arrays Text focuses on first approach

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Array-Based Implementations Fig Two possible ways to use arrays to represent dictionary entries: (a) an array of objects that encapsulates each search key and corresponding value …

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Array-Based Implementations Fig Two possible ways to use arrays to represent dictionary entries: (b) parallel arrays of search keys and values

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Unsorted Array-Based Dictionary Our implementation uses one array  Each element in dictionary (the array) is an instance of class Entry  Entry will be private and internal to the dictionary class Outer class stated in terms of type parameters K and V  Data types of the search keys and the values View source code of ArrayDictionarysource code

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Unsorted Array-Based Dictionary 5 Fig Adding a new entry to an unsorted array- based dictionary. Click to see method add()

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Unsorted Array-Based Dictionary 6 Fig 18-3 Removing an entry from an unsorted array-based dictionary Click to see method remove()

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Unsorted Array-Based Implementations 8 Unsorted worst-case efficiencies  Addition O(1)  Removal O(n)  Retrieval O(n)  Traversal O(n)

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Sorted Array-Based Dictionary 9 Fig Adding an entry to a sorted array-based dictionary: (a) search; (b) make room; (c) insert.

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Sorted Array-Based Dictionary 11 Some of implementation same as unsorted dictionary Differences  Search key must be from class that implements Comparable View class SortedArrayDictionary SortedArrayDictionary Note methods  add add  locateIndex locateIndex

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Sorted Array-Based Implementations 15 Sorted worst-case efficiencies  Addition O(n)  Removal O(n)  Retrieval O(log n)  Traversal O(n)

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Vector-Based Implementations Similar in spirit to the array-based version With vector no need for …  makeRoom  doubleArray  isArrayFull  Counting entries, vector does so for you View class SortedVectorDictionary SortedVectorDictionary  Note private inner class KeyIteratorKeyIterator

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Linked Implementations 22 Fig Three possible ways to use linked nodes to represent the entries of a dictionary: (a) a chain of nodes that each reference an entry object; …

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Linked Implementations Fig Three possible ways to use linked nodes to represent the entries of a dictionary: (b) parallel chains of search keys and values …

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Linked Implementations Fig Three possible ways to use linked nodes to represent the entries of a dictionary: (c) a chain of nodes that each reference a search key and a value

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Unsorted Linked Implementations 23 Unsorted worst-case efficiencies  Addition O(1)  Removal O(n)  Retrieval O(n)  Traversal O(n)

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Linked Implementations Fig Adding to an unsorted linked dictionary.

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A Sorted Linked Dictionary 25 When adding nodes  Requires sequential search from beginning  Need only search until desiredKey ≥ nodeKey View class SortedLinkedDictionary SortedLinkedDictionary Note private inner class KeyIterator KeyIterator

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Sorted Linked Implementations 27 Sorted worst-case efficiencies  Addition O(n)  Removal O(n)  Retrieval O(n)  Traversal O(n)