Course Hero Logo

Lab- RedBlackTrees.docx - Lab: Data Structures and...

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 - 4 out of 16 pages.

Lab: Data Structures and AlgorithmsTopic: Red Black Trees + BSTObjectiveWorking with Red Black TreesSolutions to tasks 2 and 3 will be considered as Assignment 3, Start from Task 2 or3 and complete the task 1 in the endTask 1:Similar to the cases of Insertion, submit the rules for cases of Deletion.Examples of each case are also required.You may not create a power point for it, you may write down the cases on a MicrosoftWord, or text file and submit that file. Handwritten rules are also acceptable, the choice isyours.Task 2:For a BST, create the following functions:1.Copy Constructor2.A function other than copy constructor, which creates copy of a tree passed as parameter to thefunction into the tree that called the function. The name of this function should becopyTree3.Destructor (should destroy the complete tree without memory leakage or dangling pointers)4.A function other than destructor, which when called, destroys the tree that called the function.You can name this function asdestroyTreeTask 3:For a BST, create a function that deletes all the duplicate nodes (if any) present in the tree..
The complete explanation of Red-Black tree is given below. I have copiedeverything from Wikipedia. You can do the same to copy 6 rules of deletion as longas you understand them (task 1).Partial code of insert and delete are also given in the explanation below. This ismore than enough to implement the project. If you intend to copy the codes givenbelow without understanding it, trust me, it won’t run. You can try.NOTE THAT R-B TREES ARE A PART OF YOUR COURSE IRRESPECTIVEOF THE FACT WHETHER YOU IMPLEMENT IT AS A PROJECT OT NOT.Red–black treeFrom Wikipedia, the free encyclopediaRed–black treeTypeTreeInvented1972Invented byRudolf BayerTime complexityinbig O notationAverageWorst caseSearchO(log n)O(log n)InsertO(log n)O(log n)DeleteO(log n)O(log n)A red–black tree is abinary search treewith an extra bit of data per node, its color, which can beeither red or black. The extra bit of storage ensures an approximately balanced tree by constraininghow nodes are colored from any path from the root to the leaf.[1]Thus, it is adata structurewhich is atype ofself-balancing binary search tree.Balance is preserved by painting each node of the tree with one of two colors (typically called 'red'and 'black') in a way that satisfies certain properties, which collectively constrain how unbalancedthe tree can become in the worst case. When the tree is modified, the new tree is subsequently

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 16 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
N/A
Tags
Red black tree, Red Black Trees

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