Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:07:47+00:00 2026-06-12T00:07:47+00:00

I am trying to insert a new value into an AVL tree. The new

  • 0

I am trying to insert a new value into an AVL tree. The new insertion causes imbalance (as per the article on Wikipedia, this should belong to the left-right case), hence needs rotation. However, it is not possible to rotate in the current situation, since both children end up in becoming lesser than a parent:

           15
         /    \
        10    27
       /  \      
      8   12

Now if I want to insert 11, the structure becomes imbalanced:

           15
         /    \
        10    27
       /  \      
      8   12
         /
        11

Since the left subtree is longer, and the left subtree has a longer right subtree, as per the Wikipedia diagrams, this should fall under the Left-Right case. However, there, the element 4 had both left and right subtrees, making the rotation possible. but here, since 12 has only the left subtree, rotation makes it look like:

           15
         /    \
        12    27
       /  \      
      10   8
         /
        11

resulting in both children of 12 being less than 12. What am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:07:48+00:00Added an answer on June 12, 2026 at 12:07 am

    You seem to be rotating wrong. The only node with the wrong balance factor is the root, so you rotate around that.

    That case involves checking the balance factor of 10 (left child of the root): it is -1, so we need two different rotations (left-right case).

    First, we rotate around 10 to the left, as per the upper left part of this image:

    enter image description here

    So we get:

               15
              /  \
             12  27
            / 
           10    
          /  \
         8   11           
    

    Then you continue with the next rotation as described in the image.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new and this is my first question. I'm trying to insert a value
I'm trying to insert a null value into my database from C# like this:
Well as the question says am trying to insert a string value into a
I'm trying to get a basic DataGridView to insert new rows into a table.
I am trying to insert a new password into the password column of my
I have an issue, I'm trying to insert a new row into a postgres
I'm trying to insert into jQuery full calendar event data, which in this case
I'm trying to insert some new objects into a firebird database using NHibernate. I
Using a VBA script in Excel, I'm trying to insert a new row into
I'm new to ASP. I am trying to insert data from an asp:textbox into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.