Question

In: Computer Science

Draw the red-black BST that results when you insert letters A through K int order into...

Draw the red-black BST that results when you insert letters A through K int order into an initially empty tree, then describe what happens in general when trees are built by insertion of keys in ascending order. What about descending order?

Solutions

Expert Solution

A red-black tree is a binary search tree in which each node is colored either red or black and follows the following conditions:

  • The root of the tree is always black.
  • Every leaf (which is null always) must be black.
  • The children of a red node are always black i.e., there can never be adjacent red nodes.
  • Every path from the root to a 0-node or a 1-node has the same number of black nodes.

Insertion in the Red Black tree happens in the same way when nodes are in ascending or descending order.There are no different rules when nodes are sorted in a certain fashion.Every insertion follows the same rules of restructuring and recoloring.

The difference is in the balancing part.The nodes will arrange themselves in a line with no branches.Since each node is larger than the previously inserted node, every node is a right child, so all the nodes are on right side of the root.Hence, the tree will be maximally unbalanced.

The tree in fact will behave like a linked list. The complexity of searching will reduce to O(N) instead of O(logN) as it is for a balanced tree.

Similarly, if nodes are inserted in descending order, every node would be the left child of its parent; the tree would be unbalanced on the left side.

As per the question if we insert nodes from A to K in ascending order or descending order following results will be shown:

Nodes inserted in Ascending Order:-

Nodes inserted in Descending order:-

Hope this is helpful

Please please dont downvote

If it is helpful please please please upvote it wil help me alot


Related Solutions

Cards are: Black A, K, Q, J Red    A, K, Q, J A K Q J...
Cards are: Black A, K, Q, J Red    A, K, Q, J A K Q J A K Q J 1.) The probability of picking a numeric card if you pick two cards randomly 2.) The probability of Picking K and Q if you pick two cards randomly. It does not matter which color. However, K needs to be in your left and Q needs to be in your right hand. 3.) The probability of Picking K and Q if...
Cards are: Black A, K, Q, J Red    A, K, Q, J A K Q J...
Cards are: Black A, K, Q, J Red    A, K, Q, J A K Q J A K Q J 1.) The probability of picking a numeric card if you pick two cards randomly 2.) The probability of Picking K and Q if you pick two cards randomly. It does not matter which color. However, K needs to be in your left and Q needs to be in your right hand. 3.) The probability of Picking K and Q if...
suppose he roll two dice one black and one red you record the outcomes in order...
suppose he roll two dice one black and one red you record the outcomes in order for example the outcome (35) notes at three on the black die And a five on the red dye. What a beauty event that the black guy is even, B be the event at the red dye is odd, and C be the event that the dice sum to 10 (a) List and describe the outcomes in the sample space S and the events...
An urn contains 1 black marble, 1 white marble, and 1 red marble. Suppose you draw...
An urn contains 1 black marble, 1 white marble, and 1 red marble. Suppose you draw a marble from the urn 8 times with replacement. a) Describe the sample space. How would you denote outcomes? How do you assign probabilities to each outcome? b) What is the probability of drawing exactly 2 black and 3 white marbles after the 8 draws? c) How many different configurations of numbers of black, white, and red marbles are possible for the 8 draws?
Given the following numbers in the given order, show the red black tree              100, 200,...
Given the following numbers in the given order, show the red black tree              100, 200, 150, 170, 165, 180, 220, 163, 164 Show the pre-order traversal of this red black tree while showing the color of each node in the pre-order traversal. Write (C++) the red black tree code and insert the above numbers. Show the screen shot of the pre-order traversal of the resulting tree. Distinguish the colors by writing a * next to the black color values....
Suppose we have a sack with 2 red balls and 2 black balls, and we draw...
Suppose we have a sack with 2 red balls and 2 black balls, and we draw balls without replacement until the second red ball is drawn. Describe the random variable ? = "the number of balls drawn". Describe by giving the range, probability distribution, expected value, standard deviation, and variance.
A box contains 7 black balls and a single red ball. Peter and Frances draw without...
A box contains 7 black balls and a single red ball. Peter and Frances draw without replacement balls from this urn, alternating after each draw until the red ball is drawn. The game is won by the player who happens to draw the single red ball. Peter is a gentleman and offers Frances the choice of whether she wants to start or not. Frances has a hunch that she might be better off if she starts; after all, she might...
When using binomial approach and Black-Scholes formula for pricing options, do you expect the results to...
When using binomial approach and Black-Scholes formula for pricing options, do you expect the results to be the same? (3)Why or why not? (2)  Price a put and a call with data offered below using both methods and show the prices. Do your results support initial expectations? (5) Present stock price $30, exercise price $40, interest rate 5%, option expires one year from now, volatility 27%, stock will either move up by 40% or down by 27%.
Assume jar has four red marbles and two black marbles. Draw out two marbles with and...
Assume jar has four red marbles and two black marbles. Draw out two marbles with and without replacement. Find the requested probabilities (enter the probabilities as fractions.) a.) p(two red marbles) with replacement = without replacement = b.) p(two black marbles) with replacement = without replacement = c.) p(one red and one black marble) with replacement = without replacement = d.) p(red on the first draw and black on the second draw) with replacement = without replacement =
Suppose an urn contains 3 black chips, 2 red chips, and two green chips. We draw...
Suppose an urn contains 3 black chips, 2 red chips, and two green chips. We draw three chips at random without replacement. Let A be the event that all three chips are of different color. (a) What is the probability space Ω you are working with? (b) Compute P(A) by imagining that the chips are drawn one by one as an ordered sample. (c) Compute P(A) by imagining that the three chips are drawn all at once as an unordered...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT