1 / 33

Main Index

Chapter 12 – Advanced Associative Structures. 1. Main Index. Contents. Binary Search tree, red-black tree, and AVL tree Example Hash Function Open probe addressing Chaining with separate lists (2 slide) Hash Iterator Efficiency of Hash Methods Binary Search Trees

karan
Download Presentation

Main Index

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 12 – Advanced Associative Structures 1 Main Index Contents • Binary Search tree, red-black tree, and AVL tree Example • Hash Function • Open probe addressing • Chaining with separate lists (2 slide) • Hash Iterator • Efficiency of Hash Methods • Binary Search Trees • 2-3-4 Tree (2 slides) • Insertion of 2-3-4 tree (4 slides) • Red-Black Trees • Converting 2-3-4 tree to Red-Black tree • Four Situations in the Splitting of a 4-Node: • left child of a BLACK parent P • prior to inserting node • oriented left-left from G using a single right rotation • oriented left-right from G after the color flip • Building a Red-Black Tree (2 slides) • Red-Black Tree Representation • Summary Slide (8 slides)

  2. 2 Main Index Contents Binary Search Tree, Red-Black Tree and AVL Tree Example

  3. 3 Main Index Contents Example Hash Function

  4. Example Hash Function 4 Main Index Contents

  5. 5 Main Index Contents Hash Table Using Open Probe Addressing Example

  6. Chaining with Separate Lists Example

  7. 7 Main Index Contents Hash Iterator hIter Referencing Element 22 in Table ht

  8. Hash table size = m, Number of elements in hash table = n, Load factor  = Average Probes for Successful Search Average Probes for Unsuccessful Search Open Probe Chaining  8 Main Index Contents Efficiency of Hash Methods

  9. Two Binary Search Tree Example • Insertion sequence: 5, 15, 20, 3, 9, 7, 12, 17, 6, 75, 100, 18, 25, 35, 40

  10. 10 Main Index Contents 2-3-4 Tree Method

  11. 11 Main Index Contents 2-3-4 Tree Example

  12. Example of Insertion of 2-3-4 Tree

  13. 13 Main Index Contents Another Example of Insertion of 2-3-4 Tree • Insertion Sequence: 2, 15, 12, 4, 8, 10, 25, 35, 55, 11, 9, 5, 7

  14. 14 Main Index Contents Another Example of Insertion of 2-3-4 Tree (Cont…)

  15. Another Example of Insertion of 2-3-4 Tree (Cont…)

  16. 16 Main Index Contents Red-Black Trees

  17. Converting a 2-3-4 Tree to Red-Black Tree Example

  18. 18 Main Index Contents Four Situations in the Splitting of a 4-Node

  19. 19 Main Index Contents Left child of a Black parent P

  20. Prior to inserting node 55

  21. 21 Main Index Contents Oriented left-left from G Using A Single Right Rotation

  22. 22 Main Index Contents Oriented Left-Right From G After the Color Flip

  23. 23 Main Index Contents Building A Red-Black Tree

  24. 24 Main Index Contents Building A Red-Black Tree (Cont…)

  25. rbnode Representation of Red-Black Tree

  26. 26 Main Index Contents Summary Slide 1 §- Hash Table - simulates the fastest searching technique, knowing the index of the required value in a vector and array and apply the index to access the value, by applying a hash function that converts the data to an integer - After obtaining an index by dividing the value from the hash function by the table size and taking the remainder, access the table. Normally, the number of elements in the table is much smaller than the number of distinct data values, so collisions occur. - To handle collisions, we must place a value that collides with an existing table element into the table in such a way that we can efficiently access it later.

  27. 27 Main Index Contents Summary Slide 2 §- Hash Table (Cont…) - average running time for a search of a hash table is O(1) - the worst case is O(n)

  28. 28 Main Index Contents Summary Slide 3 §- Collision Resolution - Two types: 1) linear open probe addressing - the table is a vector or array of static size - After using the hash function to compute a table index, look up the entry in the table. - If the values match, perform an update if necessary. - If the table entry is empty, insert the value in the table.

  29. 29 Main Index Contents Summary Slide 4 §- Collision Resolution (Cont…) - Two types: 1) linear open probe addressing - Otherwise, probe forward circularly, looking for a match or an empty table slot. - If the probe returns to the original starting point, the table is full. - you can search table items that hashed to different table locations. - Deleting an item difficult.

  30. 30 Main Index Contents Summary Slide 5 §- Collision Resolution (Cont…) 2) chaining with separate lists. - the hash table is a vector of list objects - Each list is a sequence of colliding items. - After applying the hash function to compute the table index, search the list for the data value. - If it is found, update its value; otherwise, insert the value at the back of the list. - you search only items that collided at the same table location

  31. 31 Main Index Contents Summary Slide 6 §- Collision Resolution (Cont…) - there is no limitation on the number of values in the table, and deleting an item from the table involves only erasing it from its corresponding list

  32. 32 Main Index Contents Summary Slide 7 §- 2-3-4 tree - a node has either 1 value and 2 children, 2 values and 3 children, or 3 values and 4 children - construction of 2-3-4 trees is complex, so we build an equivalent binary tree known as a red-black tree 

  33. 33 Main Index Contents Summary Slide 8 §- red-black trees - Deleting a node from a red-black tree is rather difficult.   - the class rbtree, builds a red-black tree

More Related