Dictionaries Collection of items. Each item is a pair.  (key, element)  Pairs have different keys.

Slides:



Advertisements
Similar presentations
The Dictionary ADT Definition A dictionary is an ordered or unordered list of key-element pairs, where keys are used to locate elements in the list. Example:
Advertisements

1 AVL Trees. 2 AVL Tree AVL trees are balanced. An AVL Tree is a binary search tree such that for every internal node v of T, the heights of the children.
Chapter 4: Trees Part II - AVL Tree
Winner trees. Loser Trees.
Selection Trees. What are selection trees? Complete binary tree Each node represents a “match” Winner Trees Loser Trees.
Skip List & Hashing CSE, POSTECH.
Dictionaries Collection of pairs.  (key, element)  Pairs have different keys. Operations.  get(theKey)  put(theKey, theElement)  remove(theKey) 5/2/20151.
Searching Kruse and Ryba Ch and 9.6. Problem: Search We are given a list of records. Each record has an associated key. Give efficient algorithm.
Digital Search Trees & Binary Tries Analog of radix sort to searching. Keys are binary bit strings.  Fixed length – 0110, 0010, 1010,  Variable.
6/14/2015 6:48 AM(2,4) Trees /14/2015 6:48 AM(2,4) Trees2 Outline and Reading Multi-way search tree (§3.3.1) Definition Search (2,4)
Binary Search Trees Dictionary Operations:  IsEmpty()  Search(key)  Insert(key, value)  Delete(key)
Dynamic Dictionaries Primary Operations:  Get(key) => search  Insert(key, element) => insert  Delete(key) => delete Additional operations:  Ascend()
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
© 2004 Goodrich, Tamassia (2,4) Trees
Binary Search Trees CSE, POSTECH. Search Trees Search trees are ideal for implementing dictionaries – Similar or better performance than skip lists and.
1 BST Trees A binary search tree is a binary tree in which every node satisfies the following: the key of every node in the left subtree is.
Chapter 61 Chapter 6 Index Structures for Files. Chapter 62 Indexes Indexes are additional auxiliary access structures with typically provide either faster.
Chapter 19 - basic definitions - order statistics ( findkth( ) ) - balanced binary search trees - Java implementations Binary Search Trees 1CSCI 3333 Data.
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
ADT Table and Heap Ellen Walker CPSC 201 Data Structures Hiram College.
© 2011 Pearson Addison-Wesley. All rights reserved 11 B-1 Chapter 11 (continued) Trees.
Dictionaries Collection of pairs.  (key, element)  Pairs have different keys. Operations.  get(theKey)  put(theKey, theElement)  remove(theKey)
Dictionaries Collection of pairs.  (key, element)  Pairs have different keys  E.g. a pair contains two components, student id and name (1234, Nan)
Balanced Binary Search Tree 황승원 Fall 2010 CSE, POSTECH.
CSCE 3110 Data Structures & Algorithm Analysis AVL Trees Reading: Chap. 4, Weiss.
Binary Search Tree 황승원 Fall 2011 CSE, POSTECH 2 2 Search Trees Search trees are ideal for implementing dictionaries – Similar or better performance than.
Binary SearchTrees [CLRS] – Chap 12. What is a binary tree ? A binary tree is a linked data structure in which each node is an object that contains following.
Binary Search Trees (10.1) CSE 2011 Winter November 2015.
Lec 15 Oct 18 Binary Search Trees (Chapter 5 of text)
Static Dictionaries Collection of items. Each item is a pair.  (key, element)  Pairs have different keys. Operations are:  initialize/create  get (search)
Fall 2006 CSC311: Data Structures 1 Chapter 10: Search Trees Objectives: Binary Search Trees: Search, update, and implementation AVL Trees: Properties.
© 2006 Pearson Education Chapter 10: Non-linear Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
3.1. Binary Search Trees   . Ordered Dictionaries Keys are assumed to come from a total order. Old operations: insert, delete, find, …
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
David Stotts Computer Science Department UNC Chapel Hill.
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
CIS 068 Welcome to CIS 068 ! Lesson 12: Data Structures 3 Trees.
SNU IDB Lab. Ch 15. Binary Search Trees © copyright 2006 SNU IDB Lab.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Lecture 10COMPSCI.220.FS.T Binary Search Tree BST converts a static binary search into a dynamic binary search allowing to efficiently insert and.
Dictionaries Collection of pairs.  (key, element)  Pairs have different keys. Operations.  find(theKey)  erase(theKey)  insert(theKey, theElement)
Binary Search Trees Dictionary Operations:  get(key)  put(key, value)  remove(key) Additional operations:  ascend()  get(index) (indexed binary search.
Dynamic Dictionaries Primary Operations:  get(key) => search  put(key, element) => insert  remove(key) => delete Additional operations:  ascend()
Binary Search Trees Dictionary Operations:  search(key)  insert(key, value)  delete(key) Additional operations:  ascend()  IndexSearch(index) (indexed.
Winner trees. Loser Trees.
1 the BSTree class  BSTreeNode has same structure as binary tree nodes  elements stored in a BSTree are a key- value pair  must be a class (or a struct)
Dictionaries Collection of items. Each item is a pair. (key, element)
Multiway Search Trees Data may not fit into main memory
Homework will be announced soon Midterm exam date announced
Binary Search Trees (10.1) CSE 2011 Winter August 2018.
Multiway search trees and the (2,4)-tree
Best-fit bin packing in O(n log n) time
Binary Search Tree Chapter 10.
Dynamic Dictionaries Primary Operations: Additional operations:
Binary Search Trees Dictionary Operations: Additional operations:
Chapter 10: Non-linear Data Structures
The Dictionary ADT Definition A dictionary is an ordered or unordered list of key-element pairs, where keys are used to locate elements in the list. Example:
Advanced Associative Structures
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
CS222P: Principles of Data Management Notes #6 Index Overview and ISAM Tree Index Instructor: Chen Li.
Dictionaries Collection of unordered pairs. Operations. (key, element)
Dictionaries Collection of pairs. Operations. (key, element)
(2,4) Trees (2,4) Trees (2,4) Trees.
Dynamic Dictionaries Primary Operations: Additional operations:
(2,4) Trees 2/15/2019 (2,4) Trees (2,4) Trees.
CS222/CS122C: Principles of Data Management Notes #6 Index Overview and ISAM Tree Index Instructor: Chen Li.
(2,4) Trees (2,4) Trees (2,4) Trees.
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #05 Index Overview and ISAM Tree Index Instructor: Chen Li.
Presentation transcript:

Dictionaries Collection of items. Each item is a pair.  (key, element)  Pairs have different keys.

Application Collection of student records in this class.  (key, element) = (student name, linear list of assignment and exam scores)  All keys are distinct. Collection of in-use domain names.  (godaddy.com, owner information)  All keys are distinct.

Dictionary With Duplicates Keys are not required to be distinct. Word dictionary.  Items/pairs are of the form (word, meaning).  May have two or more entries for the same word. (bolt, a threaded pin) (bolt, a crash of thunder) (bolt, to shoot forth suddenly) (bolt, a gulp) (bolt, a standard roll of cloth) etc.

Dictionary Operations Static Dictionary.  initialize/create  get(theKey) (a.k.a. search)  CD ROM word dictionary  CD ROM geographic database of cities, rivers, roads, auto navigation system, etc. Dynamic Dictionary.  get(theKey) (a.k.a. search)  put(theKey, theElement) (a.k.a. insert)  remove(theKey) (a.k.a. delete)

Hash Table Dictionaries O(1) expected time for get, put, and remove. O(n) worst-case time for get, put, and remove.  O(log n) if overflows handled by balanced search trees. Not suitable for nearest match queries.  Get element with smallest key >= theKey. Not suitable for range queries. Not suitable for indexed operations.  Get element with third smallest key.  Remove element with 5 th smallest key.

Bin Packing n items to be packed into bins each item has a size each bin has a capacity of c minimize number of bins

Bin Packing Heuristics Best Fit.  Items are packed one at a time in given order.  To determine the bin for an item, first determine set S of bins into which the item fits.  If S is empty, then start a new bin and put item into this new bin.  Otherwise, pack into bin of S that has least available capacity.

Best Fit Example n = 4 weights = [4, 7, 3, 6] capacity = 10 Pack red item into first bin.

Best Fit n = 4 weights = [4, 7, 3, 6] capacity = 10 Pack blue item next. Doesn’t fit, so start a new bin.

Best Fit n = 4 weights = [4, 7, 3, 6] capacity = 10

Best Fit n = 4 weights = [4, 7, 3, 6] capacity = 10 Pack yellow item into second bin.

Best Fit n = 4 weights = [4, 7, 3, 6] capacity = 10 Pack green item into first bin.

Best Fit n = 4 weights = [4, 7, 3, 6] capacity = 10 Optimal packing.

Implementation Of Best Fit Use a dynamic dictionary (with duplicates) in which the items are of the form (available capacity, bin index). Pack an item whose requirement is s.  Find a bin with smallest available capacity >= s.  Reduce available capacity of this bin by s. May be done by removing old pair and inserting new one.  If no such bin, start a new bin. Insert a new pair into the dictionary.

Best Fit Example 12 active bins. Pack item whose size is

Complexity Of Best Fit Use a balanced binary search tree (with duplicates) in which the pairs are (available capacity, bin index). O(n) get, put, and remove/put operations, where n is the number of items to be packed. O(n log n).

Indexed Binary Search Tree Binary search tree. Each node has an additional field.  leftSize = number of nodes in its left subtree

Example Indexed Binary Search Tree leftSize values are in red

leftSize And Rank Rank of an element is its position in inorder (inorder = ascending key order). [2,6,7,8,10,15,18,20,25,30,35,40] rank(2) = 0 rank(15) = 5 rank(20) = 7 lextSize(x) = rank(x) with respect to elements in subtree rooted at x

leftSize And Rank sorted list = [2,6,7,8,10,15,18,20,25,30,35,40]

get(index) And remove(index) sorted list = [2,6,7,8,10,15,18,20,25,30,35,40]

get(index) And remove(index) if index = x.leftSize desired element is x.element if index < x.leftSize desired element is index’th element in left subtree of x if index > x.leftSize desired element is (index – x.leftSize – 1)’th element in right subtree of x

Linear List As Indexed Binary Tree h e b ad f l j ik c g list = [a,b,c,d,e,f,g,h,i,j,k,l]

Performance Linear List.  get(index)  put(index, element)  remove(index) Array.  O(1), O(n), O(n). Chain.  O(n), O(n), O(n). Indexed AVL Tree (IAVL)  O(log n), O(log n), O(log n).

Experimental Results 40,000 of each operation. Java code on a 350MHz PC

Performance Indexed AVL Tree (IAVL) Operation Array Chain IAVL get 5.6ms 157sec 63ms average puts 5.8sec 115sec 392ms worst-case puts 11.8sec 157sec 544ms average removes 5.8sec 149sec 1.5sec worst-case removes 11.7sec 157sec 1.6sec Time for 40,000 operations

Focus Tree structures for static and dynamic dictionaries.