Advertisement
bwukki

Untitled

Dec 6th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 3.12 KB | None | 0 0
  1. \documentclass[12pt]{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage{amsmath}
  4. \usepackage{graphicx}
  5.  
  6. \title{Derivations For updating balance factors in AVL trees after rotations}
  7. \author{Blake Cecil}
  8.  
  9.  
  10. \begin{document}
  11.  
  12. \maketitle
  13.  
  14. \section*{Left Rotations}
  15.  
  16. \begin{figure}[h]
  17. \centering
  18. \includegraphics[width=13cm]{avl.png}
  19. \caption{A tree after left rotation}
  20. \end{figure}
  21. Allow $h_x$ to denote a sub-tree rooted at x. First we will calculate the new balance factor for B\\
  22.  
  23. By Definition we have:\\
  24. \begin{align*}
  25. newBal(B) &= h_a - h_c\\
  26. oldBal(B) &= h_a - h_d
  27. \end{align*}\\
  28.  
  29. However the height of d can also be given by $1 + max(h_c, h_e)$ so by substitution:\\
  30.  
  31. $$oldbal(B)=h_a - (1 + max(h_c, h_e)$$\\
  32. Subtracting the old balance yields\\
  33. \begin{align*}
  34. newBal(B)-oldBal(B) &= h_a - h_c -(h_a - (1 + max(h_c, h_e))\\
  35. newBal(B)-oldBal(B) &= h_a - h_c -h_a + (1 + max(h_c, h_e))\\
  36. newBal(B)-oldBal(B) &= - h_c + (1 + max(h_c, h_e))\\
  37. newBal(B) &= oldBal(B) + 1 + max(h_c, h_e) - h_c
  38. \end{align*}\\
  39. Applying the identity $max(a, b)-c = max(a-c, b- c)$ yields\\
  40. \begin{align*}
  41. newBal(B) &= oldBal(B) + 1 + max(h_c-h_c, h_e-h_c)\\
  42. newBal(B) &= oldBal(B) + 1 + max(0, h_e-h_c)
  43. \end{align*}\\
  44. Returning to our original picture notice $h_e-h_c = -oldBal(D)$ so by substitution\\
  45. $$newBal(B) = oldBal(B) + 1 + max(0, -oldBal(D))$$\\
  46. Applying the identity $max(-a,-b) = -min(a, b)$ yields\\
  47. $$newBal(B) = oldBal(B) + 1 - min(0, oldbal(D)$$\\
  48. So $newBal(B) = oldBal(B) + 1 - min(0, oldbal(D)$ is the updated balance factor for Node B after a left rotate\\
  49. We know want to determine the new balance for D\\
  50. By Definition we have\\
  51. \begin{align*}
  52. newBal(D) &= h_b - h_e\\
  53. oldBal(D) &= h_c - h_e
  54. \end{align*}\\
  55. However the height of b can also be given by $1 + max(h_a, h_c)$ so by substitution\\
  56. $$newBal(D) = 1 + max(h_a, h_c) - h_e$$\\
  57. Subtracting the old balance yields:\\
  58. \begin{align*}
  59. newBal(D) - oldBal(D) &= 1 + max(h_a, h_c) - h_e - (h_c - h_e)\\
  60. newBal(D) - oldBal(D) &= 1 + max(h_a, h_c) - h_e - h_c + h_e\\
  61. newBal(D) - oldBal(D) &= 1 + max(h_a, h_c) - h_c
  62. \end{align*}\\
  63. Applying the identity $max(a, b)-c = max(a-c, b- c)$ yields\\
  64. $$newBal(D) - oldBal(D) = 1 + max(h_a - h_c, 0)$$\\
  65. Returning to our original picture notice $h_a - h_c = newBal(B)$ so by substitution\\
  66. \begin{align*}
  67. newBal(D) - oldBal(D) &= 1 + max(newBal(B), 0)\\
  68. newBal(D) &= oldBal(D) + 1 + max(newBal(B), 0)
  69. \end{align*}
  70. \section*{Right rotations}
  71. By definition, we know that Blake is a doo-doo head. Thus it is trivial to see:
  72. $$E(t) = \text{Curtis' ego} = e^{2t}$$\\
  73. And thus long term behavior is categorized by:
  74. \begin{align*}
  75. \lim_{a \to \infty} \int_0^a E(t) dt &= \lim_{a \to \infty} \int_0^a e^{2t} dt\\
  76. &= \infty
  77. \end{align*}
  78. And so as $t$ tends to $\infty$ his ego will as well. And this shit is fucking $\mathcal{O}(n\log{}n)$  
  79.  
  80. \begin{minipage}[c]{0.35\linewidth}
  81. \begin{align*}
  82. \mathcal{O}(n!logloglogloglog(n^n)) &= 4x+y3^{2^2}\\
  83. &= \text{blue}\\
  84. &= f(uck)
  85. \end{align*}
  86. \end{minipage}
  87. \hfill
  88. \begin{minipage}[c]{0.35\linewidth}
  89. Well fuck
  90. \end{minipage}
  91.  
  92. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement