2 3 t r e e s a a t r e e s b t r e e s a n n o u n c e m
play

2 - 3 t r e e s , A A t r e e s , B - t r e e - PowerPoint PPT Presentation

2 - 3 t r e e s , A A t r e e s , B - t r e e s A n n o u n c e m e n t C o n s u l t a t i o n t i m e s 1 0 - 1 2 , r o o m E S 6 1 ! Mo n d a y 9 Ma y t h


  1. 2 - 3 t r e e s , A A t r e e s , B - t r e e s

  2. A n n o u n c e m e n t C o n s u l t a t i o n t i m e s – 1 0 - 1 2 , r o o m E S 6 1 ! ● Mo n d a y 9 Ma y t h ● Tiu r s d a y 1 2 Ma y t h ● Tiu r s d a y 1 9 Ma y t h ● Mo n d a y 2 3 Ma y r d N o p l a n – j u s t c o m e a n d a s k q u e s t i o n s P . S . d o n ' t f o r g e t t h e r e a r e e x e r c i s e s o n t h e w e b s i t e !

  3. 2 - 3 t r e e s I n a b i n a r y t r e e , e a c h n o d e h a s t w o c h i l d r e n I n a 2 - 3 t r e e , e a c h n o d e h a s e i t h e r 2 c h i l d r e n ( a ) o r 3 ( a ) 2 - n o d e 3 - n o d e A 2 - n o d e i s a n o r m a l B S T n o d e : ● O n e d a t a v a l u e x , w h i c h i s g r e a t e r t h a n a l l v a l u e s i n t h e l e f t s u b t r e e a n d l e s s t h a n a l l v a l u e s i n t h e r i g h t s u b t r e e A 3 - n o d e i s d i fg e r e n t : ● T d a t a v a l u e s a n d w o x y ● A l l t h e v a l u e s i n t h e l e f t s u b t r e e a r e l e s s t h a n x ● A l l t h e v a l u e s i n t h e m i d d l e s u b t r e e a r e b e t w e e n a n d x y ● A l l t h e v a l u e s i n t h e r i g h t s u b t r e e a r e g r e a t e r t h a n y

  4. 2 - 3 t r e e s A n e x a m p l e o f a 2 - 3 t r e e :

  5. W h y 2 - 3 t r e e s ? Wi t h a 2 - 3 t r e e w e c a n m a i n t a i n t h e i n v a r i a n t : ● Tie t r e e i s a l w a y s p e r f e c t l y b a l a n c e d ! I n v a r i a n t : a l l c h i l d r e n o f e a c h n o d e h a v e t h e s a m e h e i g h t a l w a y s ● I n p a r t i c u l a r , a n y n o n - l e a f 2 - n o d e h a s 2 c h i l d r e n ● A n y n o n - l e a f 3 - n o d e h a s 3 c h i l d r e n Tii s w a s n ' t p o s s i b l e w i t h b i n a r y s e a r c h t r e e s

  6. W h i c h o f t h e s e a r e 2 - 3 t r e e s ? 7 7 2 1 11 5 2 1 1 1 5 1 3 4 5 9 1 3 1 7 1 9 1 9 1 3 1 71 9 7 7 2 2 1 11 5 1 11 5 1 5 9 1 3 1 71 9 1 5 9 1 71 9

  7. W h i c h o f t h e s e a r e 2 - 3 t r e e s ? 7 7 2 1 11 5 2 1 1 1 5 1 3 4 5 9 1 3 1 7 1 9 1 9 1 3 1 71 9 O n l y t h i s o n e 7 7 ( w h y ? ) 2 2 1 11 5 1 11 5 1 5 9 1 3 1 71 9 1 5 9 1 71 9

  8. I n s e r t i o n i n t o a 2 - 3 t r e e T o i n s e r t a v a l u e ( e . g . 4 ) i n t o a 2 - 3 t r e e , w e s t a r t b y d o i n g a n o r m a l i n s e r t i o n . . . 7 2 1 1 1 5 1 5 9 1 3 1 7 1 9 W e b r o k e t h e b a l a n c e i n v a r i a n t ! 4

  9. I n s e r t i o n i n t o a 2 - 3 t r e e T o fj x t h e b a l a n c e i n v a r i a n t , w e a b s o r b t h e b a d n o d e i n t o i t s p a r e n t ! 7 2 1 1 1 5 1 9 1 3 1 7 1 9 4 5 4 g o t a b s o r b e d i n t o 5

  10. I n s e r t i o n i n t o a 2 - 3 t r e e N o w s u p p o s e w e w a n t t o i n s e r t 3 . W e ' l l a b s o r b i t i n t o i t s p a r e n t a s b e f o r e . . . 7 2 1 1 1 5 1 4 5 9 1 3 1 7 1 9 3

  11. I n s e r t i o n i n t o a 2 - 3 t r e e W e g e t a 4 - n o d e , w h i c h i s n o t a l l o w e d ! W e fj x t h i s b y a m e t h o d c a l l e d . s p l i t t i n g 7 2 1 1 1 5 1 9 1 3 1 7 1 9 3 4 5

  12. S p l i t t i n g a 4 - n o d e T o g e t r i d o f a 4 - n o d e , w e i t i n t o s p l i t s e v e r a l 2 - n o d e s ! Tii s c r e a t e s a n e x t r a l e v e l i n t h e t r e e . W e w i l l fj x t h i s b y a b s o r b i n g y t h e r e d n o d e i n t o i t s p a r e n t . x y z x z A B C D A B C D

  13. I n s e r t i o n i n t o a 2 - 3 t r e e A f t e r s p l i t t i n g , w e a b s o r b t h e “ e x t r a l e v e l ” n o d e i n t o i t s p a r e n t . 7 A b s o r b 4 i n t o 2 . 2 1 1 1 5 1 9 1 3 1 7 1 9 4 3 5

  14. I n s e r t i o n i n t o a 2 - 3 t r e e W e r e s t o r e d t h e i n v a r i a n t ! L e t ' s t r y i n s e r t i n g 1 8 . 7 2 4 1 1 1 5 1 9 1 3 1 7 1 9 3 5

  15. I n s e r t i o n i n t o a 2 - 3 t r e e F i r s t a d d a n d a b s o r b . W e g o t a 4 - n o d e , s p l i t i t . 7 2 4 1 1 1 5 1 3 5 9 1 3 1 7 1 8 1 9

  16. I n s e r t i o n i n t o a 2 - 3 t r e e A b s o r b t h e e x t r a n o d e i n t o t h e p a r e n t . 7 2 4 1 1 1 5 1 3 5 9 1 3 1 8 1 7 1 9

  17. I n s e r t i o n i n t o a 2 - 3 t r e e W e g o t a 4 - n o d e a g a i n , s o s p l i t a n d a b s o r b . 1 5 w i l l b e a b s o r b e d 7 2 4 1 1 1 5 1 8 1 3 5 9 1 3 1 7 1 9

  18. I n s e r t i o n i n t o a 2 - 3 t r e e D o n e ! ( I f w e i n s e r t e v e n m o r e , e v e n t u a l l y t h e r o o t w i l l s p l i t , w h i c h a d d s a n e w l e v e l t o t h e t r e e . ) 7 1 5 2 4 1 1 1 8 1 3 5 9 1 3 1 7 1 9

  19. 2 - 3 i n s e r t i o n a l g o r i t h m I n s e r t t h e n e w n o d e i n t o t h e t r e e Tie n a l t e r n a t e 2 s t e p s : ● a b s o r b t h e n o d e i n t o i t s p a r e n t , m o v e u p t o t h e p a r e n t ● i f t h e n o d e i s a 4 - n o d e , i t i n t o 2 - n o d e s s p l i t S t o p o n c e y o u d o n ' t n e e d t o s p l i t

  20. 2 - 3 t r e e s , s u m m a r y 2 - 3 t r e e s d o n o t u s e r o t a t i o n , u n l i k e b a l a n c e d B S T s – i n s t e a d , t h e y k e e p t h e t r e e p e r f e c t l y b a l a n c e d ● I n v a r i a n t m a i n t a i n e d u s i n g a b s o r p t i o n ( t o r e m o v e u n w a n t e d n o d e s ) a n d ( t o e l i m i n a t e 4 - n o d e s ) s p l i t t i n g C o m p l e x i t y i s O ( l o g n ) , a s t r e e i s p e r f e c t l y b a l a n c e d C o n c e p t u a l l y m u c h s i m p l e r t h a n A V L t r e e s ! B u t i m p l e m e n t a t i o n i s r e a l l y a n n o y i n g : ( ● S e e T w o Tir e e . h s

  21. A A t r e e s

  22. A A t r e e s A A t r e e s i m p l e m e n t a 2 - 3 t r e e u s i n g a B S T ! A 2 - n o d e b e c o m e s a B S T n o d e A 3 - n o d e b e c o m e s t w o B S T n o d e s : x x y A y A B C W e ' l l a l w a y s t r a n s l a t e a 3 - n o d e B C i n t o a n o d e a n d i t s r i g h t c h i l d

  23. A A t r e e s , t h e p l a n A n A A t r e e i s r e a l l y a 2 - 3 t r e e , b u t w e s t o r e i t i n a b i n a r y s e a r c h t r e e ● A b i t l i k e w h a t w e d i d f o r b i n a r y h e a p s W e ' l l n e e d t o a d d e x t r a i n f o r m a t i o n t o t h e n o d e s , a n d i n v a r i a n t s , s o t h a t : ● A n y A A t r e e m u s t c o r r e s p o n d t o a 2 - 3 t r e e ● W e c a n t e l l w h e t h e r e a c h n o d e i n t h e t r e e i s a 2 - n o d e , o r p a r t o f a 3 - n o d e Tie n w e c a n a d a p t 2 - 3 i n s e r t i o n t o A A t r e e s ! ● F o r s e a r c h i n g , w e c a n j u s t u s e B S T s e a r c h

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend