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 8167357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:09:58+00:00 2026-06-06T20:09:58+00:00

I am trying to implement an AVL tree and I’m having a hard time

  • 0

I am trying to implement an AVL tree and I’m having a hard time knowing when I need a RR or RL rotation (same for LL and LR).

What are the preconditions for each and how are they different. I know when I see a picture of the tree (intuitively) but what are the actual conditions ?

This is a logic problem, no code necessary, thank you.

What I do know is it involves the tree being left heavy or right heavy. But how do you determine that ?

  • 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-06T20:10:00+00:00Added an answer on June 6, 2026 at 8:10 pm

    There may be different solutions, but one is as following:

    When adding an item recursively, at each recursive call you should keep track of whether that call added the node to the left or right subtree (by letting the add function return it, for example). After the recursive call you check the height invariant. If you find that the it has been violated at that node after the insertion, you will then know the path to the imbalance.

    Some (incomplete) pseudo-code:

    add(item, node):
      if item < node.value //should add to left subtree
        if node.left is empty
          //add item here
        else
          addedLeft := add(item, node.left)
          if node.left.height - node.right.height > 1
            if addedLeft
              //you know the path to the subtree causing the imbalance is LL, do a RR (single-right) rotation
            else
              //path is LR, do a LR (double-right) rotation
      ...
    

    The recursive calls will unfold bottom-up from the added node and the general idea is to check at which node the invariant is violated (if any). When that node is discovered, you need to know the path to the subtree causing the imbalance. One must solve that problem somehow, this is one solution.

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

Sidebar

Related Questions

I'm trying to implement an AVL tree and seem to be having issues with
I am trying to implement an AVL tree and not sure about the best
I'm currently trying to implement an AVL tree in C++, so far I've done
I'm trying to implement AVL. Here's my insert, balance_tree, check_bf (balance factor), and single
Trying to implement NSCopying for the first time, and I have a question about
Just trying to implement mobFox into my app, but having trouble to make it
I am working on an assignment that asks me to implement an AVL tree.
Trying to implement Wpf Listbox dragging, and I need the Wpf equivalent of the
Trying to implement a rating system of users and postings. What is the best
Trying to implement a UITableView of names similar to the built-in Contacts iPhone app

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.