Presentation is loading. Please wait.

Presentation is loading. Please wait.

CO4301 – Advanced Games Development Week 12 Using Trees

Similar presentations


Presentation on theme: "CO4301 – Advanced Games Development Week 12 Using Trees"— Presentation transcript:

1 CO4301 – Advanced Games Development Week 12 Using Trees
Gareth Bellaby

2 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)

3 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

4 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.

5 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

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

7 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.

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

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

10 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.

11 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

12 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.

13 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.

14 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.

15 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.

16 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.

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

18 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.

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

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

21 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.


Download ppt "CO4301 – Advanced Games Development Week 12 Using Trees"

Similar presentations


Ads by Google