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

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 הינם עצים,
A. Frank File Organization Indexed-Sequential File Introduction Thanks to Tamar Barnes.
2 Suffix Tree: Definition Suffix tree T על מחרוזת S שגודלה n, הוא עץ מכוון עם בדיוק n עלים ממוספרים מ -1 עד n. לכל צומת פנימית ( חוץ מהשורש ) יש לפחות.
1 Data Structures, CS, TAU, Splay Tree Splay Tree  מימוש של עץ חיפוש בינארי  מטרה לדאוג ל- Amortized Time  פעולה בודדת יכולה לקחת O(N)  אבל כל רצף.
1 Formal Specifications for Complex Systems (236368) Tutorial #5 Refinement in Z: data refinement; operations refinement; their combinations.
רקורסיות 18 יוני יוני יוני 1518 יוני יוני יוני 1518 יוני יוני יוני 151.
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
Formal Specifications for Complex Systems (236368) Tutorial #6 appendix Statecharts vs. Raphsody 7 (theory vs. practice)
Synchronizers - מסנכרנים הדמיית רשת סינכרונית ברשת אסינכרונית.
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
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
ערכים עצמיים בשיטות נומריות. משוואה אופינית X מציין וקטור עצמי מציינת ערך עצמי תואם לוקטור.
שאלה 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 במקרה גרוע ביותר.
עצים בינאריים - תזכורת דרגת צומת שורש עלה צומת פנימי מרחק בין 2 צמתים
1 - גמישות בבינאריות גמישות בעומק - עץ חיפוש בינארי: ממוצע O(log n) גרוע ביותר (O(n - היינו רוצים לשמור את העץ מאוזן תמיד Data Structures, CS, TAU
CSC 2300 Data Structures & Algorithms February 16, 2007 Chapter 4. Trees.
Lecture 13 Maximal Accurate Forests From Distance Matrix.
(C) סיון טל גילוי מידע וזיהוי תבניות תרגול מס. 9 גילוי מידע וזיהוי תבניות תרגול מס. 9 דחיסת נתונים מהו קידוד תכונות של קידודים אי - שוויון קרפט.
תרגול 4 21/3/2007 מבני נתונים 07b ליאור שפירא. תזכורת – B-trees  לכל צומת x יש השדות הבאים n[x] מס ' מפתחות ב -x המפתחות עצמם בסדר לא יורד כל צומת פנימי.
2-4 tree k=2 Each node has 2,3,or 4 children. Delete delete(14,T)
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.
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)
Review for Exam 2 Topics covered: –Recursion and recursive functions –General rooted trees –Binary Search Trees (BST) –Splay Tree –RB Tree –K-D Trees For.
אלגוריתמי חיפוש. 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 –
חזרה חלקית על תרגול 12 גרף G=(V,E)
Computer Programming תרגול 3 Summer 2016
Engineering Programming A
Presentation transcript:

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

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

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

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

5 בעיה : k 3 שקוע ( כמעט ) לעומקו המקורי של k 1 בעיה : ישנם מקרים שלוקחים  בעיות בעץ דוגמה לבעיה זו בעמ ’ הבא. לא בטוח ש צריך את הדוגמא בכלל !!!!

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

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

8  N פעולות לוקחות שפוץ : ביצוע Rotate משופר, ביצוע Rotate משופר, המבוצע על שלישיית צמתים. ( שתי אפשרויות : ) Zig-zagZig-zig

Data Structures, CS, TAU, Splay Tree 9 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

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

Data Structures, CS, TAU, Splay Tree 11 Splaying at node

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 אותה דוגמא מוגדלת

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

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

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

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

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

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

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

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

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