Balanced Search Trees and 2-3 Trees for Efficient Data Operations

bbm 204 algorithms lab recitation 4 2 3 search n.w
1 / 17
Embed
Share

Discover the significance of balanced search trees and 2-3 trees in optimizing search, insertion, and removal operations. Dive into exercises and illustrations to enhance your understanding of these data structures.

  • Search Trees
  • Data Operations
  • Balanced Trees
  • 2-3 Trees
  • Algorithm Efficiency

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. BBM 204 Algorithms Lab Recitation 4 2-3 search trees Red-black BSTs I l Karabey

  2. Index Balanced Search Trees 2-3 search trees Red-black BSTs Exercises for 2-3 and Red-black trees

  3. Why do we need a balanced tree? Source: http://ee.usc.edu/~redekopp/cs104/slides/L19_BalancedBST_23.pdf

  4. 2-3 Search Trees Each internal node has either 2 or 3 children All leaves are at the same level Find, insert and remove operations take O(logn) time Source: http://ee.usc.edu/~redekopp/cs104/slides/L19_BalancedBST_23.pdf

  5. 2-3 Search Trees Source: http://ee.usc.edu/~redekopp/cs104/slides/L19_BalancedBST_23.pdf

  6. Exercise-1: 2-3 Insertion Draw the 2-3 tree that results when you insert the keys E A S Y Q U T I O N in that order into an initially empty tree Source: Algorithms, 4th Edition, R. Sedgewick and K. Wayne, Addison-Wesley Professional, 2011 (Chapter 3, Exercises 3.3.1, pp. 449)

  7. Exercise-2 (Your turn ) Draw the 2-3 tree that results when you insert the keys Y L P M X H C R A E S in that order into an initially empty tree Source: Algorithms, 4th Edition, R. Sedgewick and K. Wayne, Addison-Wesley Professional, 2011 (Chapter 3, Exercises 3.3.2, pp. 449)

  8. 2-3 Search Tree Removal Source: http://ee.usc.edu/~redekopp/cs104/slides/L19_BalancedBST_23.pdf

  9. Remove cases of 2-3 Trees Source: http://ee.usc.edu/~redekopp/cs104/slides/L19_BalancedBST_23.pdf

  10. Remove Exercise 1 Source: http://ee.usc.edu/~redekopp/cs104/slides/L19_BalancedBST_23.pdf

  11. Remove Exercise 1 (cont.) Source: http://ee.usc.edu/~redekopp/cs104/slides/L19_BalancedBST_23.pdf

  12. Remove Exercise 2 Source: http://ee.usc.edu/~redekopp/cs104/slides/L19_BalancedBST_23.pdf

  13. Red-black BSTs Every node is either red or black. If a node has a NULL child, that "child" is considered black If a node is red, then both of its children are black Every simple path from a node to a descendant NULL child has the same number of black nodes, (including the black NULL child) The root is black Source: http://web.cs.hacettepe.edu.tr/~sever/bil367/lectures/redblack16.pdf

  14. Relation between Red-black BSTs and 2-3 tree Source: http://web.cs.hacettepe.edu.tr/~bbm202/slides/09-balanced-trees.pdf

  15. Insertion Cases for Red-black BSTs Case 1: Right child red, left child black rotate left Case 2: Left child, left-left grandchild red rotate right Case 3: Both children red flip colors Source: http://web.cs.hacettepe.edu.tr/~bbm202/slides/09-balanced-trees.pdf

  16. Exercise-3: Red-black BSTs Insertion Draw red-black BST that results when you insert the keys E A S Y Q U T I O N in that order into an initially empty tree Source: Algorithms, 4th Edition, R. Sedgewick and K. Wayne, Addison-Wesley Professional, 2011 (Chapter 3, Exercises 3.3.10, pp. 449)

  17. Exercise-4 (Your turn ) Draw red-black BST that results when you insert the keys Y L P M X H C R A E S in that order into an initially empty tree Source: Algorithms, 4th Edition, R. Sedgewick and K. Wayne, Addison-Wesley Professional, 2011 (Chapter 3, Exercises 3.3.11, pp. 449)

Related


More Related Content