10-Balanced-Search-Trees

10-Balanced-Search-Trees - Algorithms LECTURE 10 Balanced...

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

View Full Document Right Arrow Icon
Algorithms L7.1 Professor Ashok Subramanian L ECTURE 10 Balanced Search Trees Red-black trees Height of a red-black tree Rotations Insertion Algorithms
Image of page 1

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

View Full Document Right Arrow Icon
Algorithms L7.2 Balanced search trees Balanced search tree: A search-tree data structure for which a height of O (lg n ) is guaranteed when implementing a dynamic set of n items. Examples: AVL trees 2-3 trees 2-3-4 trees B-trees Red-black trees
Image of page 2
Algorithms L7.3 Red-black trees This data structure requires an extra one- bit color field in each node. Red-black properties: 1. Every node is either red or black. 2. The root and leaves ( NIL ’s) are black. 3. If a node is red, then its parent is black. 4. All simple paths from any node x to a descendant leaf have the same number of black nodes = black-height( x ) .
Image of page 3

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

View Full Document Right Arrow Icon
Algorithms L7.4 Example of a red-black tree h = 4 8 11 10 18 26 22 3 7 NIL NIL NIL NIL NIL NIL NIL NIL NIL
Image of page 4
Algorithms L7.5 Example of a red-black tree 8 11 10 18 26 22 3 7 NIL NIL NIL NIL NIL NIL NIL NIL NIL 1. Every node is either red or black.
Image of page 5

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

View Full Document Right Arrow Icon
Algorithms L7.6 Example of a red-black tree 8 11 10 18 26 22 3 7 NIL NIL NIL NIL NIL NIL NIL NIL NIL 1. The root and leaves ( NIL ’s) are black.
Image of page 6
Algorithms L7.7 Example of a red-black tree 8 11 10 18 26 22 3 7 NIL NIL NIL NIL NIL NIL NIL NIL NIL 1. If a node is red, then its parent is black.
Image of page 7

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

View Full Document Right Arrow Icon
Algorithms L7.8 Example of a red-black tree 1. All simple paths from any node x to a descendant leaf have the same number of black nodes = black-height ( x ) . 8 11 10 18 26 22 3 7 NIL NIL NIL NIL NIL NIL NIL NIL NIL bh = 2 bh = 1 bh = 1 bh = 2 bh = 0
Image of page 8
Algorithms L7.9 Height of a red-black tree Theorem. A red-black tree with n keys has height h 2 lg( n + 1) .
Image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
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