Tables and Priority Queues!

Similar documents
Tables and Priority Queues

ADT Priority Queue. Heaps. A Heap Implementation of the ADT Priority Queue. Heapsort

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

Tables and Priority Queues

CS200: Tables and Priority Queues

Tables, Priority Queues, Heaps

4/3/13. Outline. Part 7. Tables and Priority Queues. Value Oriented Data Structures. Example: Table of Student Points. Table ADT.

Outline. Part 7. Tables and Priority Queues. Example: Table of Student Points. Value Oriented Data Structures. Table ADT. Search Keys 4/2/12

" Which data Structure to extend to create a heap? " Two binary tree extensions are needed in a heap. n it is a binary tree (a complete one)

Priority Queue. How to implement a Priority Queue? queue. priority queue

PROGRAMMING II ABSTRACT DATA TYPES Unassessed Coursework 4: Binary Search Trees and Heaps

CS200: Balanced Search Trees

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

CS302 - Data Structures using C++

The smallest element is the first one removed. (You could also define a largest-first-out priority queue)

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

CSC 321: Data Structures. Fall 2016

CSC 321: Data Structures. Fall 2017

CS165: Priority Queues, Heaps

CS200 Midterm 2 Fall 2007

Algorithms and Data Structures

Heaps & Priority Queues. (Walls & Mirrors - Remainder of Chapter 11)

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology

CSE 214 Computer Science II Heaps and Priority Queues

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

Priority Queues Heaps Heapsort

Priority Queues Heaps Heapsort

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

EXAMINATIONS 2016 TRIMESTER 2

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Java collections framework

CS106X Programming Abstractions in C++ Dr. Cynthia Bailey Lee

Java collections framework

Priority Queues. 04/10/03 Lecture 22 1

The heap is essentially an array-based binary tree with either the biggest or smallest element at the root.

WITH SOLUTIONS!!! WARNING: THIS COPY CONTAINS SOLUTIONS!!! COMP103 Introduction to Data Structures and Algorithms

9. Heap : Priority Queue

Motivation Computer Information Systems Storage Retrieval Updates. Binary Search Trees. OrderedStructures. Binary Search Tree

Programming II (CS300)

EXAMINATIONS 2017 TRIMESTER 2

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

****** NOTE!! THIS CONTAINS SOLUTIONS ***** TRIMESTER 2

Sets and Maps. Part of the Collections Framework

Lecture 13: AVL Trees and Binary Heaps

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

Topics for CSCI 151 Final Exam Wednesday, May 10

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

Heaps. Heaps. A heap is a complete binary tree.

Priority queues. Priority queues. Priority queue operations

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

CONTAINS SOLUTIONS!!!

EXAMINATIONS 2010 END YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

Abstract Data Types Spring 2018 Exam Prep 5: February 12, 2018

CMSC 202H. Containers and Iterators

INFO1x05 Tutorial 6. Exercise 1: Heaps and Priority Queues

Heaps and Priority Queues

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

Priority Queues. Lecture15: Heaps. Priority Queue ADT. Sequence based Priority Queue

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum

Priority Queues. e.g. jobs sent to a printer, Operating system job scheduler in a multi-user environment. Simulation environments

2. Instance simplification Solve a problem s instance by transforming it into another simpler/easier instance of the same problem

ITI Introduction to Computing II

Programming II (CS300)

Terminology. The ADT Binary Tree. The ADT Binary Search Tree

CSE 2123: Collections: Priority Queues. Jeremy Morris

Sorting. Two types of sort internal - all done in memory external - secondary storage may be used

ITI Introduction to Computing II

Exam Data structures DIT960/DAT036

Collections Framework: Part 2

Topics Recursive Sorting Algorithms Divide and Conquer technique An O(NlogN) Sorting Alg. using a Heap making use of the heap properties STL Sorting F

Lecture Topics. Object Structures. Hierarchical Organization. Tree Concepts. Hierarchical Organization. Hierarchical Organization

CS200 Final Exam Fall 2007

Lecture 7. Transform-and-Conquer

Sorting. Task Description. Selection Sort. Should we worry about speed?

COMP 250 Midterm #2 March 11 th 2013

CS 310 Advanced Data Structures and Algorithms

CMSC 341 Lecture 14: Priority Queues, Heaps

Data Structures and Algorithms

ECE 242 Data Structures and Algorithms. Heaps I. Lecture 22. Prof. Eric Polizzi

27/04/2012. Objectives. Collection. Collections Framework. "Collection" Interface. Collection algorithm. Legacy collection

Priority Queues and Huffman Trees

Priority Queues and Binary Heaps

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

CSC Design and Analysis of Algorithms. Lecture 8. Transform and Conquer II Algorithm Design Technique. Transform and Conquer

CS 234. Module 8. November 15, CS 234 Module 8 ADT Priority Queue 1 / 22

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 PRACTICE EXAM

Readings. Priority Queue ADT. FindMin Problem. Priority Queues & Binary Heaps. List implementation of a Priority Queue

Algorithm Efficiency & Sorting. Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms

Trees 1: introduction to Binary Trees & Heaps. trees 1

Algorithms and Data Structures

Priority Queues. Chapter 9

Algorithm Analysis Advanced Data Structure. Chung-Ang University, Jaesung Lee

CH 8. HEAPS AND PRIORITY QUEUES

Java Collections. Readings and References. Collections Framework. Java 2 Collections. References. CSE 403, Winter 2003 Software Engineering

Generics Collection Framework

CH. 8 PRIORITY QUEUES AND HEAPS

CMSC 341 Priority Queues & Heaps. Based on slides from previous iterations of this course

Model Solutions. COMP 103: Test April, 2013

Transcription:

Chapter 12! Tables and Priority Queues! 2011 Pearson Addison-Wesley. All rights reserved 12 A-1 2015-11-30 21:52:31 1/49 Chapter-12.pdf (#14)

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! Figure 12-1 An ordinary table of cities 2011 Pearson Addison-Wesley. All rights reserved 12 A-2 2015-11-30 21:52:31 2/49 Chapter-12.pdf (2/49)

The ADT Table Operations of the ADT table! Create an empty table! Determine whether a table is empty! Determine the number of items in a table! Insert a new item into a table! Delete the item with a given search key from a table! Retrieve the item with a given search key from a table! Traverse the items in a table in sorted search-key order! 2011 Pearson Addison-Wesley. All rights reserved 12 A-3 2015-11-30 21:52:31 3/49 Chapter-12.pdf (3/49)

The ADT Table Pseudocode for the operations of the ADT table! createtable() // Creates an empty table. tableisempty() // Determines whether a table is empty. tablelength() // Determines the number of items in a table. tableinsert(newitem) throws TableException // Inserts newitem into a table whose items have // distinct search keys that differ from newitem s // search key. Throws TableException if the // insertion is not successful 2011 Pearson Addison-Wesley. All rights reserved 12 A-4 2015-11-30 21:52:31 4/49 Chapter-12.pdf (4/49)

The ADT Table Pseudocode for the operations of the ADT table (Continued)! tabledelete(searchkey) // Deletes from a table the item whose search key // equals searchkey. Returns false if no such item // exists. Returns true if the deletion was // successful. tableretrieve(searchkey) // Returns the item in a table whose search key // equals searchkey. Returns null if no such item // exists. tabletraverse() // Traverses a table in sorted search-key order. 2011 Pearson Addison-Wesley. All rights reserved 12 A-5 2015-11-30 21:52:31 5/49 Chapter-12.pdf (5/49)

The ADT Table Value of the search key for an item must remain the same as long as the item is stored in the table! KeyedItem class! Contains an item s search key and a method for accessing the search-key data field! Prevents the search-key value from being modified once an item is created! TableInterface interface! Defines the table operations! 2011 Pearson Addison-Wesley. All rights reserved 12 A-6 2015-11-30 21:52:31 6/49 Chapter-12.pdf (6/49)

Selecting an Implementation Categories of linear implementations! Unsorted, array based! Unsorted, referenced based! Sorted (by search key), array based! Sorted (by search key), reference based! Figure 12-3 The data fields for two sorted linear implementations of the ADT table for the data in Figure 12-1: a) array based; b) reference based 2011 Pearson Addison-Wesley. All rights reserved 12 A-7 2015-11-30 21:52:31 7/49 Chapter-12.pdf (7/49)

Selecting an Implementation A binary search implementation!! A nonlinear implementation! Figure 12-4 The data fields for a binary search tree implementation of the ADT table for the data in Figure 12-1 2011 Pearson Addison-Wesley. All rights reserved 12 A-8 2015-11-30 21:52:31 8/49 Chapter-12.pdf (8/49)

Selecting an Implementation The binary search tree implementation offers several advantages over linear implementations! The requirements of a particular application influence the selection of an implementation! Questions to be considered about an application before choosing an implementation! What operations are needed?! How often is each operation required?! 2011 Pearson Addison-Wesley. All rights reserved 12 A-9 2015-11-30 21:52:31 9/49 Chapter-12.pdf (9/49)

Scenario A: Insertion and Traversal in No Particular Order An unsorted order in efficient! Both array based and reference based tableinsert operation is O(1)! Array based versus reference based! If a good estimate of the maximum possible size of the table is not available! Reference based implementation is preferred! If a good estimate of the maximum possible size of the table is available! The choice is mostly a matter of style! 2011 Pearson Addison-Wesley. All rights reserved 12 A-10 2015-11-30 21:52:31 10/49 Chapter-12.pdf (10/49)

Scenario A: Insertion and Traversal in No Particular Order Figure 12-5 Insertion for unsorted linear implementations: a) array based; b) reference based 2011 Pearson Addison-Wesley. All rights reserved 12 A-11 2015-11-30 21:52:32 11/49 Chapter-12.pdf (11/49)

Scenario A: Insertion and Traversal in No Particular Order A binary search tree implementation is not appropriate! It does more work than the application requires! It orders the table items! The insertion operation is O(log n) in the average case!! 2011 Pearson Addison-Wesley. All rights reserved 12 A-12 2015-11-30 21:52:32 12/49 Chapter-12.pdf (12/49)

Scenario B: Retrieval Binary search! An array-based implementation! Binary search can be used if the array is sorted! A reference-based implementation! Binary search can be performed, but is too inefficient to be practical! A binary search of an array is more efficient than a sequential search of a linked list! Binary search of an array! Worst case: O(log 2 n)! Sequential search of a linked list! O(n)! 2011 Pearson Addison-Wesley. All rights reserved 12 A-13 2015-11-30 21:52:32 13/49 Chapter-12.pdf (13/49)

Scenario B: Retrieval For frequent retrievals! If the table s maximum size is known! A sorted array-based implementation is appropriate! If the table s maximum size is not known! A binary search tree implementation is appropriate! 2011 Pearson Addison-Wesley. All rights reserved 12 A-14 2015-11-30 21:52:32 14/49 Chapter-12.pdf (14/49)

Scenario C: Insertion, Deletion, Retrieval, and Traversal in Sorted Order Steps performed by both insertion and deletion! Step 1: Find the appropriate position in the table! Step 2: Insert into (or delete from) this position! Step 1! An array-based implementation is superior than a reference-based implementation! Step 2! A reference-based implementation is superior than an array-based implementation! A sorted array-based implementation shifts data during insertions and deletions! 2011 Pearson Addison-Wesley. All rights reserved 12 A-15 2015-11-30 21:52:32 15/49 Chapter-12.pdf (15/49)

Scenario C: Insertion, Deletion, Retrieval, and Traversal in Sorted Order Figure 12-6 Insertion for sorted linear implementations: a) array based; b) reference based 2011 Pearson Addison-Wesley. All rights reserved 12 A-16 2015-11-30 21:52:32 16/49 Chapter-12.pdf (16/49)

Scenario C: Insertion, Deletion, Retrieval, and Traversal in Sorted Order Insertion and deletion operations! Both sorted linear implementations are comparable, but neither is suitable! tableinsert and tabledelete operations! Sorted array-based implementation is O(n)! Sorted reference-based implementation is O(n)! Binary search tree implementation is suitable! It combines the best features of the two linear implementations! 2011 Pearson Addison-Wesley. All rights reserved 12 A-17 2015-11-30 21:52:32 17/49 Chapter-12.pdf (17/49)

A Sorted Array-Based Implementation of the ADT Table Linear implementations! Useful for many applications despite certain difficulties! A binary search tree implementation! In general, can be a better choice than a linear implementation! A balanced binary search tree implementation! Increases the efficiency of the ADT table operations! 2011 Pearson Addison-Wesley. All rights reserved 12 A-18 2015-11-30 21:52:32 18/49 Chapter-12.pdf (18/49)

A Sorted Array-Based Implementation of the ADT Table Figure 12-7 The average-case order of the operations of the ADT table for various implementations 2011 Pearson Addison-Wesley. All rights reserved 12 A-19 2015-11-30 21:52:32 19/49 Chapter-12.pdf (19/49)

A Sorted Array-Based Implementation of the ADT Table Reasons for studying linear implementations! Perspective! Efficiency! Motivation! TableArrayBased class Provides an array-based implementation of the ADT table! Implements TableInterface! 2011 Pearson Addison-Wesley. All rights reserved 12 A-20 2015-11-30 21:52:32 20/49 Chapter-12.pdf (20/49)

A Binary Search Tree Implementation of the ADT Table TableBSTBased class! Represents a nonlinear reference-based implementation of the ADT table! Uses a binary search tree to represent the items in the ADT table! Reuses the class BinarySearchTree 2011 Pearson Addison-Wesley. All rights reserved 12 A-21 2015-11-30 21:52:32 21/49 Chapter-12.pdf (21/49)

The ADT Priority Queue: A Variation of the ADT Table The ADT priority queue! Orders its items by a priority value! The first item removed is the one having the highest priority value! Operations of the ADT priority queue! Create an empty priority queue! Determine whether a priority queue is empty! Insert a new item into a priority queue! Retrieve and then delete the item in a priority queue with the highest priority value! 2011 Pearson Addison-Wesley. All rights reserved 12 B-22 2015-11-30 21:52:32 22/49 Chapter-12.pdf (22/49)

The ADT Priority Queue: A Variation of the ADT Table Pseudocode for the operations of the ADT priority queue! createpqueue() // Creates an empty priority queue. pqisempty() // Determines whether a priority queue is // empty. 2011 Pearson Addison-Wesley. All rights reserved 12 B-23 2015-11-30 21:52:33 23/49 Chapter-12.pdf (23/49)

The ADT Priority Queue: A Variation of the ADT Table Pseudocode for the operations of the ADT priority queue (Continued)! pqinsert(newitem) throws PQueueException // Inserts newitem into a priority queue. // Throws PQueueException if priority queue is // full. pqdelete() // Retrieves and then deletes the item in a // priority queue with the highest priority // value. 2011 Pearson Addison-Wesley. All rights reserved 12 B-24 2015-11-30 21:52:33 24/49 Chapter-12.pdf (24/49)

The ADT Priority Queue: A Variation of the ADT Table Possible implementations! Sorted linear implementations! Appropriate if the number of items in the priority queue is small! Array-based implementation! Maintains the items sorted in ascending order of priority value! Reference-based implementation! Maintains the items sorted in descending order of priority value! 2011 Pearson Addison-Wesley. All rights reserved 12 B-25 2015-11-30 21:52:33 25/49 Chapter-12.pdf (25/49)

The ADT Priority Queue: A Variation of the ADT Table Figure 12-9a and 12-9b Some implementations of the ADT priority queue: a) array based; b) reference based 2011 Pearson Addison-Wesley. All rights reserved 12 B-26 2015-11-30 21:52:33 26/49 Chapter-12.pdf (26/49)

The ADT Priority Queue: A Variation of the ADT Table Possible implementations (Continued)! Binary search tree implementation! Appropriate for any priority queue! Figure 12-9c Some implementations of the ADT priority queue: c) binary search tree 2011 Pearson Addison-Wesley. All rights reserved 12 B-27 2015-11-30 21:52:33 27/49 Chapter-12.pdf (27/49)

Heaps A heap is a complete binary tree! That is empty!!or! Whose root contains a search key greater than or equal to the search key in each of its children, and! Whose root has heaps as its subtrees! 2011 Pearson Addison-Wesley. All rights reserved 12 B-28 2015-11-30 21:52:33 28/49 Chapter-12.pdf (28/49)

Heaps Maxheap! A heap in which the root contains the item with the largest search key! Minheap! A heap in which the root contains the item with the smallest search key! 2011 Pearson Addison-Wesley. All rights reserved 12 B-29 2015-11-30 21:52:33 29/49 Chapter-12.pdf (29/49)

Heaps Pseudocode for the operations of the ADT heap! createheap() // Creates an empty heap. heapisempty() // Determines whether a heap is empty. heapinsert(newitem) throws HeapException // Inserts newitem into a heap. Throws // HeapException if heap is full. heapdelete() // Retrieves and then deletes a heap s root // item. This item has the largest search key. 2011 Pearson Addison-Wesley. All rights reserved 12 B-30 2015-11-30 21:52:33 30/49 Chapter-12.pdf (30/49)

Heaps: An Array-based Implementation of a Heap Data fields! items: an array of heap items! size: an integer equal to the number of items in the heap! Figure 12-11 A heap with its array representation 2011 Pearson Addison-Wesley. All rights reserved 12 B-31 2015-11-30 21:52:33 31/49 Chapter-12.pdf (31/49)

Heaps: heapdelete Step 1: Return the item in the root! Results in disjoint heaps! Figure 12-12a a) Disjoint heaps 2011 Pearson Addison-Wesley. All rights reserved 12 B-32 2015-11-30 21:52:33 32/49 Chapter-12.pdf (32/49)

Heaps: heapdelete Step 2: Copy the item from the last node into the root! Results in a semiheap! Figure 12-12b b) a semiheap 2011 Pearson Addison-Wesley. All rights reserved 12 B-33 2015-11-30 21:52:33 33/49 Chapter-12.pdf (33/49)

Heaps: heapdelete Step 3: Transform the semiheap back into a heap! Performed by the recursive algorithm heaprebuild Figure 12-14 Recursive calls to heaprebuild 2011 Pearson Addison-Wesley. All rights reserved 12 B-34 2015-11-30 21:52:34 34/49 Chapter-12.pdf (34/49)

Heaps: heapdelete Efficiency! heapdelete is O(log n)! Figure 12-13 Deletion from a heap 2011 Pearson Addison-Wesley. All rights reserved 12 B-35 2015-11-30 21:52:34 35/49 Chapter-12.pdf (35/49)

Heaps: heapinsert Strategy! Insert newitem into the bottom of the tree! Trickle new item up to appropriate spot in the tree! Efficiency: O(log n)! Heap class! Represents an array-based implementation of the ADT heap! Figure 12-15 Insertion into a heap 2011 Pearson Addison-Wesley. All rights reserved 12 B-36 2015-11-30 21:52:34 36/49 Chapter-12.pdf (36/49)

A Heap Implementation of the ADT Priority Queue Priority-queue operations and heap operations are analogous! The priority value in a priority-queue corresponds to a heap item s search key! PriorityQueue class! Has an instance of the Heap class as its data field! 2011 Pearson Addison-Wesley. All rights reserved 12 B-37 2015-11-30 21:52:34 37/49 Chapter-12.pdf (37/49)

A Heap Implementation of the ADT Priority Queue A heap implementation of a priority queue! Disadvantage! Requires the knowledge of the priority queue s maximum size! Advantage! A heap is always balanced! Finite, distinct priority values! A heap of queues! Useful when a finite number of distinct priority values are used, which can result in many items having the same priority value! 2011 Pearson Addison-Wesley. All rights reserved 12 B-38 2015-11-30 21:52:34 38/49 Chapter-12.pdf (38/49)

Heapsort Strategy! Transforms the array into a heap! Removes the heap's root (the largest element) by exchanging it with the heap s last element! Transforms the resulting semiheap back into a heap! Efficiency! Compared to mergesort! Both heapsort and mergesort are O(n * log n) in both the worst and average cases! Advantage over mergesort! Heapsort does not require a second array! Compared to quicksort! Quicksort is the preferred sorting method! 2011 Pearson Addison-Wesley. All rights reserved 12 B-39 2015-11-30 21:52:34 39/49 Chapter-12.pdf (39/49)

Heapsort Figure 12-16 a) The initial contents of anarray; b) anarray s corresponding binary tree Figure 12-18 Heapsort partitions an array into two regions 2011 Pearson Addison-Wesley. All rights reserved 12 B-40 2015-11-30 21:52:34 40/49 Chapter-12.pdf (40/49)

Tables and Priority Queues in JFC: The JFC Map Interface Map interface! Provides the basis for numerous other implementations of different kinds of maps! public interface Map<K,V> methods! void clear() boolean containskey(object key) boolean containsvalue(object value) Set<Map.Entry<K,V>> entryset() V get(object key); 2011 Pearson Addison-Wesley. All rights reserved 12 B-41 2015-11-30 21:52:34 41/49 Chapter-12.pdf (41/49)

Tables and Priority Queues in JFC: The JFC Map Interface public interface Map<K,V> methods (continued)! boolean isempty() Set<K> keyset() V put(k key, V value) V remove(object key) Collection<V> values() 2011 Pearson Addison-Wesley. All rights reserved 12 B-42 2015-11-30 21:52:34 42/49 Chapter-12.pdf (42/49)

The JFC Set Interface Set interface! Ordered collection! Stores single value entries! Does not allow for duplicate elements! public interface Set<T> methods! boolean add(t o) boolean addall(collection<? extends T> c) void clear() boolean contains(object o) boolean isempty() 2011 Pearson Addison-Wesley. All rights reserved 12 B-43 2015-11-30 21:52:35 43/49 Chapter-12.pdf (43/49)

The JFC Set Interface public interface Set<T> methods (continued)! Iterator<T> iterator() boolean remove(object o) boolean removeall(collection<?> c) boolean retainall(collection<?> c) int size() 2011 Pearson Addison-Wesley. All rights reserved 12 B-44 2015-11-30 21:52:35 44/49 Chapter-12.pdf (44/49)

The JFC PriorityQueue Class PriorityQueue class! Has a single data-type parameter with ordered elements! Relies on the natural ordering of the elements! As provided by the Comparable interface or a Comparator object! Elements in queue are ordered in ascending order! public Class PriorityQueue<T> methods! PriorityQueue(int initialcapacity) PriorityQueue(int initialcapacity, Comparator<? super T> comparator) boolean add(t o) void clear() boolean contains(object o) 2011 Pearson Addison-Wesley. All rights reserved 12 B-45 2015-11-30 21:52:35 45/49 Chapter-12.pdf (45/49)

The JFC PriorityQueue Class public Class PriorityQueue<T> methods (continued)! Comparator<? super T> comparator() T element() Iterator<T> iterator() boolean offer(t o) T peek() T poll() boolean remove(object o) int size() 2011 Pearson Addison-Wesley. All rights reserved 12 B-46 2015-11-30 21:52:35 46/49 Chapter-12.pdf (46/49)

Summary The ADT table supports value-oriented operations! The linear implementations (array based and reference based) of a table are adequate only in limited situations or for certain operations! A nonlinear reference-based (binary search tree) implementation of the ADT table provides the best aspects of the two linear implementations! A priority queue, a variation of the ADT table, has operations which allow you to retrieve and remove the item with the largest priority value! 2011 Pearson Addison-Wesley. All rights reserved 12 B-47 2015-11-30 21:52:35 47/49 Chapter-12.pdf (47/49)

Summary A heap that uses an array-based representation of a complete binary tree is a good implementation of a priority queue when you know the maximum number of items that will be stored at any one time! Efficiency! Heapsort, like mergesort, has good worst-case and average-case behaviors, but neither algorithms is as good in the average case as quicksort! Heapsort has an advantage over mergesort in that it does not require a second array! 2011 Pearson Addison-Wesley. All rights reserved 12 B-48 2015-11-30 21:52:35 48/49 Chapter-12.pdf (48/49)

Summary Tables and priority queues in JFC! Map interface! Set interface! PriorityQueue class! 2011 Pearson Addison-Wesley. All rights reserved 12 B-49 2015-11-30 21:52:35 49/49 Chapter-12.pdf (49/49)