Dictionary Implementations Chapter 18. 2 Chapter Contents Array-Based Implementations The Entries An Unsorted Array-Based Dictionary A Sorted Array-Based.

Slides:



Advertisements
Similar presentations
List Implementations That Use Arrays
Advertisements

The ArrayList Class and the enum Keyword
Hashing as a Dictionary Implementation
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.
Hashing Chapters What is Hashing? A technique that determines an index or location for storage of an item in a data structure The hash function.
A Binary Search Tree Implementation Chapter Chapter Contents Getting Started An Interface for the Binary Search Tree Duplicate Entries Beginning.
Dictionary Implementations Chapter 18 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
A Bag Implementation that Links Data Chapter 3 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
1 Heaps & Priority Queues (Walls & Mirrors - Remainder of Chapter 11)
InOrder Traversal Algorithm // InOrder traversal algorithm inOrder(TreeNode n) { if (n != null) { inOrder(n.getLeft()); visit(n) inOrder(n.getRight());
Completing the Linked Implementation of a List Chapter 7 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
© 2006 Pearson Addison-Wesley. All rights reserved12 A-1 Chapter 12 Tables and Priority Queues.
CS 315 March 24 Goals: Heap (Chapter 6) priority queue definition of a heap Algorithms for Insert DeleteMin percolate-down Build-heap.
Queue, Deque, and Priority Queue Implementations Chapter 14.
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.
Searching Chapter Chapter Contents The Problem Searching an Unsorted Array Iterative Sequential Search Recursive Sequential Search Efficiency of.
Stack Implementations Chapter Chapter Contents A Linked Implementation An Array-Based Implementation A Vector-Based Implementation.
© 2006 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 Tables and Priority Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring.
Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Announcements.
List Implementations That Use Arrays Chapter 5. 2 Chapter Contents Using a Fixed-Size Array to Implement the ADT List An Analogy The Java Implementation.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Queue, Deque, and Priority Queue Implementations Chapter 24 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Priority Queues. Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out –The “smallest” element.
© 2006 Pearson Addison-Wesley. All rights reserved12 A-1 Chapter 12 Heaps.
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.
Stack Implementations Chapter Chapter Contents A Linked Implementation An Array-Based Implementation A Vector-Based Implementation.
Heaps. 2 A complete binary tree Nodes contain Comparable objects Each node contains no smaller (or no larger) than objects in its descendants Maxheap.
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.
Searching Chapter 18 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Hashing as a Dictionary Implementation Chapter 20 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Marc Smith and Jim Ten Eyck
A Binary Search Tree Implementation Chapter 27 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Dictionaries Chapter Chapter Contents Specifications for the ADT Dictionary A Java Interface Iterators Using the ADT Dictionary A Directory of Telephone.
© 2011 Pearson Addison-Wesley. All rights reserved 11 B-1 Chapter 11 (continued) Trees.
© 2006 Pearson Addison-Wesley. All rights reserved12 A-1 Chapter 12 Tables and Priority Queues.
Chapter 18 Java Collections Framework
COSC2007 Data Structures II Chapter 12 Tables & Priority Queues I.
Searching Chapter 18 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Tree Implementations Chapter 16 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 11 B Trees. © 2004 Pearson Addison-Wesley. All rights reserved 11 B-2 The ADT Binary Search Tree A deficiency of the ADT binary tree which is.
Hashing as a Dictionary Implementation Chapter 19.
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
The ADT Table The ADT table, or dictionary Uses a search key to identify its items Its items are records that contain several pieces of data 2 Figure.
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
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.
Chapter 12 Heaps & HeapSort © John Urrutia 2014, All Rights Reserved1.
Intro. to Data Structures Chapter 6 Priority Queue (Heap) Veera Muangsin, Dept. of Computer Engineering, Chulalongkorn University 1 Priority Queue.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
CSI 312 Dr. Yousef Qawqzeh Heaps and Priority Queue.
Queue, Deque, and Priority Queue Implementations Chapter 23.
Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Sorted Lists Chapter Chapter Contents Specifications for the ADT Sorted List Using the ADT Sorted List A Linked Implementation The Method add The.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Objectives Upon completion you will be able to: Explain the design, use, and operation of a linear.
CS Data Structures Chapter 8 Lists Mehmet H Gunes
A Bag Implementation that Links Data
List Implementations Chapter 9.
List Implementations that Use Arrays
List Implementations that Use Arrays
Presentation transcript:

Dictionary Implementations Chapter 18

2 Chapter Contents Array-Based Implementations The Entries An Unsorted Array-Based Dictionary A Sorted Array-Based Dictionary Vector-Based Implementation Linked Implementations The Entries An Unsorted Linked Dictionary A Sorted Linked Dictionary

3 Array Based Implementations Each entry consists of two parts A search key A value Strategies Encapsulate the two parts into an object Use two parallel arrays Use a two dimensional array Text focuses on first approach

4 Array-Based Implementations Fig ways to use arrays to represent dictionary entries: (a) an array of entry objects; (b) parallel arrays of search keys and values; (c) 2-dimensional array of search keys and values

5 The Entries A class to represent the two-part entries private class Entry implements java.io.Serializable {private Object key;private Object value; private Entry(Object searchKey, Object dataValue) {key = searchKey; value = dataValue; } // end constructor private Object getKey() {return key;} // end getKey private Object getValue()} {return value;} // end getValue private void setValue(Object dataValue) {value = dataValue;} // end setValue } // end Entry

6 Unsorted Array-Based Dictionary Fig Unsorted, array-based dictionary: (a) adding an entry; (b) removing an entry.

7 Array-Based Implementations Unsorted worst-case efficiencies Addition O(1) Removal O(n) Retrieval O(n) Traversal O(n) Sorted worst-case efficiencies Addition O(n) Removal O(n) Retrieval O(log n) Traversal O(n)

8 Sorted Array-Based Dictionary Fig Adding an entry to a sorted array-based dictionary: (a) search; (b) make room; (c) insert.

9 Sorted Array-Based Dictionary Beginning of the class public class SortedArrayDictionary implements DictionaryInterface, java.io.Serializable {private Entry [] entries;// array of sorted entries private int currentSize = 0; // number of entries private final static int DEFAULT_MAX_SIZE = 25; public SortedArrayDictionary() {entries = new Entry[DEFAULT_MAX_SIZE]; currentSize = 0; } // end default constructor public SortedArrayDictionary(int maxSize) {entries = new Entry[maxSize]; currentSize = 0; } // end constructor...

10 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 Downside Requires some involved casts

11 Vector-Based Implementations Beginning of the class public class SortedVectorDictionary implements DictionaryInterface, java.io.Serializable {private Vector entries; public SortedVectorDictionary() {entries = new Vector();// as needed, vector doubles its size } // end default constructor public SortedVectorDictionary(int maxSize) {entries = new Vector(maxSize); } // end constructor...

12 Linked Implementations Fig a) Could use a chain of nodes that each reference an entry object

13 Linked Implementations Fig b) Use parallel chains of search keys and values figure 18-4 a & b

14 Linked Implementations Fig c) Use a chain of nodes that each reference a search key and value figure 18-4 c

15 Linked Implementations Unsorted worst-case efficiencies Addition O(1) Removal O(n) Retrieval O(n) Traversal O(n) Sorted worst-case efficiencies Addition O(n) Removal O(n) Retrieval O(n) Traversal O(n)

16 Linked Implementations Fig Adding to an unsorted linked dictionary.