1 Data Structures, CS, TAU, Splay Tree Splay Tree  מימוש של עץ חיפוש בינארי  מטרה לדאוג ל- Amortized Time  פעולה בודדת יכולה לקחת O(N)  אבל כל רצף.

Slides:



Advertisements
Similar presentations
1 Colorful XML: One Hierarchy Isn't Enough Authors : H. V. Jagadish, Laks V. S. Lakshmanan, Monica Scannapieco, Divesh Srivastava, Nuwee Wiwatwattana Presented.
Advertisements

1 Data Structures, CS, TAU, RB-Tree1 עץ אדום-שחור  עץ חיפוש בינארי  בכל צומת ביט אינפורמציה נוסף - צבע  עץ “כמעט מאוזן”  (O(log n במקרה גרוע ביותר.
Splay Trees CSE 331 Section 2 James Daly. Reminder Homework 2 is out Due Thursday in class Project 2 is out Covers tree sets Due next Friday at midnight.
1 Formal Specifications for Complex Systems (236368) Tutorial #4 Refinement in Z: data refinement; operations refinement; their combinations.
1 Trees CLRS: chapter A hierarchical combinatorial structure הגדרה רקורסיבית: 1. צומת בודד. זהו גם שורש העץ. 2. אם n הוא צומת ו T 1 ….T K הינם עצים,
חיפוש בינה מלאכותית אבי רוזנפלד. סוגי חיפוש כלליים UNINFORMED SEARCH -- חיפושים לא מיודעים במרחי מצבים – BFS – DFS INFORMED SEARCH – חיפושים מיודעים –
EECS 311: Chapter 4 Notes Chris Riesbeck EECS Northwestern.
טבלאות סמלים נכתב ע"י אלכס קוגן סמסטר חורף, תשס"ח.
פונקציונל פונקציה מספר פונקציונל דוגמאות לא פונקציונל פונקציונל.
CPSC 320: Intermediate Algorithm Design & Analysis Splay Trees (for Amortized Analysis) Steve Wolfman 1.
פעולות מילון Insert, Delete, Search Binary Search Tree, AVL, 2-3 Tree, Skip List O(log n) האם יש מבנה עם סבוכיות (1)O? לא למפתח כלשהו.
1 Data Structures, CS, TAU, RB-Tree1 עץ אדום-שחור  עץ חיפוש בינארי  בכל צומת ביט אינפורמציה נוסף - צבע  עץ “כמעט מאוזן”  (O(log n במקרה גרוע ביותר.
עצים ועצי חיפוש חומר קריאה לשיעור זה Chapter 5.5– Trees (91 – 97)
תרגול 8 עצי B+ אינדקס משני.
חורף - תשס " ג DBMS, Design1 שימור תלויות אינטואיציה : כל תלות פונקציונלית שהתקיימה בסכמה המקורית מתקיימת גם בסכמה המפורקת. מטרה : כאשר מעדכנים.
עבודה סמינריונית Prelude to Ukkonen algorithm ON-LINE CONSTRUCTION OF SUFFIX TREES מגישים : עיד מוחמד טיבי פיראס.
CS 202, Spring 2003 Fundamental Structures of Computer Science II Bilkent University1 Splay trees CS 202 – Fundamental Structures of Computer Science II.
1 Trees CLRS: chapter A hierarchical combinatorial structure הגדרה רקורסיבית: 1. צומת בודד. זהו גם שורש העץ. 2. אם n הוא צומת ו T 1 ….T K הינם עצים,
2 Suffix Tree: Definition Suffix tree T על מחרוזת S שגודלה n, הוא עץ מכוון עם בדיוק n עלים ממוספרים מ -1 עד n. לכל צומת פנימית ( חוץ מהשורש ) יש לפחות.
1 Formal Specifications for Complex Systems (236368) Tutorial #5 Refinement in Z: data refinement; operations refinement; their combinations.
רקורסיות 18 יוני יוני יוני 1518 יוני יוני יוני 1518 יוני יוני יוני 151.
Data Structures, CS, TAU, Splay Tree 1 Splay Tree - עץ חיפוש בינארי - מטרה לדאוג ל - Amortized Time - פעולה בודדת יכולה לקחת O(N) - אבל כל רצף M פעולות.
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
Formal Specifications for Complex Systems (236368) Tutorial #6 appendix Statecharts vs. Raphsody 7 (theory vs. practice)
IN מעגל חשמלי אנלוגי לדנדריט הפוסט-סינפטי: מה קורה בתא הפוסט סינפטי עקב הפעלת סינפסה כימית ?
Multi-Cycle MIPS דוגמאות. דוגמה 1 נתון קטע הקוד הבא: begin:addi $v0, $zero, -1 loop:add $a0, $a0, $a0 addi$v0,$v0,1 bne $a0, $zero, loop הניחו כי בתחילת.
Union-Find A data structure for maintaining a collection of disjoint sets Course: Data Structures Lecturer: Hanoch Levy January 2010.
תרגול 7 עצי B
2-3 trees עצי 3-2 ועצי דרגות Chapter 19: B trees (381 – 397) Chapter 15: Augmenting data structures (281 – 290) חומר קריאה לשיעור זה Lecture5 of Geiger.
ערכים עצמיים בשיטות נומריות. משוואה אופינית X מציין וקטור עצמי מציינת ערך עצמי תואם לוקטור.
Sorting II: הפרד ומשול. Last week: in-place sorting Bubble Sort – O(n 2 ) comparisons –O(n) best case comparisons, O(n 2 ) exchanges Selection Sort -
שאלה 1 נתון כביש ישר עם תחנות דלק בנקודות , בנקודת המוצא נתונה מכונית עם תא דלק שמספיק ל-100 ק"מ. מחיר מילוי תא הדלק בתחנה.
1 ייצוג באמצעות עצים שונים מתוחכם רק לקבוצות גדולות (תקורה בפעולות ובתכנות!!!) עצי חיפוש בינאריים BINARY SEARCH TREES תחום סדור (> < =) תחום איברים גדול.
Data Structures, CS, TAU, Perfect Hashing 1 Perfect Hashing בעיה : נתונה קבוצה S של n מפתחות מתחום U השוואה ל - Hash : * טבלה קבועה (Hash רגיל - דינאמי.
גרפים - Graphs גרף G(V,E) מורכב מקבוצת צמתים V וקבוצת קשתות E.
1 Data Structures, CS, TAU, Perfect Hashing בעיה: נתונה קבוצה S של n מפתחות מתחום U השוואה ל- Hash : * טבלה קבועה (Hash רגיל - דינאמי) * רוצים זמן קבוע.
עצים מאוזנים הגדרה: משפחת עצים תקרא מאוזנת אם ,h(T) = O(log n) באשר T הוא עץ במשפחה, n הוא מספר הצמתים ב-T ו-h(T) הוא הגובה של T עצי (Adelson-Velsky,
Balanced Trees. Binary Search tree with a balance condition Why? For every node in the tree, the height of its left and right subtrees must differ by.
Data Structures, CS, TAU, RB-Tree 1 עץ אדום-שחור - עץ חיפוש בינארי - בכל צומת ביט אינפורמציה נוסף - צבע « עץ “ כמעט מאוזן ” « (O(log n במקרה גרוע ביותר.
1 Data Structures, CS, TAU, RB-Tree1 עץ אדום-שחור  עץ חיפוש בינארי  בכל צומת ביט אינפורמציה נוסף - צבע  עץ “כמעט מאוזן”  (O(log n במקרה גרוע ביותר.
Tirgul 13: Trees 1. הגדרות עץ – מודל מופשט של מבנה היררכי. עץ מורכב מאוסף של צמתים (קודקודים) עם יחס אבא-בן. שורש בעץ – צומת ללא אבא. בכל עץ יש בדיוק.
עצים בינאריים - תזכורת דרגת צומת שורש עלה צומת פנימי מרחק בין 2 צמתים
1 - גמישות בבינאריות גמישות בעומק - עץ חיפוש בינארי: ממוצע O(log n) גרוע ביותר (O(n - היינו רוצים לשמור את העץ מאוזן תמיד Data Structures, CS, TAU
CSC 2300 Data Structures & Algorithms February 16, 2007 Chapter 4. Trees.
1 Spring Semester 2007, Dept. of Computer Science, Technion Internet Networking recitation #3 Internet Control Message Protocol (ICMP)
מבנה מחשבים תרגול מספר 3. טענה על עצים משפט: בעץ שדרגת כל קודקודיו חסומה ב-3, מספר העלים ≤ מספר הקודקודים הפנימיים + 2. הוכחה: באינדוקציה על n, מספר הקודקודים.
Lecture 13 Maximal Accurate Forests From Distance Matrix.
(C) סיון טל גילוי מידע וזיהוי תבניות תרגול מס. 9 גילוי מידע וזיהוי תבניות תרגול מס. 9 דחיסת נתונים מהו קידוד תכונות של קידודים אי - שוויון קרפט.
תרגול 4 21/3/2007 מבני נתונים 07b ליאור שפירא. תזכורת – B-trees  לכל צומת x יש השדות הבאים n[x] מס ' מפתחות ב -x המפתחות עצמם בסדר לא יורד כל צומת פנימי.
Eddie Bortnikov/Aran Bergman, Principles of Reliable Distributed Systems, Technion EE, Spring Principles of Reliable Distributed Systems Recitation.
Splay Trees Splay trees are binary search trees (BSTs) that:
Splay Trees and B-Trees
CMSC 341 Splay Trees. 8/3/2007 UMBC CMSC 341 SplayTrees 2 Problems with BSTs Because the shape of a BST is determined by the order that data is inserted,
CSC 213 – Large Scale Programming. Implementing Map with a Tree  Accessing root much faster than going to leaves  In real-world, should place important.
Oct 26, 2001CSE 373, Autumn A Forest of Trees Binary search trees: simple. –good on average: O(log n) –bad in the worst case: O(n) AVL trees: more.
Tree Rotations & Splay Trees. BST Structure BST's only perform well when balanced But common cases lead to unbalanced trees.
1 Trees CLRS: chapter A hierarchical combinatorial structure הגדרה רקורסיבית: 1. צומת בודד. זהו גם שורש העץ. 2. אם n הוא צומת ו T 1 ….T K הינם עצים,
Jim Anderson Comp 750, Fall 2009 Splay Trees - 1 Splay Trees In balanced tree schemes, explicit rules are followed to ensure balance. In splay trees, there.
Data Structures Hanoch Levi and Uri Zwick March 2011 Lecture 3 Dynamic Sets / Dictionaries Binary Search Trees.
Present Simple (הווה פשוט) Ella Tubali Almogim School Qiriyat Yam 2011.
Splay Trees Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss Chapter 22 © 2002 Addison Wesley.
CS 5243: Algorithms Balanced Trees AVL : Adelson-Velskii and Landis(1962)
אלגוריתמי חיפוש. Brute Force Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To.
Tirgul 12 Trees 1.
Computer Architecture and Assembly Language
תירגול 14: מבני נתונים דינאמיים
Data Structures, CS, TAU, Splay Tree
Marina Kogan Sadetsky –
Computer Programming תרגול 3 Summer 2016
Engineering Programming A
Presentation transcript:

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

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

3 Data Structures, CS, TAU, Splay Tree k5k5 k4k4 A k3k3 k2k2 k1k1 CB D E F (מסלול גישה מסומן באדום) Rotate k5k5 k4k4 A k3k3 k2k2 k1k1 C B D E F

4 Data Structures, CS, TAU, Splay Tree k5k5 k4k4 A k3k3 k2k2 k1k1 C B D E F Rotate

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

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

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

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

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

10 Data Structures, CS, TAU, Splay Tree דוגמא: k5k5 k4k4 A k3k3 k2k2 k1k1 C B D E F (מסלול גישה מסומן באדום) Rotate חזרה לדוגמה

11 Data Structures, CS, TAU, Splay Tree k5k5 k4k4 A k3k3 k2k2 k1k1 C B D E F k 1, Zig-Zag gives: k5k5 k4k4 A k3k3 k2k2 k1k1 C B D E F k 1, Zig-Zig gives: חזרה לדוגמא

12 Data Structures, CS, TAU, Splay Tree Splaying at Node 1

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

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

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

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

17 Data Structures, CS, TAU, Splay Tree אותה דוגמא מוגדלת Result of splaying at node 1 a tree of all left children גובה עץ קטן פי 2!

18 Data Structures, CS, TAU, Splay Tree Result of splaying previous tree at node 2 גובה עץ קטן פי 2!

19 Data Structures, CS, TAU, Splay Tree Result of splaying previous tree at node 3 גובה עץ קטן פי 2!

20 Data Structures, CS, TAU, Splay Tree Result of splaying previous tree at node 4

21 Data Structures, CS, TAU, Splay Tree Result of splaying previous tree at node 5

22 Data Structures, CS, TAU, Splay Tree Result of splaying previous tree at node 6

23 Data Structures, CS, TAU, Splay Tree Result of splaying previous tree at node 7

24 Data Structures, CS, TAU, Splay Tree Result of splaying previous tree at node 8

25 Data Structures, CS, TAU, Splay Tree Result of splaying previous tree at node 9

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