<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohamed Benlmaoujoud</title>
    <description>The latest articles on DEV Community by Mohamed Benlmaoujoud (@benlmaoujoud).</description>
    <link>https://dev.to/benlmaoujoud</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F776824%2Fad3d6eb3-6358-4756-acc7-32d0061ecd4e.jpeg</url>
      <title>DEV Community: Mohamed Benlmaoujoud</title>
      <link>https://dev.to/benlmaoujoud</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/benlmaoujoud"/>
    <language>en</language>
    <item>
      <title>AVL Tree : Rotation, and Balance Factor Explained</title>
      <dc:creator>Mohamed Benlmaoujoud</dc:creator>
      <pubDate>Sat, 18 Dec 2021 20:31:56 +0000</pubDate>
      <link>https://dev.to/benlmaoujoud/avl-tree-insertion-rotation-and-balance-factor-explained-314n</link>
      <guid>https://dev.to/benlmaoujoud/avl-tree-insertion-rotation-and-balance-factor-explained-314n</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is an AVL Tree?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;An AVL tree is a type of binary search tree. Named after it's inventors Adelson, Velskii, and Landis, AVL trees have the property of dynamic self-balancing in addition to all the other properties exhibited by binary search trees.&lt;/p&gt;

&lt;p&gt;A BST is a data structure composed of nodes. It has the following guarantees:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Each tree has a root node (at the top)&lt;/li&gt;
&lt;li&gt;The root node has zero, one, or two child nodes&lt;/li&gt;
&lt;li&gt;Each child node has zero, one, or two child nodes&lt;/li&gt;
&lt;li&gt;Each node has up to two children&lt;/li&gt;
&lt;li&gt;For each node, its left descendants are less than the &lt;/li&gt;
&lt;li&gt;current node, which is less than the right descendants&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;So The difference between the depth of right and left sub-         trees cannot be more than one |depth(right) - dépt(left)|&amp;gt;1. 
&lt;em&gt;This difference is called the balance factor.&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So how we can balance our BST , well 💁 we can use some ruls (rotations) to balance it .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Left Rotation (LL Rotation)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In left rotations, every node moves one position to left from the current position.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UyBktTUg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zj12loca9jv82fywoel.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UyBktTUg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zj12loca9jv82fywoel.jpeg" alt="Image description" width="880" height="559"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;2. Right Rotation (RR Rotation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In right rotations, every node moves one position to right from the current position.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TtgAqLvf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmzn1j2l9ibhfhns3jws.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TtgAqLvf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmzn1j2l9ibhfhns3jws.jpeg" alt="Image description" width="880" height="606"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;3. Left-Right &amp;amp;&amp;amp; Right-Left Rotation (LR &amp;amp;&amp;amp; RL Rotation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LR or RL rotations are a combination of a single left &lt;br&gt;
resp (right)  rotation followed by a single right resp(left) rotation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Application of AVL Trees&lt;/strong&gt;&lt;br&gt;
AVL trees are beneficial in cases like a database where insertions and deletions are not that frequent, but you frequently check for entries.&lt;/p&gt;

</description>
      <category>datastructue</category>
      <category>programming</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
