Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structures, CS, TAU, Splay Tree

Similar presentations


Presentation on theme: "Data Structures, CS, TAU, Splay Tree"— Presentation transcript:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


Download ppt "Data Structures, CS, TAU, Splay Tree"

Similar presentations


Ads by Google