Course Hero Logo

Red-Black-Trees - Red-Black Trees Contents Introduction...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 2 out of 4 pages.

Red-Black TreesContentsIntroductionRed-Black Tree OperationsinsertdeleteSummaryIntroductionRecall that, for binary search trees, although the average-case times for the lookup, insert, and deletemethods are all O(log N), where N is the number of nodes in the tree, the worst-case time is O(N). WecanguaranteeO(log N) time for all three methods by using a balanced tree -- a tree that always hasheight O(log N)-- instead of a binary search tree.A number of different balanced trees have been defined, including AVL trees, 2-4 trees, and B trees. Youmight learn about the first two in an algorithms class and the third in a database class. Here we will lookat yet another kind of balanced tree called a red-black tree.The important idea behind all of these trees is that the insert and delete operations mayrestructurethetree to keep it balanced. So lookup, insert, and delete will always be logarithmic in the number of nodesbut insert and delete may be more complicated than for binary search trees.A red-black tree is a binary search tree in whicheach node has a color (red or black) associated with it (in addition to its key and left and rightchildren)the following 3 properties hold:1.(root property) The root of the red-black tree is black2.(red property) The children of a red node are black.3.(black property) For each node with at least one null child, the number of black nodes onthe path from the root to the null child is the same.An example of a red-black tree is shown below:Operations on a Red-Black TreeAs with the binary search tree, we will want to be able to perform the following operations on red-blacktrees:insert a key value (insert)

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 4 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
MarvinSolomon
Tags
Binary Search, Data Structures, Red black tree, Self balancing binary search tree, Insert key

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture