CO4301 – Advanced Games Development Week 12 Using Trees

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

Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 19 - basic definitions - order statistics ( findkth( ) ) - balanced binary search trees - Java implementations Binary Search Trees 1CSCI 3333 Data.
FEN 2012UCN Technology - Computer Science 1 Data Structures and Collections Principles revisited.NET: –Two libraries: System.Collections System.Collections.Generics.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Week 6 - Friday.  What did we talk about last time?  Recursive running time  Fast exponentiation  Merge sort  Introduced the Master theorem.
111 © 2002, Cisco Systems, Inc. All rights reserved.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (continued) Advanced Implementation of Tables.
TECH Computer Science Dynamic Sets and Searching Analysis Technique  Amortized Analysis // average cost of each operation in the worst case Dynamic Sets.
Indexing and hashing Azita Keshmiri CS 157B. Basic concept An index for a file in a database system works the same way as the index in text book. For.
Advanced Data Structure By Kayman 21 Jan Outline Review of some data structures Array Linked List Sorted Array New stuff 3 of the most important.
Week 9 - Monday.  What did we talk about last time?  Practiced with red-black trees  AVL trees  Balanced add.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –
1 Principles revisited.NET: Two libraries: System.Collections System.Collections.Generics Data Structures and Collections.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
STL Associative Containers navigating by key. Pair Class aggregates values of two, possibly different, types used in associative containers defined in.
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
FALL 2005CENG 213 Data Structures1 Review. FALL 2005CENG 213 Data Structures2 Collection of items Problems that must manage data by value. Some important.
Algorithms Design Fall 2016 Week 6 Hash Collusion Algorithms and Binary Search Trees.
Dictionaries Collection of items. Each item is a pair. (key, element)
Introduction toData structures and Algorithms
Sections 10.5 – 10.6 Hashing.
COMP261 Lecture 23 B Trees.
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
CSE 214 – Computer Science II Maps
Design & Analysis of Algorithm Map
CO4301 – Advanced Games Development Week 11 AVL Trees
Week 7 - Friday CS221.
October 2nd – Dictionary ADT
Azita Keshmiri CS 157B Ch 12 indexing and hashing
CSCI 210 Data Structures and Algorithms
Efficiency of in Binary Trees
Data Abstraction & Problem Solving with C++
CO4301 – Advanced Games Development Week 10 Red-Black Trees continued
Data Structures and Analysis (COMP 410)
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
Cse 373 April 26th – Exam Review.
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:
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.
structures and their relationships." - Linus Torvalds
Advanced Associative Structures
Hash Table.
Chapter 15 Lists Objectives
structures and their relationships." - Linus Torvalds
Chapter 6 Transform and Conquer.
Sidharth Mishra Dr. T.Y. Lin CS 257 Section 1 MH 222 SJSU - Fall 2016
Chapter 21 Hashing: Implementing Dictionaries and Sets
Dictionaries and Their Implementations
Indexing and Hashing Basic Concepts Ordered Indices
Ordered Maps & Dictionaries
CSE 373: Data Structures and Algorithms
Recitation Outline C++ STL associative containers Examples
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Chapter 6: Transform and Conquer
CSE 373, Copyright S. Tanimoto, 2002 Hashing -
CS202 - Fundamental Structures of Computer Science II
Binary Trees: Motivation
One-Pass Algorithms for Database Operations (15.2)
Advanced Implementation of Tables
Advanced Implementation of Tables
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
How to use hash tables to solve olympiad problems
CO4301 – Advanced Games Development Week 4 Binary Search Trees
CSE 326: Data Structures Lecture #14
structures and their relationships." - Linus Torvalds
Week 6 - Monday CS221.
CSE 373: Data Structures and Algorithms
Presentation transcript:

CO4301 – Advanced Games Development Week 12 Using Trees Gareth Bellaby

Set A set is an Abstract Data Type (ADT). It's an implementation of a finite set. A collection of unique objects. Each object only occurs once. Sets are unordered. (In practice we'll order them for the sake of efficiency)

Set There are a number of operations associated with sets. The most important are: union. The join of two sets. intersection. The overlap of two sets. But it'll be useful to have: difference. The set of objects in A, which are not in B. subset. size filter

Implementation Consider how we could possibly implement a set. Need to store the set. Need efficient implementation of operations such as union: combine set A and set B, setting aside duplicates. Note that an efficient implementation might well reuse the existing structures rather than create a brand new third one.

Implementation Underlying this would be efficient implementations of Add (Insert): Traverse the objects and if not found then insert into the set (using whatever method). Delete (Remove) Search (Lookup) Modify (Replace) But also the general maintenance of the structure

List List (start with unordered) Straightforward but inefficient. Why?

Ordered list Ordered list Better. Use something like insertion sort. Could build custom structure which similarly sorts as it's built. Search using binary search, for example. Search is good, but obvious problems with insertion and deletion, e.g. insert at beginning of array. Requires moving all of the other items along if using an array.

Linked List Linked List Insertion at the beginning of the list (or end with doubly linked list), but again obvious limitations are traversal.

Tree Tree Binary search tree No restrictions on it becoming unbalanced. Hence can degenerate into the equivalent of an ordered list.

Map The ADP of an associative array. Collection of (key,value) pairs. Each key is unique (so obvious link with sets) Each node contains a key and a value. Obviously the value could be a link to larger data set.

Dictionary Problem A map is a of a general problem in computer science called the Dictionary Problem How to store data which, like a dictionary, has a key and a value. In a dictionary the key is the word, and the value is the definition of the word. Databases

Approaches Efficient data structure to implement search, delete and insert operations. Two main possibilities: Hash tables Trees These are both efficient solutions to the dictionary problem.

Hash table Hash table is good. Chained or open access both provide reasonable approaches. It does have the problem of a worst case scenario, e.g. in chained hash table, all entries hashed to a single bucket and therefore degenerates to a linked list.

Hash table However, generally a hash table does not approach a worst case condition. The average time for a tree is slower than a comparable hash table because the operations need to maintain the self-balancing properties of the tree are slower than the probing operations or linked list costs associated with hash tables.

Choice Often a pragmatic decision, but can give some advice. Hash table probably results in fewer reads. Need an efficient hash function. May be difficult or time consuming. Patterns of data.

Choice Hash misses may cause a problem if the implementation requires a consistent time. Degradation of performance is better in a BST than a hash table, e.g. doesn’t the potential catastrophic or rapid-fall in performance that a hash table has.

Choice Hash tables are unordered data. BST are ordered data. Imagine wanting to retrieve the data in an ordered fashion.

Choice BST may pack the data together better. Better if interested in a range of objects. Trees allow very easily for subtrees and hence ranges of values. No equivalence in hash tables. Allows access to other operations such as “closest match”, cf. closest points next week.

Choice Possible to combine the two, e.g. index the hash table using a BST.

Considerations The STL set, map, multiset, and multimap are generally built using a red-black tree. Search trees Open list for directed search

Tree unification Identifying whether one tree is the same as a another tree Can be used for solving equations or logic statements. Consider a tree representing an equation. If one tree can be considered to be the same as another, then the equations are equivalent.