Question

Question 46 2 pts Which of the following is incorrect about a red-black tree? Group of...

Question 46

2 pts

Which of the following is incorrect about a red-black tree?

Group of answer choices

a. The leaves are always red

b. A red-black tree is equivalent to a 2-4 tree

c. A red node must have a black parent

d. Every path from the root to the leaves must have the same number of red nodes

e. a and d


Flag this Question

Question 47

2 pts

Given the following maxheap, assuming heap entries start at index 1, show the heap after adding the entry 87 using the array representation.

index

0

1

2

3

4

5

6

value

45

12

40

8

7

24

Group of answer choices

a.

index

0

1

2

3

4

5

6

7

value

45

12

40

8

7

24

87

b.

index

0

1

2

3

4

5

6

7

value

45

12

87

8

7

24

40

c.

index

0

1

2

3

4

5

6

7

value

87

45

12

24

40

8

7

d.

index

0

1

2

3

4

5

6

7

value

87

45

12

40

24

8

7

e.

index

0

1

2

3

4

5

6

7

value

87

12

45

8

7

24

40

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1

a) Leaves are alway red. This statement as false. Only condition of R-B tree is root is always black. suppose there are 3 levels, then leaf will be black, as no two levels can have same color

b) 2-4 trees and red black trees are equivalent. This statement is correct.

c) A red node must have black parent. Since no adjacent level nodes can have same color and root is always black, this statement is also true.

d) Every path from the root to the leaves must have the same number of red nodes. This statement is false. The correct answer would be black nodes instead of red in above statement as per definition of red black tree.

So correct answer for question 1 would option e) which states option b) and d) are false.

2. In a max heap, root element will be always 1. Left child of node is available at index 2i and right child at index 2i + 1, parent will have index i/2, if heap is implemented as an array.

Initial heap: [45, 12, 40, 87, 24]

add 87

array [45, 12, 40, 87, 24, 87]

heapify [87, 12, 45, 87, 24, 40]

Operations in heapify.

87 added at index 6 is compared with parent at index floor(6/2) = 3. ie. 40. Since 87 is larger than 40(max heap), we will swap them. New array after swap is

[45, 12, 87, 87, 24, 40]

We will be checking 87 at index 3 with it's parent at index floor(3/2) = 1 i.e. 45. Since 87 is larger than 45, swap them to get the heap.

[87, 12, 45, 87, 24, 40] corresponds to option (e)

KINDLY REVIEW.

Add a comment
Know the answer?
Add Answer to:
Question 46 2 pts Which of the following is incorrect about a red-black tree? Group of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60, 130, 64, 87 to perform the followings: a) Binary Search Tree - Draw a binary search tree - Retrieve the integers ke...

    Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60, 130, 64, 87 to perform the followings: a) Binary Search Tree - Draw a binary search tree - Retrieve the integers keys in post-order - Retrieve the integers keys in pre-order - Draw a binary search tree after node 58 is deleted b) Create a Hash Table using the methods described below. Show the final array after all integer keys are inserted. Assumes that...

  • Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60,...

    Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60, 130, 64, 87 to perform the followings: a) Binary Search Tree - Draw a binary search tree - Retrieve the integers keys in post-order - Retrieve the integers keys in pre-order - Draw a binary search tree after node 58 is deleted b) Create a Hash Table using the methods described below. Show the final array after all integer keys are inserted. Assumes that...

  • Num #2 Below, you are given a correct Red-Black tree, in which red nodes are shown...

    Num #2 Below, you are given a correct Red-Black tree, in which red nodes are shown as shaded diamonds, while black nodes are shown as empty circles. Give the final tree obtained from inserting the key '8 into this tree, after the insert function correctly restores the Red-Black Tree properties. It is not necessary to show intermediate steps, but if your final answer is wrong, you will get partial credit if earlier steps are correct. 4 (6 3 10

  • Data structures Exercises: For the following binary tree (Index-Value): 0 1 2 3 4 5 6...

    Data structures Exercises: For the following binary tree (Index-Value): 0 1 2 3 4 5 6 7 8 9 A C E G B P D X F H Give the pre-order traversal. Give the post-order traversal. Give the in-order traversal. Determine the height of the tree. Using these values: 8 6 4 3 5 9 2 1 6 Build a binary search tree. Build an AVL Tree. Build a 2-3 Tree. Build a min-heap. Build a max-heap. Apply a...

  • 13) The value of the resistance R1 of colors (Red, Black, Black, and Gold) is: Red...

    13) The value of the resistance R1 of colors (Red, Black, Black, and Gold) is: Red Black Gold Gold: 5% Silver 1023 (A) (2052) 22 (B) (20:1) (C) (200+ 10) 2 (D) (2007 20) 2 (E) (27 0.1) Black: 0 Brown: 1 Red: 2 Orange : 3 Yellow : 4 Green: 5 Blue : 6 Violet:7 Gray: 8 White: 9 14) Which of the following equations is correct when applying Kirchhoff loop rule for the circuit shown below (A) 6...

  • In this assignment, you will develop a C program to construct a red and black tree....

    In this assignment, you will develop a C program to construct a red and black tree. For a given input sequence the tree is unique by using RB-INSERT on one number at a time. Below is an example: The input is a sequence of numbers separated by comma, e.g. 1,8,11,2, … You can enter the numbers using an input file and output the tree, or through a command line with one number at a time (with “X” to stop entering...

  • (a) On an initially empty red-black tree, perform the following operations in this order: insert(1), insert(3),...

    (a) On an initially empty red-black tree, perform the following operations in this order: insert(1), insert(3), insert(5), insert(6), insert(7), delete(1) Show all the intermediate steps of your work (b) We can get another sorting algorithm by first inserting all the keys into a red-black tree, and then performing an in-order traversal of the tree. What's the time complexity of this algorithm? (As always, use O or Θ notation.)

  • You are given a binary tree of the form: Each node in the tree has a...

    You are given a binary tree of the form: Each node in the tree has a left child and a right child. Each of the children will be extended as a linked list. Every node has the following attributes: key, left node, right node, and next node. The next node allows a node, that is a part of the tree, to be extended as a linked list. The diamonds represent the next nodes, which are part of the linked list...

  • Red black trees Perform insertions of the following keys, 4, 7, 12, 15, 3, 5, 14,...

    Red black trees Perform insertions of the following keys, 4, 7, 12, 15, 3, 5, 14, 18, 16, 17 (left to right) into a redblack tree, then, perform deletions of keys 3, 12, 17, under the properties as provided below. • Root propoerty: the root is black. • External propoerty: every leaf is black. • Internal propoerty: the children of a red node are black. • Depth propoerty: all the leaves have the same black depth. Note that insertions have...

  • Trees and Heaps 1. Show that the maximum number of nodes in a binary tree of...

    Trees and Heaps 1. Show that the maximum number of nodes in a binary tree of height h is 2h+1 − 1. 2. A full node is a node with two children. Prove that the number of full nodes plus one is equal to the number of leaves in a nonempty binary tree. 3. What is the minimum number of nodes in an AVL tree of height 15? 4. Show the result of inserting 14, 12, 18, 20, 27, 16,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT