Question

If the elements of (39,50, 92,70,27,37] were inserted into a self-balancing tree (in the same order as presented here), then

[number_1] [number_2] [number_3] [number_4] [number_5] [number_6] [number_7]

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

Self balancing tree is the tree in which the balanced factor of every node is either -1,0 or +1.

The balanced factor of node = height of left subtree - height of right subtree

[39,50,92,70,27,37] are to be inserted in balancing tree.

STEP 1)First node 39 is inserted in the empty tree

Balanced factor of node 39 = height of left subtree - height of right subtree

Since node 39 is first node so it's both height of left and right subtree is 0

Balanced factor of node 39=0-0=0

This tree after adding node 39 is shown in figure 1 in image

FIGURE 1 FIGURE 2 FIGURE 3 39 39 39 50 921 FIGURE 3 FIGURE 4 39 50 IR (RR)=L7 50 (29 92 az) FIGURE 6 FIGURE_5 - 1 50 50 1 920

FIGURE 7 FIGURES 50 50 92 92 O 39 LR 37 Rotation 70 70 27 27 39 37 FINAL TREE AFTER INSERTION 50 37 92 27 39 (70 Nuu FIGURE 9

STEP 2)Node 50 is inserted in the tree as according to binary search tree property 50 is more than 39 so it will come on right side of 39

Balanced factor of node 39=0-1=1

Balanced factor of node 50=0-0=0

The balanced factor is 1 and 0 after adding 50 so the tree is balanced as shown in image in figure 2

STEP 3)Now 92 is added according to binary search tree property it will come on right of node 50 because 92 greater than 50

Balanced factor of node 39=0-2=-2

Balanced factor of node 50= 0-1=-1

Balanced factor of node 92= 0-0=0

The tree after inserting 92 is shown in image in figure 3

But the tree is not balanced because balanced factor of node 39 is -2 as three are two right insertions(RR) so tree needs to balanced by making 1 left rotation L on node 39

The new tree after left rotation show in figure 4 which is balanced.

STEP 4) Node 70 is inserted in the balanced tree as 70<92 so it will come on left  side of the node 92.

Balanced factor of node 50=0-1=-1

Balanced factor of node 39=0-0=0

Balanced factor of node 92=1-0=1

Balanced factor of node 70=0-0=0

Since all balanced factor is 0 ,1 and -1 so tree is balanced

The tree is shown in image in figure 5

STEP 5)Node 27 is inserted in the balanced tree as 27<39 so it will be on the left side of node 39

Balanced factor of node 50=2-2=0

Balanced factor of node 39=1-0=1

Balanced factor of node 27=0-0=0

Balanced factor of node 92=1-0=1

Balanced factor of node 70 =0-0=0

Since all balanced factor is 0 and 1 so tree is balanced as shown in image in figure 6

STEP 6) Node 37 is inserted in the tree to right of node 27 according to binary search tree property as 37>27 so come on right side of node 27 as shown in image in figure 7.

Balanced factor of node 50=3-2=1

Balanced factor of node 39=2-0=2

Balanced factor of node 27=0-1=-1

Balanced factor of node 37=0-0=0

Balanced factor of node 92=1-0=1

Balanced factor of node 70=0-0=0

So the tree is not balanced as the node 39 has balanced factor 2 due to one left and one right insertion (LR) so two rotation are made on tree one left and one right rotation to give final tree in image in figure 8

Now the tree is balanced so the final tree after insertion shown in image in figure 9

Number_1 is 50

Number_2 is 37

Number_3 is 92

Number_4 is 27

Number_5 is 39

Number_6 is 70

Number_7 is null

FIGURE 1 FIGURE 2 FIGURE 3 39 39 39 50 921 FIGURE 3 FIGURE 4 39 50 IR (RR)=L7 50 (29 92 az) FIGURE 6 FIGURE_5 - 1 50 50 1 920 92 39 (39 27 70 70 csscanned with Carlscanner

FIGURE 7 FIGURES 50 50 92 92 O 39 LR 37 Rotation 70 70 27 27 39 37 FINAL TREE AFTER INSERTION 50 37 92 27 39 (70 Nuu FIGURE 9 C Scanned with CamScanner

FIGURE 1 FIGURE 2 FIGURE 3 39 39 39 50 921 FIGURE 3 FIGURE 4 39 50 IR (RR)=L7 50 (29 92 az) FIGURE 6 FIGURE_5 - 1 50 50 1 920 92 39 (39 27 70 70 csscanned with Carlscanner

We were unable to transcribe this image

FIGURE 1 FIGURE 2 FIGURE 3 39 39 39 50 921 FIGURE 3 FIGURE 4 39 50 IR (RR)=L7 50 (29 92 az) FIGURE 6 FIGURE_5 - 1 50 50 1 920 92 39 (39 27 70 70 csscanned with Carlscanner

FIGURE 7 FIGURES 50 50 92 92 O 39 LR 37 Rotation 70 70 27 27 39 37 FINAL TREE AFTER INSERTION 50 37 92 27 39 (70 Nuu FIGURE 9 C Scanned with CamScanner

Add a comment
Know the answer?
Add Answer to:
If the elements of (39,50, 92,70,27,37] were inserted into a self-balancing tree (in the same order...
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
  • A balanced binary tree is a binary tree structure in which the left and right subtrees of every node differ

    Data structures C++1- A balanced binary tree is a binary tree structure in which the left and right subtrees of every node differ in height by no more than 1 Out of the following choices, which is the minimum set of nodes, if removed, will make the BST balanced?2- Which of the following is true for Red-Black Trees ? Select all choices that apply! Select one or more: a. For each node in the tree, all paths from that node to any leaf nodes contain...

  • I need help in C++ implementing binary search tree. I have the .h file for the...

    I need help in C++ implementing binary search tree. I have the .h file for the binary search tree class. I have 4 classic texts, and 2 different dictionaries. Classic Texts: Alice In Wonderland.txt A Tale of Two Cities.txt Pride And Prejudice.txt War and Peace.txt 2 different dictionaries: Dictionary.txt Dictionary-brit.txt The data structures from the standard template library can not be used.The main program should open the text file, read in the words, remove the punctuation and change all the...

  • 26-ary tree for spell checker in JAVA You are asked to write some functionalities for a...

    26-ary tree for spell checker in JAVA You are asked to write some functionalities for a spelling checker inside Tree.java that has at least the following methods: /*Adds a word to a spelling checker’s collection of correctly spelled words*/ void add(String word) /*Returns true if the given word is spelled correctly*/ boolean check(String word) /*Returns back all words in the tree in alphabetical order*/ public String getDictionaryInAlphabeticalOrder() Store the collection of correctly spelled words in a 26-ary tree. The number...

  • Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order,...

    Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order, and to plot a binary tree into a 2-dimensional array. You may write many recursive methods for this project. You are not allowed to use any existing Java classes such as ArrayList or Vector or Tree. Please stop your program if the user enters 0 as the tree selection. Your program must run the following Test Case 1 plus two more test cases to...

  • Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order, and to plot a binar...

    Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order, and to plot a binary tree into a 2-dimensional array. You may write many recursive methods for this project. You are not allowed to use any existing Java classes such as ArrayList or Vector or Tree. Please stop your program if the user enters 0 as the tree selection. Your program must run the following Test Case 1 plus two more test cases to...

  • (10 pts) Use the following information for all parts: On a particular golf course, a sample...

    (10 pts) Use the following information for all parts: On a particular golf course, a sample of 40 golfers have a mean golf score of 79. Suppose the population standard deviation for this course is 3.6605. (a) Using the formula a 90% confidence interval as presented in lecture, fill in the blanks with the appropriate values for this problem for calculating the confidence interval below. To enter where x is any number, type sqrt(x). For example, should be typed as...

  • The first and second picture are the definition of 2-3 tree,3rd and 4th are the pre-condition...

    The first and second picture are the definition of 2-3 tree,3rd and 4th are the pre-condition and post-condition. Please use these question to solve problem 8,the last photo. 2-3 Trees: Definition Suppose that E is an ordered type, that is, a nonempty set of values that have a total order. A 2-3-tree, for type E, is a finite rooted tree T (like a binary search tree or a red-black tree) that satisfies the following 2-3 Tree Properties: (a) Every leaf...

  • Summary You will write an application to build a tree structure called Trie for a dictionary...

    Summary You will write an application to build a tree structure called Trie for a dictionary of English words, and use the Trie to generate completion lists for string searches. Trie Structure A Trie is a general tree, in that each node can have any number of children. It is used to store a dictionary (list) of words that can be searched on, in a manner that allows for efficient generation of completion lists. The word list is originally stored...

  • Recursion and Trees Application – Building a Word Index Make sure you have read and understood...

    Recursion and Trees Application – Building a Word Index Make sure you have read and understood ·         lesson modules week 10 and 11 ·         chapters 9 and 10 of our text ·         module - Lab Homework Requirements before submitting this assignment. Hand in only one program, please. Background: In many applications, the composition of a collection of data items changes over time. Not only are new data items added and existing ones removed, but data items may be duplicated. A list data structure...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

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