

{"id":100203,"date":"2021-08-20T09:00:38","date_gmt":"2021-08-20T03:30:38","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=100203"},"modified":"2021-08-18T22:45:48","modified_gmt":"2021-08-18T17:15:48","slug":"avl-tree","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/avl-tree\/","title":{"rendered":"AVL Tree in Data Structure"},"content":{"rendered":"<p>AVL tree is a specific type of binary search tree where the difference between heights of left and right subtrees is either 0 or 1 only for all nodes. It implements all properties of the binary search tree.<\/p>\n<p>AVL tree was invented by gm Adelson &#8211; Velsky and Em Landis in 1962 and was named AVL in their honor.<\/p>\n<h3>Balanced binary tree<\/h3>\n<p>A binary tree is said to be balanced if the balance factor of each node is -1, 0, or 1. If the balance factor is any value other than these values, the tree is said to be unbalanced and needs correction.<\/p>\n<p>The balance factor is the difference between the height of the right subtree and the left subtree.<\/p>\n<h3>Balance factor (k) = height (left(k)) &#8211; height (right(k))<\/h3>\n<ul>\n<li>If the balance factor is 1, the left sub-tree is one level higher than the right sub-tree.<\/li>\n<li>If the balance factor is 0, the left sub-tree and right sub-tree contain equal height.<\/li>\n<li>If the balance factor is -1, the left sub-tree is one level lower than the right sub-tree.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100403\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image01.jpg\" alt=\"AVL tree in DS\" width=\"547\" height=\"453\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image01.jpg 547w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image01-520x431.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image01-320x265.jpg 320w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/a><\/p>\n<p>The tree above has the properties of the binary search tree and also the balance factor for each node is either 1,0, or -1. Therefore, the above tree can be classified as an AVL tree.<\/p>\n<h3>Operations on AVL trees<\/h3>\n<p>There are 2 major operations performed on AVL trees.<\/p>\n<ul>\n<li><strong>Insertion:<\/strong> inserting a new node in the tree<\/li>\n<li><strong>Deletion:<\/strong> deleting an existing node in the tree<\/li>\n<\/ul>\n<p>Insertion and deletion procedures in the AVL tree are exactly the same as the insertion and deletion procedures in the binary search tree article since the AVL tree is also a BST. But this insertion and deletion operation, after implementation can violate the AVL property of the balance factor.<\/p>\n<p>To restore the balance factor within the range of -1 and 1, rotations are applied. A tree can be balanced by applying rotations.<\/p>\n<h3>AVL rotations<\/h3>\n<p>There are 4 types of rotations in AVL tree<\/p>\n<p>1. L L rotation<br \/>\n2. R R rotation<br \/>\n3. R L rotation<br \/>\n4. L R rotation<\/p>\n<h4>L L rotation<\/h4>\n<p>If BST becomes unbalanced, due to a node being inserted into the left subtree of the left subtree of the root node, then we apply L L rotation. L L rotation is clockwise rotation and is applied on the edge below a node having balance factor 2.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100404\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image02.jpg\" alt=\"LL Rotation in AVL\" width=\"467\" height=\"310\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image02.jpg 467w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image02-320x212.jpg 320w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image02-272x182.jpg 272w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><\/a><\/p>\n<h4>R R rotation<\/h4>\n<p>If BST becomes unbalanced, due to a node being inserted into the right subtree of the right subtree of the root node, then we apply R R rotation. R R rotation is counter-clockwise rotation and is applied on the edge below a node having balance factor 2.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image03.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100405\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image03.jpg\" alt=\"RR Rotation in AVL\" width=\"467\" height=\"310\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image03.jpg 467w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image03-320x212.jpg 320w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image03-272x182.jpg 272w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><\/a><\/p>\n<h4>L R rotation<\/h4>\n<p>Double rotations are a combination of single rotations.<\/p>\n<p>L R rotation = R R rotation + L L rotation<\/p>\n<p>First R R rotation is performed on subtree and then L L rotation is performed on full tree.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image04.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100406\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image04.jpg\" alt=\"L R rotation in AVL\" width=\"688\" height=\"310\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image04.jpg 688w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image04-520x234.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image04-320x144.jpg 320w\" sizes=\"auto, (max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<h4>R L rotation<\/h4>\n<p>R L rotation = L L rotation + R R rotation<\/p>\n<p>First L L rotation is performed on subtree and then R R rotation is performed on full tree.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image05.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100407\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image05.jpg\" alt=\"R L Rotation in AVL\" width=\"688\" height=\"310\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image05.jpg 688w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image05-520x234.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image05-320x144.jpg 320w\" sizes=\"auto, (max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<h3>Working of AVL tree<\/h3>\n<p>Step 1: insert 78<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image6.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100408\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image6.jpg\" alt=\"Insertion in AVL\" width=\"88\" height=\"71\" \/><\/a><\/p>\n<p>Step 2: insert 36<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image07.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100409\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image07.jpg\" alt=\"Working of AVL tree\" width=\"132\" height=\"161\" \/><\/a><\/p>\n<p>Step 3: insert 120<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image08.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100410\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image08.jpg\" alt=\"Insertion of node in AVL\" width=\"219\" height=\"182\" \/><\/a><\/p>\n<p>Step 4: insert 100<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image09.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100411\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image09.jpg\" alt=\"AVL Working\" width=\"203\" height=\"262\" \/><\/a><\/p>\n<p>Step 5: insert 110<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image010.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100412\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image010.jpg\" alt=\"AVL Inserting node\" width=\"557\" height=\"349\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image010.jpg 557w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image010-520x326.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image010-320x201.jpg 320w\" sizes=\"auto, (max-width: 557px) 100vw, 557px\" \/><\/a><\/p>\n<p>Step 6: insert 130<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image011.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100413\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image011.jpg\" alt=\"Insert node in AVL Tree\" width=\"607\" height=\"349\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image011.jpg 607w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image011-520x299.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image011-320x184.jpg 320w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/a><\/p>\n<p>Step 7: insert 50<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image012.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100414\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image012.jpg\" alt=\"AVL Tree Working\" width=\"312\" height=\"365\" \/><\/a><\/p>\n<p>Step 8: delete 120<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image013.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100415\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image013.jpg\" alt=\"Deletion in AVL Tree\" width=\"578\" height=\"365\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image013.jpg 578w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image013-520x328.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS-normal-image013-320x202.jpg 320w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/a><\/p>\n<h3>Implementation of AVL Tree in C<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n\r\nstruct Node \r\n{\r\n  int Val;\r\n  struct Node *left;\r\n  struct Node *right;\r\n  int height;\r\n};\r\n\r\nint max(int a, int b);\r\n\r\nint height(struct Node *N) \r\n{\r\n  if (N == NULL)\r\n    return 0;\r\n  return N-&gt;height;\r\n}\r\n\r\nint max(int a, int b) \r\n{\r\n  return (a &gt; b) ? a : b;\r\n}\r\n\r\nstruct Node *newNode(int Val) \r\n{\r\n  struct Node *node = (struct Node *)\r\n    malloc(sizeof(struct Node));\r\n  node-&gt;Val = Val;\r\n  node-&gt;left = NULL;\r\n  node-&gt;right = NULL;\r\n  node-&gt;height = 1;\r\n  return (node);\r\n}\r\n\r\nstruct Node *RotateRight(struct Node *y) \r\n{\r\n  struct Node *x = y-&gt;left;\r\n  struct Node *TEMP2 = x-&gt;right;\r\n\r\n  x-&gt;right = y;\r\n  y-&gt;left = TEMP2;\r\n\r\n  y-&gt;height = max(height(y-&gt;left), height(y-&gt;right)) + 1;\r\n  x-&gt;height = max(height(x-&gt;left), height(x-&gt;right)) + 1;\r\n\r\n  return x;\r\n}\r\n\r\nstruct Node *RotateLeft(struct Node *x) \r\n{\r\n  struct Node *y = x-&gt;right;\r\n  struct Node *TEMP2 = y-&gt;left;\r\n\r\n  y-&gt;left = x;\r\n  x-&gt;right = TEMP2;\r\n\r\n  x-&gt;height = max(height(x-&gt;left), height(x-&gt;right)) + 1;\r\n  y-&gt;height = max(height(y-&gt;left), height(y-&gt;right)) + 1;\r\n\r\n  return y;\r\n}\r\n\r\nint getBalance(struct Node *N) \r\n{\r\n  if (N == NULL)\r\n    return 0;\r\n  return height(N-&gt;left) - height(N-&gt;right);\r\n}\r\n\r\nstruct Node *insertNode(struct Node *node, int Val) \r\n{\r\n    \r\n  if (node == NULL)\r\n    return (newNode(Val));\r\n\r\n  if (Val &lt; node-&gt;Val)\r\n    node-&gt;left = insertNode(node-&gt;left, Val);\r\n  else if (Val &gt; node-&gt;Val)\r\n    node-&gt;right = insertNode(node-&gt;right, Val);\r\n  else\r\n    return node;\r\n\r\n  node-&gt;height = 1 + max(height(node-&gt;left),height(node-&gt;right));\r\n\r\n  int balance = getBalance(node);\r\n  if (balance &gt; 1 &amp;&amp; Val &lt; node-&gt;left-&gt;Val)\r\n    return RotateRight(node);\r\n\r\n  if (balance &lt; -1 &amp;&amp; Val &gt; node-&gt;right-&gt;Val)\r\n    return RotateLeft(node);\r\n\r\n  if (balance &gt; 1 &amp;&amp; Val &gt; node-&gt;left-&gt;Val) \r\n  {\r\n    node-&gt;left = RotateLeft(node-&gt;left);\r\n    return RotateRight(node);\r\n  }\r\n\r\n  if (balance &lt; -1 &amp;&amp; Val &lt; node-&gt;right-&gt;Val) \r\n  {\r\n    node-&gt;right = RotateRight(node-&gt;right);\r\n    return RotateLeft(node);\r\n  }\r\n\r\n  return node;\r\n}\r\n\r\nstruct Node *minValueNode(struct Node *node) \r\n{\r\n  struct Node *current = node;\r\n\r\n  while (current-&gt;left != NULL)\r\n    current = current-&gt;left;\r\n\r\n  return current;\r\n}\r\n\r\nstruct Node *deleteNode(struct Node *root, int Val) \r\n{\r\n  if (root == NULL)\r\n    return root;\r\n\r\n  if (Val &lt; root-&gt;Val)\r\n    root-&gt;left = deleteNode(root-&gt;left, Val);\r\n\r\n  else if (Val &gt; root-&gt;Val)\r\n    root-&gt;right = deleteNode(root-&gt;right, Val);\r\n\r\n  else \r\n  {\r\n    if ((root-&gt;left == NULL) || (root-&gt;right == NULL)) \r\n    {\r\n      struct Node *temp = root-&gt;left ? root-&gt;left : root-&gt;right;\r\n\r\n      if (temp == NULL)\r\n      {\r\n        temp = root;\r\n        root = NULL;\r\n      } \r\n      else\r\n        *root = *temp;\r\n      free(temp);\r\n    } \r\n    else \r\n    {\r\n      struct Node *temp = minValueNode(root-&gt;right);\r\n\r\n      root-&gt;Val = temp-&gt;Val;\r\n\r\n      root-&gt;right = deleteNode(root-&gt;right, temp-&gt;Val);\r\n    }\r\n  }\r\n\r\n  if (root == NULL)\r\n    return root;\r\n\r\n  root-&gt;height = 1 + max(height(root-&gt;left),height(root-&gt;right));\r\n\r\n  int balance = getBalance(root);\r\n  if (balance &gt; 1 &amp;&amp; getBalance(root-&gt;left) &gt;= 0)\r\n    return RotateRight(root);\r\n\r\n  if (balance &gt; 1 &amp;&amp; getBalance(root-&gt;left) &lt; 0) \r\n  {\r\n    root-&gt;left = RotateLeft(root-&gt;left);\r\n    return RotateRight(root);\r\n  }\r\n\r\n  if (balance &lt; -1 &amp;&amp; getBalance(root-&gt;right) &lt;= 0)\r\n    return RotateLeft(root);\r\n\r\n  if (balance &lt; -1 &amp;&amp; getBalance(root-&gt;right) &gt; 0) \r\n  {\r\n    root-&gt;right = RotateRight(root-&gt;right);\r\n    return RotateLeft(root);\r\n  }\r\n\r\n  return root;\r\n}\r\n\r\nvoid printPreOrder(struct Node *root) \r\n{\r\n  if (root != NULL) \r\n  {\r\n    printf(\"%d \", root-&gt;Val);\r\n    printPreOrder(root-&gt;left);\r\n    printPreOrder(root-&gt;right);\r\n  }\r\n}\r\n\r\nint main() \r\n{\r\n  struct Node *root = NULL;\r\n\r\n  root = insertNode(root, 56);\r\n  root = insertNode(root, 14);\r\n  root = insertNode(root, 86);\r\n  root = insertNode(root, 25);\r\n  root = insertNode(root, 38);\r\n  root = insertNode(root, 69);\r\n  root = insertNode(root, 89);\r\n\r\n  printPreOrder(root);\r\n\r\n  root = deleteNode(root, 14);\r\n\r\n  printf(\"AVL after deletion: \");\r\n  printPreOrder(root);\r\n\r\n  return 0;\r\n}\r\n<\/pre>\n<h3>AVL Tree implementation in C++<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nstruct Node \r\n{\r\n  int Val;\r\n  struct Node *left;\r\n  struct Node *right;\r\n  int height;\r\n};\r\n\r\nint max(int a, int b);\r\n\r\nint height(struct Node *N) \r\n{\r\n  if (N == NULL)\r\n    return 0;\r\n  return N-&gt;height;\r\n}\r\n\r\nint max(int a, int b) \r\n{\r\n  return (a &gt; b) ? a : b;\r\n}\r\n\r\nstruct Node *newNode(int Val) \r\n{\r\n  struct Node *node = (struct Node *)\r\n    malloc(sizeof(struct Node));\r\n  node-&gt;Val = Val;\r\n  node-&gt;left = NULL;\r\n  node-&gt;right = NULL;\r\n  node-&gt;height = 1;\r\n  return (node);\r\n}\r\n\r\nstruct Node *RotateRight(struct Node *y) \r\n{\r\n  struct Node *x = y-&gt;left;\r\n  struct Node *TEMP2 = x-&gt;right;\r\n\r\n  x-&gt;right = y;\r\n  y-&gt;left = TEMP2;\r\n\r\n  y-&gt;height = max(height(y-&gt;left), height(y-&gt;right)) + 1;\r\n  x-&gt;height = max(height(x-&gt;left), height(x-&gt;right)) + 1;\r\n\r\n  return x;\r\n}\r\n\r\nstruct Node *RotateLeft(struct Node *x) \r\n{\r\n  struct Node *y = x-&gt;right;\r\n  struct Node *TEMP2 = y-&gt;left;\r\n\r\n  y-&gt;left = x;\r\n  x-&gt;right = TEMP2;\r\n\r\n  x-&gt;height = max(height(x-&gt;left), height(x-&gt;right)) + 1;\r\n  y-&gt;height = max(height(y-&gt;left), height(y-&gt;right)) + 1;\r\n\r\n  return y;\r\n}\r\n\r\nint getBalance(struct Node *N) \r\n{\r\n  if (N == NULL)\r\n    return 0;\r\n  return height(N-&gt;left) - height(N-&gt;right);\r\n}\r\n\r\nstruct Node *insertNode(struct Node *node, int Val) \r\n{\r\n    \r\n  if (node == NULL)\r\n    return (newNode(Val));\r\n\r\n  if (Val &lt; node-&gt;Val)\r\n    node-&gt;left = insertNode(node-&gt;left, Val);\r\n  else if (Val &gt; node-&gt;Val)\r\n    node-&gt;right = insertNode(node-&gt;right, Val);\r\n  else\r\n    return node;\r\n\r\n  node-&gt;height = 1 + max(height(node-&gt;left),height(node-&gt;right));\r\n\r\n  int balance = getBalance(node);\r\n  if (balance &gt; 1 &amp;&amp; Val &lt; node-&gt;left-&gt;Val)\r\n    return RotateRight(node);\r\n\r\n  if (balance &lt; -1 &amp;&amp; Val &gt; node-&gt;right-&gt;Val)\r\n    return RotateLeft(node);\r\n\r\n  if (balance &gt; 1 &amp;&amp; Val &gt; node-&gt;left-&gt;Val) \r\n  {\r\n    node-&gt;left = RotateLeft(node-&gt;left);\r\n    return RotateRight(node);\r\n  }\r\n\r\n  if (balance &lt; -1 &amp;&amp; Val &lt; node-&gt;right-&gt;Val) \r\n  {\r\n    node-&gt;right = RotateRight(node-&gt;right);\r\n    return RotateLeft(node);\r\n  }\r\n\r\n  return node;\r\n}\r\n\r\nstruct Node *minValueNode(struct Node *node) \r\n{\r\n  struct Node *current = node;\r\n\r\n  while (current-&gt;left != NULL)\r\n    current = current-&gt;left;\r\n\r\n  return current;\r\n}\r\n\r\nstruct Node *deleteNode(struct Node *root, int Val) \r\n{\r\n  if (root == NULL)\r\n    return root;\r\n\r\n  if (Val &lt; root-&gt;Val)\r\n    root-&gt;left = deleteNode(root-&gt;left, Val);\r\n\r\n  else if (Val &gt; root-&gt;Val)\r\n    root-&gt;right = deleteNode(root-&gt;right, Val);\r\n\r\n  else \r\n  {\r\n    if ((root-&gt;left == NULL) || (root-&gt;right == NULL)) \r\n    {\r\n      struct Node *temp = root-&gt;left ? root-&gt;left : root-&gt;right;\r\n\r\n      if (temp == NULL)\r\n      {\r\n        temp = root;\r\n        root = NULL;\r\n      } \r\n      else\r\n        *root = *temp;\r\n      free(temp);\r\n    } \r\n    else \r\n    {\r\n      struct Node *temp = minValueNode(root-&gt;right);\r\n\r\n      root-&gt;Val = temp-&gt;Val;\r\n\r\n      root-&gt;right = deleteNode(root-&gt;right, temp-&gt;Val);\r\n    }\r\n  }\r\n\r\n  if (root == NULL)\r\n    return root;\r\n\r\n  root-&gt;height = 1 + max(height(root-&gt;left),height(root-&gt;right));\r\n\r\n  int balance = getBalance(root);\r\n  if (balance &gt; 1 &amp;&amp; getBalance(root-&gt;left) &gt;= 0)\r\n    return RotateRight(root);\r\n\r\n  if (balance &gt; 1 &amp;&amp; getBalance(root-&gt;left) &lt; 0) \r\n  {\r\n    root-&gt;left = RotateLeft(root-&gt;left);\r\n    return RotateRight(root);\r\n  }\r\n\r\n  if (balance &lt; -1 &amp;&amp; getBalance(root-&gt;right) &lt;= 0)\r\n    return RotateLeft(root);\r\n\r\n  if (balance &lt; -1 &amp;&amp; getBalance(root-&gt;right) &gt; 0) \r\n  {\r\n    root-&gt;right = RotateRight(root-&gt;right);\r\n    return RotateLeft(root);\r\n  }\r\n\r\n  return root;\r\n}\r\n\r\nvoid printPreOrder(struct Node *root) \r\n{\r\n  if (root != NULL) \r\n  {\r\n    printf(\"%d \", root-&gt;Val);\r\n    printPreOrder(root-&gt;left);\r\n    printPreOrder(root-&gt;right);\r\n  }\r\n}\r\n\r\nint main() \r\n{\r\n  struct Node *root = NULL;\r\n\r\n  root = insertNode(root, 56);\r\n  root = insertNode(root, 14);\r\n  root = insertNode(root, 86);\r\n  root = insertNode(root, 25);\r\n  root = insertNode(root, 38);\r\n  root = insertNode(root, 69);\r\n  root = insertNode(root, 89);\r\n\r\n  printPreOrder(root);\r\n\r\n  root = deleteNode(root, 14);\r\n\r\n  cout &lt;&lt;\"AVL after deletion: \" ;\r\n  printPreOrder(root);\r\n\r\n  return 0;\r\n}\r\n<\/pre>\n<h3>Implementation of AVL Tree in JAVA<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Node {\r\n  int item, height;\r\n  Node left, right;\r\n\r\n  Node(int d) {\r\n    item = d;\r\n    height = 1;\r\n  }\r\n}\r\n\r\nclass AVL {\r\n  Node root;\r\n\r\n  int height(Node N) {\r\n    if (N == null)\r\n      return 0;\r\n    return N.height;\r\n  }\r\n\r\n  int max(int a, int b) {\r\n    return (a &gt; b) ? a : b;\r\n  }\r\n\r\n  Node RotateRight(Node y) {\r\n    Node x = y.left;\r\n    Node T2 = x.right;\r\n    x.right = y;\r\n    y.left = T2;\r\n    y.height = max(height(y.left), height(y.right)) + 1;\r\n    x.height = max(height(x.left), height(x.right)) + 1;\r\n    return x;\r\n  }\r\n\r\n  Node RotateLeft(Node x) {\r\n    Node y = x.right;\r\n    Node T2 = y.left;\r\n    y.left = x;\r\n    x.right = T2;\r\n    x.height = max(height(x.left), height(x.right)) + 1;\r\n    y.height = max(height(y.left), height(y.right)) + 1;\r\n    return y;\r\n  }\r\n\r\n  int getBalanceFactor(Node N) {\r\n    if (N == null)\r\n      return 0;\r\n    return height(N.left) - height(N.right);\r\n  }\r\n\r\n  Node insertNode(Node node, int item) {\r\n\r\n    if (node == null)\r\n      return (new Node(item));\r\n    if (item &lt; node.item)\r\n      node.left = insertNode(node.left, item);\r\n    else if (item &gt; node.item)\r\n      node.right = insertNode(node.right, item);\r\n    else\r\n      return node;\r\n\r\n    node.height = 1 + max(height(node.left), height(node.right));\r\n    int balanceFactor = getBalanceFactor(node);\r\n    if (balanceFactor &gt; 1) {\r\n      if (item &lt; node.left.item) {\r\n        return RotateRight(node);\r\n      } else if (item &gt; node.left.item) {\r\n        node.left = RotateLeft(node.left);\r\n        return RotateRight(node);\r\n      }\r\n    }\r\n    if (balanceFactor &lt; -1) {\r\n      if (item &gt; node.right.item) {\r\n        return RotateLeft(node);\r\n      } else if (item &lt; node.right.item) {\r\n        node.right = RotateRight(node.right);\r\n        return RotateLeft(node);\r\n      }\r\n    }\r\n    return node;\r\n  }\r\n\r\n  Node nodeWithMimumValue(Node node) {\r\n    Node current = node;\r\n    while (current.left != null)\r\n      current = current.left;\r\n    return current;\r\n  }\r\n\r\n  Node deleteNode(Node root, int item) {\r\n\r\n    if (root == null)\r\n      return root;\r\n    if (item &lt; root.item)\r\n      root.left = deleteNode(root.left, item);\r\n    else if (item &gt; root.item)\r\n      root.right = deleteNode(root.right, item);\r\n    else {\r\n      if ((root.left == null) || (root.right == null)) {\r\n        Node temp = null;\r\n        if (temp == root.left)\r\n          temp = root.right;\r\n        else\r\n          temp = root.left;\r\n        if (temp == null) {\r\n          temp = root;\r\n          root = null;\r\n        } else\r\n          root = temp;\r\n      } else {\r\n        Node temp = nodeWithMimumValue(root.right);\r\n        root.item = temp.item;\r\n        root.right = deleteNode(root.right, temp.item);\r\n      }\r\n    }\r\n    if (root == null)\r\n      return root;\r\n\r\n    root.height = max(height(root.left), height(root.right)) + 1;\r\n    int balanceFactor = getBalanceFactor(root);\r\n    if (balanceFactor &gt; 1) {\r\n      if (getBalanceFactor(root.left) &gt;= 0) {\r\n        return RotateRight(root);\r\n      } else {\r\n        root.left = RotateLeft(root.left);\r\n        return RotateRight(root);\r\n      }\r\n    }\r\n    if (balanceFactor &lt; -1) {\r\n      if (getBalanceFactor(root.right) &lt;= 0) {\r\n        return RotateLeft(root);\r\n      } else {\r\n        root.right = RotateRight(root.right);\r\n        return RotateLeft(root);\r\n      }\r\n    }\r\n    return root;\r\n  }\r\n\r\n  void preOrder(Node node) {\r\n    if (node != null) {\r\n      System.out.print(node.item + \" \");\r\n      preOrder(node.left);\r\n      preOrder(node.right);\r\n    }\r\n  }\r\n\r\n  private void printTree(Node currPtr, boolean last) {\r\n    if (currPtr != null) \r\n    {\r\n      \r\n      System.out.print(currPtr.item+ \" \");\r\n      printTree(currPtr.left, false);\r\n      printTree(currPtr.right, true);\r\n    }\r\n  }\r\n\r\n  public static void main(String[] args)\r\n  {\r\n    AVL tree = new AVL();\r\n    tree.root = tree.insertNode(tree.root, 56);\r\n    tree.root = tree.insertNode(tree.root, 14);\r\n    tree.root = tree.insertNode(tree.root, 86);\r\n    tree.root = tree.insertNode(tree.root, 25);\r\n    tree.root = tree.insertNode(tree.root, 38);\r\n    tree.root = tree.insertNode(tree.root, 69);\r\n    tree.root = tree.insertNode(tree.root, 89);\r\n    tree.printTree(tree.root, true);\r\n    tree.root = tree.deleteNode(tree.root, 14);\r\n    System.out.println(\"AVL After Deletion: \");\r\n    tree.printTree(tree.root, true);\r\n  }\r\n}\r\n<\/pre>\n<h3>Implementation of AVL Tree in Python<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import sys\r\nclass TreeNode(object):\r\n    def __init__(self, key):\r\n        self.key = key\r\n        self.left = None\r\n        self.right = None\r\n        self.height = 1\r\n\r\n\r\nclass AVLTree(object):\r\n\r\n    def insert_node(self, root, key):\r\n\r\n        if not root:\r\n            return TreeNode(key)\r\n        elif key &lt; root.key:\r\n            root.left = self.insert_node(root.left, key)\r\n        else:\r\n            root.right = self.insert_node(root.right, key)\r\n\r\n        root.height = 1 + max(self.getHeight(root.left),self.getHeight(root.right))\r\n\r\n        balanceFactor = self.getBalance(root)\r\n        if balanceFactor &gt; 1:\r\n            if key &lt; root.left.key:\r\n                return self.RotateRight(root)\r\n            else:\r\n                root.left = self.RotateLeft(root.left)\r\n                return self.RotateRight(root)\r\n\r\n        if balanceFactor &lt; -1:\r\n            if key &gt; root.right.key:\r\n                return self.RotateLeft(root)\r\n            else:\r\n                root.right = self.RotateRight(root.right)\r\n                return self.RotateLeft(root)\r\n\r\n        return root\r\n\r\n    def delete_node(self, root, key):\r\n\r\n        if not root:\r\n            return root\r\n        elif key &lt; root.key:\r\n            root.left = self.delete_node(root.left, key)\r\n        elif key &gt; root.key:\r\n            root.right = self.delete_node(root.right, key)\r\n        else:\r\n            if root.left is None:\r\n                temp = root.right\r\n                root = None\r\n                return temp\r\n            elif root.right is None:\r\n                temp = root.left\r\n                root = None\r\n                return temp\r\n            temp = self.getMinValueNode(root.right)\r\n            root.key = temp.key\r\n            root.right = self.delete_node(root.right,\r\n                                          temp.key)\r\n        if root is None:\r\n            return root\r\n\r\n        root.height = 1 + max(self.getHeight(root.left),\r\n                              self.getHeight(root.right))\r\n\r\n        balanceFactor = self.getBalance(root)\r\n\r\n        if balanceFactor &gt; 1:\r\n            if self.getBalance(root.left) &gt;= 0:\r\n                return self.RotateRight(root)\r\n            else:\r\n                root.left = self.RotateLeft(root.left)\r\n                return self.RotateRight(root)\r\n        if balanceFactor &lt; -1:\r\n            if self.getBalance(root.right) &lt;= 0:\r\n                return self.RotateLeft(root)\r\n            else:\r\n                root.right = self.RotateRight(root.right)\r\n                return self.RotateLeft(root)\r\n        return root\r\n\r\n    def RotateLeft(self, z):\r\n        y = z.right\r\n        T2 = y.left\r\n        y.left = z\r\n        z.right = T2\r\n        z.height = 1 + max(self.getHeight(z.left),self.getHeight(z.right))\r\n        y.height = 1 + max(self.getHeight(y.left),self.getHeight(y.right))\r\n        return y\r\n\r\n    def RotateRight(self, z):\r\n        y = z.left\r\n        T3 = y.right\r\n        y.right = z\r\n        z.left = T3\r\n        z.height = 1 + max(self.getHeight(z.left),self.getHeight(z.right))\r\n        y.height = 1 + max(self.getHeight(y.left),self.getHeight(y.right))\r\n        return y\r\n\r\n    def getHeight(self, root):\r\n        if not root:\r\n            return 0\r\n        return root.height\r\n\r\n    def getBalance(self, root):\r\n        if not root:\r\n            return 0\r\n        return self.getHeight(root.left) - self.getHeight(root.right)\r\n\r\n    def getMinValueNode(self, root):\r\n        if root is None or root.left is None:\r\n            return root\r\n        return self.getMinValueNode(root.left)\r\n\r\n    def preOrder(self, root):\r\n        if not root:\r\n            return\r\n        print(\"{0} \".format(root.key), end=\"\")\r\n        self.preOrder(root.left)\r\n        self.preOrder(root.right)\r\n\r\n    def printAVL(self, currPtr, last):\r\n        if currPtr != None:\r\n            \r\n            print(currPtr.key)\r\n            self.printAVL(currPtr.left, False)\r\n            self.printAVL(currPtr.right, True)\r\n\r\n\r\nmyTree = AVLTree()\r\nroot = None\r\nnums = [56, 14, 86, 25, 38, 69, 89]\r\nfor num in nums:\r\n    root = myTree.insert_node(root, num)\r\nmyTree.printAVL(root, True)\r\nkey = 14\r\nroot = myTree.delete_node(root, key)\r\nprint(\"After Deletion: \")\r\nmyTree.printAVL(root, True)\r\n<\/pre>\n<h3>Complexity of AVL tree<\/h3>\n<p>Insertion: O( log n )<br \/>\nDeletion: O( log n )<br \/>\nSearch: O( log n )<\/p>\n<h3>Applications of AVL Tree<\/h3>\n<ul>\n<li>Searching operations in very large datasets<\/li>\n<li>Indexing of data in very large databases.<\/li>\n<\/ul>\n<h3>Conclusion<\/h3>\n<p>AVL Trees are self-balancing binary trees. If at any point, during insertion or deletion, there is an unbalancing in the tree, it is again balanced by different rotations. AVL Trees are more balanced than red-black trees. AVL Tree is preferred over red-black trees in cases where the insertion and deletion are less frequent.<\/p>\n<p>In further articles, we will learn about another type of binary tree known as spanning tree.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>AVL tree is a specific type of binary search tree where the difference between heights of left and right subtrees is either 0 or 1 only for all nodes. It implements all properties of&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":100402,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24020],"tags":[24901,24897,24899,24900,24898],"class_list":["post-100203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-structure-tutorials","tag-applications-of-avl-tree","tag-avl-tree","tag-avl-tree-implementation-in-c","tag-complexity-of-avl-tree","tag-implementation-of-avl-tree-in-ds"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>AVL Tree in Data Structure - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn what is AVL tree in Data Structure. See AVL rotations, operations, Working, implementation, applications &amp; complexity of AVL tree.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/avl-tree\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AVL Tree in Data Structure - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn what is AVL tree in Data Structure. See AVL rotations, operations, Working, implementation, applications &amp; complexity of AVL tree.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/avl-tree\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-20T03:30:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"AVL Tree in Data Structure - DataFlair","description":"Learn what is AVL tree in Data Structure. See AVL rotations, operations, Working, implementation, applications & complexity of AVL tree.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/avl-tree\/","og_locale":"en_US","og_type":"article","og_title":"AVL Tree in Data Structure - DataFlair","og_description":"Learn what is AVL tree in Data Structure. See AVL rotations, operations, Working, implementation, applications & complexity of AVL tree.","og_url":"https:\/\/data-flair.training\/blogs\/avl-tree\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-08-20T03:30:38+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/avl-tree\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/avl-tree\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9"},"headline":"AVL Tree in Data Structure","datePublished":"2021-08-20T03:30:38+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/avl-tree\/"},"wordCount":644,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/avl-tree\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS.jpg","keywords":["Applications of AVL Tree","AVL tree","AVL Tree implementation in C++","Complexity of AVL tree","Implementation of AVL Tree in DS"],"articleSection":["Data Structure Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/avl-tree\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/avl-tree\/","url":"https:\/\/data-flair.training\/blogs\/avl-tree\/","name":"AVL Tree in Data Structure - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/avl-tree\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/avl-tree\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS.jpg","datePublished":"2021-08-20T03:30:38+00:00","description":"Learn what is AVL tree in Data Structure. See AVL rotations, operations, Working, implementation, applications & complexity of AVL tree.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/avl-tree\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/avl-tree\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/avl-tree\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/08\/AVL-tree-in-DS.jpg","width":1200,"height":628,"caption":"AVL tree in DS"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/avl-tree\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Data Structure Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/data-structure-tutorials\/"},{"@type":"ListItem","position":3,"name":"AVL Tree in Data Structure"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team is a group of passionate educators and industry experts dedicated to providing high-quality online learning resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With years of experience in the field, the team aims to simplify complex topics and help learners advance their careers. At DataFlair, we believe in empowering students and professionals with the knowledge and skills needed to thrive in today\u2019s fast-paced tech industry. Follow us for Free courses, expert insights, tutorials, and practical tips to boost your learning journey.","url":"https:\/\/data-flair.training\/blogs\/author\/datafbdad\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/100203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=100203"}],"version-history":[{"count":2,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/100203\/revisions"}],"predecessor-version":[{"id":100416,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/100203\/revisions\/100416"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/100402"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=100203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=100203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=100203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}