1 / 12

COP 3503 - Computer Science II (Fall 2005) Week Seven

COP 3503 - Computer Science II (Fall 2005) Week Seven. By Yunjun Zhang. A. B. C. D. E. Red-Black Tree. General Rooted Tree properties One root Each node in the tree has only one parent The path between the root and any single node in the tree is unique. (no circle) Things to remember

kevork
Download Presentation

COP 3503 - Computer Science II (Fall 2005) Week Seven

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. COP 3503 - Computer Science II (Fall 2005)Week Seven By Yunjun Zhang

  2. A B C D E Red-Black Tree • General Rooted Tree • properties • One root • Each node in the tree has only one parent • The path between the root and any single node in the tree is unique. (no circle) • Things to remember • Parents • Children • siblings – have the same parent • Depth of a node • Height of a node

  3. Red-Black Tree • Binary Trees • No node can have more than two children • Left • Right • Expression tree • Leaves: operands, such as constants and variables • Non-leaves: operators • 1+(2*b)/c

  4. Red-Black Tree • A good animation reference http://www.cs.jhu.edu/~goodrich/dsa/trees/btree.html

  5. Red-Black Tree • Binary Search Trees • Average O(logN) • Worst O(N) • To eliminate the O(N) worst case • AVL tree • red-black tree • AA tree

  6. Red-Black Tree • Basic binary search tree: • Search order property • left tree < current node < right tree • No duplicate items (this can be changed) • Operations • Find • findMin • findMax • remove

  7. Red-Black Tree • Basic binary search tree: • Operation remove • For leaf, easy • For node with one child: parentchild directly • For node with two children: replace the node with the smallest one in its right subtree.

  8. Red-Black Tree • It is a binary search tree • Its operations have logN worst case running time • Properties • Nodes are colored in red/black • Root is black • if a node is black, its children must be black. • Every path from a node to a null link must contain the same number of black nodes.

  9. Red-Black Tree • Insertion • Use find from BST • Insert the node as RED • 3 cases (When father is the left child for grandpa. Other cases are symmetric): • Father and uncle are both red

  10. Red-Black Tree • 3 cases: • Father red, uncle black, it is the left child • Father red, uncle black, it is the right child

  11. Red-Black Tree • Top-Down Deletion • Delete node as in a regular BSTNode to be deleted will have at most one childIf we delete a Red node tree still is a Red-Black treeAssume we delete a black node • http://sage.mc.yu.edu/kbeen/teaching/algorithms/resources/red-black-mod.html

  12. Animation • http://www.ece.uc.edu/~franco/C321/html/RedBlack/redblack.html

More Related