1 / 25

Splay Tree

O(N). - פעולה בודדת יכולה לקחת. (O(M log N. - אבל כל רצף M פעולות לוקח. - בעית עץ חיפוש בינארי - עץ עמוק (לא מאוזן).  אם ביקשנו צומת מסוים הנמצא עמוק עלינו לשנות את העץ - אחרת M גישות אליו יגרמו ל -. (O(M*N. - תכונה נוספת: צמתים שנגענו בהם צפים למעלה.

aradia
Download Presentation

Splay Tree

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. O(N) - פעולה בודדת יכולה לקחת (O(M log N - אבל כל רצףM פעולות לוקח - בעית עץ חיפוש בינארי - עץ עמוק (לא מאוזן) אם ביקשנו צומת מסוים הנמצא עמוק עלינו לשנות את העץ - אחרתM גישות אליו יגרמו ל- (O(M*N - תכונה נוספת: צמתים שנגענו בהם צפים למעלה תורם לביצועים כי סיכויי הגישה החוזרת גבוהים. Splay Tree - עץ חיפוש בינארי - מטרה לדאוג ל- Amortized Time Data Structures, CS, TAU, Splay Tree

  2. דוגמא: (מסלול גישה מסומן באדום) k3 k5 k4 k2 k4 k2 k1 k3 k1 k5 Rotate Rotate D F A C B E B E A D C F רעיוןפשוט: הצף את הצומת שניגשו אליו ע”י Rotate Data Structures, CS, TAU, Splay Tree

  3. (מסלול גישה מסומן באדום) k5 k4 k1 k3 k2 k1 k2 k3 k4 k5 Rotate Rotate F F E D A B C A C B D E Data Structures, CS, TAU, Splay Tree

  4. k5 k4 k3 k2 k1 Rotate A C B D E F Data Structures, CS, TAU, Splay Tree

  5. (M*N) בעיה: ישנם מקרים שלוקחים דוגמה לבעיה זובעמ’ הבא. לא בטוח ש צריך את הדוגמא בכלל!!!! בעיות בעץ בעיה:k3שקוע (כמעט) לעומקו המקורי שלk1 Data Structures, CS, TAU, Splay Tree

  6. דוגמא: Find(1) 5 3 4 2 1 5 3 4 1 2 4 5 4 2 3 5 1 2 3 4 2 1 3 5 1 Data Structures, CS, TAU, Splay Tree

  7. Find(2) 1 2 1 3 4 5 3 1 4 5 2 2 3 5 2 3 1 4 5 2 3 1 4 4 5 Find(3) Find(4) Data Structures, CS, TAU, Splay Tree

  8.  N פעולות לוקחות שפוץ: ביצוע Rotateמשופר, המבוצע על שלישיית צמתים. ( שתי אפשרויות: ) Zig-zag Zig-zig Data Structures, CS, TAU, Splay Tree

  9. X P G P X X G G P P G X B A A D B C A C A B C D B C D D Zig-zag Zig-zig Data Structures, CS, TAU, Splay Tree

  10. k1,Zig-Zag gives: k4 k5 k2 k1 k3 k2 k3 k4 k5 k1 k1,Zig-Zig gives: D A A C B E E F C B D F חזרה לדוגמא Data Structures, CS, TAU, Splay Tree

  11. Splaying at node 1 5 3 4 2 1 7 6 5 4 7 6 1 5 3 1 4 6 5 7 2 3 1 2 7 6 4 2 3 Data Structures, CS, TAU, Splay Tree

  12. דוגמא (אותה דוגמה חוזרת מוגדלת מאוחר יותר) Data Structures, CS, TAU, Splay Tree

  13. המשך דוגמא Data Structures, CS, TAU, Splay Tree

  14. המשך דוגמא Data Structures, CS, TAU, Splay Tree

  15. סוף דוגמא Data Structures, CS, TAU, Splay Tree

  16. Result of splaying at node 1 a tree of all left children 32 30 3 2 5 4 7 6 9 8 11 10 13 12 15 14 25 1 19 18 21 20 23 22 17 24 27 26 29 28 31 16 אותה דוגמא מוגדלת Data Structures, CS, TAU, Splay Tree

  17. Result of splaying previous tree at node 2 4 5 7 6 32 2 3 8 9 11 10 12 13 15 1 16 17 14 19 18 20 21 23 30 22 25 27 26 28 29 31 24 Data Structures, CS, TAU, Splay Tree

  18. Result of splaying previous tree at node 3 4 3 8 9 11 10 2 5 7 6 12 16 17 19 1 13 15 18 14 20 24 25 27 30 26 23 22 28 32 29 31 21 Data Structures, CS, TAU, Splay Tree

  19. Result of splaying previous tree at node 4 6 32 3 2 8 9 11 10 7 5 28 29 31 30 12 16 17 1 19 18 13 15 14 20 24 27 26 21 23 22 4 25 Data Structures, CS, TAU, Splay Tree

  20. Result of splaying previous tree at node 5 32 3 2 28 29 31 30 1 16 17 19 18 13 15 12 24 25 14 27 26 21 23 22 5 4 8 9 11 10 6 7 20 Data Structures, CS, TAU, Splay Tree

  21. Result of splaying previous tree at node 6 32 28 29 31 30 16 17 19 18 13 15 14 24 25 6 26 21 27 23 22 20 8 9 5 11 7 12 3 2 1 4 10 Data Structures, CS, TAU, Splay Tree

  22. Result of splaying previous tree at node 7 32 28 29 31 30 16 17 19 18 13 15 14 24 25 8 26 21 27 23 22 20 9 11 7 10 3 2 1 4 5 6 12 Data Structures, CS, TAU, Splay Tree

  23. Result of splaying previous tree at node 8 32 28 29 31 30 16 17 19 18 13 15 14 24 25 8 26 21 27 23 22 20 9 11 7 10 3 2 1 4 5 6 12 Data Structures, CS, TAU, Splay Tree

  24. Result of splaying previous tree at node 9 32 28 29 31 30 16 17 19 18 13 15 14 24 25 8 26 21 27 23 22 20 9 10 7 11 3 2 1 4 5 6 12 Data Structures, CS, TAU, Splay Tree

  25. הערות: 2) פעולות יקרות - מוליכות לעץ טוב  זמן Ammortized יהיה טוב 1) פעולות זולות - עשויות להוליך לעץ לא טוב (כמו בנית העץ המקורי) Data Structures, CS, TAU, Splay Tree

More Related