11 Red Black Trees - Search Trees part 2 15-211 Fundamental...

Info icon This preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
Search Trees, part 2 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miler 18 February 2010 Reading for today: Sections 19.5 and 19.8
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Plan Today 2-3-4 trees Red-black trees Index trees HW3 is out You should do the theory questions first As seam carving is slow, give yourself plenty of time for testing
Image of page 2
3 Last time … Dealing with imbalance Balanced trees Maintain structural invariants that guarantee O(lg n ) height AVL trees today 2-3-4 and Red-black trees Thursday Self-adjusting trees Not necessarily O(lg n ) height, but can show amortized efficiency
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 Last time … A bad structural invariant Complete trees Consider insert(7): 42 25 12 9 17 37 29 46 50 71 47 27 44 37 17 9 7 12 29 27 44 47 71 46 25 42 50
Image of page 4
5 Last time …. AVL trees For a tree T , let L be the root’s left subtree and R be the root’s right subtree. T is an AVL tree if |height( L ) – height( R )| · 1 L is an AVL tree, and R is an AVL tree a.k.a. height-balanced trees L R
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 AVL insert At lowest node where imbalance occurred, which subtree caused the imbalance? i.e., to which subtree did the insert occur? Four cases: Left outer Left inner Right inner Right outer
Image of page 6
7 Case 1: left outer subtree The insertion was to the left subtree of the left child of X: “single rotate right” X y A B C X y A B C Δ ( h) > 1 (to be continued…)
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
8 Case 1: left outer subtree The insertion was to the left subtree of the left child of X: “single rotate right” X y A B C X y A B C 2
Image of page 8
9 Case 2: left inner subtree The insertion was to the right subtree of the left child of X: “double rotate right” X y A C D Z B X y A C D Z B (to be continued…) 2
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
10 Case 2: left inner subtree The insertion was to the right subtree of the left child of X: “double rotate right” X y A C D Z B X y A C D Z B 2
Image of page 10
11 Case 3: right inner subtree The insertion was to the left subtree of the right child of X: “double rotate left” X y A C D Z B X y A C D Z B symmetric with Case 2!
Image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
12 Case 4: right outer subtree The insertion was to the right subtree of the right child of X: “single rotate left” X y A B C 2 X y A B C symmetric with Case 1!
Image of page 12
13 AVL delete Is similar, except one subtree is too short instead of too long insert never requires more than one rebalancing operation delete might require O(lg n) rebalances as we walk up the tree.
Image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern