Marina Kogan Sadetsky –

Slides:



Advertisements
מצגות קשורות
שם המנחה: ד"ר ליבנת אפריאט-ג'ורנו
Advertisements

SQL: שינוי מסד הנתונים- פעולותDDL , DML
הרצאה 02 סוגי משתנים קרן כליף.
קורס ניהול ידע מפגש 3 - פורטלים 2know.kmrom.com.
תגובות חמצון -חיזור ודוגמאות מחיי היום יום
הרצאה 12: מיזוג, מיון ושימושים לפעולות על קבוצות - המשך
Trends in Periodic Table Properties
על הסתיו ועוד, בגן ה"תמרים" בעכו שם הגננות: מירב קדוש אלה נאמן
Ford Fulkerson.
תרגול 11: רקורסיה ופיתוח טלסקופי
לולאות Department of Computer Science-BGU 19 יולי 19.
טקס פתיחת "גינת השותפות" בעכו
נערך ע"י אריק הוד, הגימנסיה העברית הרצליה
ייצוג קבוצות מתוחכם עצי חיפוש בינאריים BINARY SEARCH TREES
Isotopes and Atomic Mass
OOO Execution of Memory Operations
יצוג קבוצות מתוחכם עצי חיפוש בינאריים BINARY SEARCH TREES
אלקטרושליליות ופולריות הקשר
משואה כימית של שריפת פחם (תגובה עם חמצן)
Jump tables, review questions
מודל דחיית זוגות אלקטרונים של קליפת הערכיות
תכנות בשפת C תרגול 11 רשימות מקושרות מבנים
Computer Programming תרגול 1 Summer 2016
The local ceremony for kindergarten children in Akko was on Akko’s hill and was dedicated to the environment. The children climbed the hill while singing.
Present Perfect Simple
תירגול 11: מיונים וחיפוש בינארי
תרכובות עם יונים פוליאטומים בחיי היום יום
A sneak peak of the Passover story at Levine Academy
יסודות מבני נתונים תרגול 13: עץ פורש מינימלי - Minimum Spanning Tree (MST)
Passover in “Parpar” kindergarten Akko The teacher: Limore Simchi
חוק שימור החומר The Law of Conservation of Mass indicates that in an
The Dolphin Class International Forest of Support
מבני נתונים תרגול 3 ליאור שפירא.
OOO Execution of Memory Operations
Mantled Howler Monkey - Alouatta palliata
Engineering Programming A
Akiba Academy of Dallas Presents
© המרכז להוראת המדעים האוניברסיטה העברית בירושלים
Short Documentation from “Yom Hatzmaut” activities in ECP – Austin TX תיעוד קצר מהפעילויות בגיל הרך בבית הספר היהודי באוסטין טקסס לקראת יום העצמאות.
האם אתם יודעים כיצד כותבים מגילה?
מוטיבציה והשוואה בין מבני נתונים שלמדנו
© המרכז להוראת המדעים האוניברסיטה העברית בירושלים
Direction of induced current
שם הגננת: עדנה סרי The teacher: Edna Seri
הרצאה 10: אלגוריתמי מיון רקורסיביים Merge sort ו-Quick sort
Class VI: Adjectives Dr. Esa Autero
Computer Architecture and System Programming Laboratory
בתרכובות יוניות יש קשרים יונים
תיעוד מפעילויות ראש השנה בגן "פרפר נחמד" –עכו-תש"ע
אלגוריתמי מיון רקורסיביים
תרגול 13 : חזרה נכתב על-ידי לימור ליבוביץ נערך ע"י ישראל גוטר
Elements and Symbols יסודות וסמלים מהם יסודות? gold carbon aluminum
Marina Kogan Sadetsky –
Emech at 1 + W = Emech at 2 mgh1 = mgh2
© המרכז להוראת המדעים האוניברסיטה העברית בירושלים
What is Chemistry? מהי כימיה? Chemistry is the study of matter and its
מבוא לתכנות ב- JAVA מעבדה 4
SQL: מושגים עמודה, תכונה, שדה, אטריביוט טבלה, רלציה סכמה
הכנת שמן זית וארכיאולוגיה בגן "ארגמן" עכו Preparing olive oil and Archeology at “Argaman” kindergarten in Akko שם הגננת: נטלי גוריבודסקי שם הסייעת :
מצביעים Pointers – המשך...
גן "יסמין "עכו שם הגננת: מרגלית פוגל שם הסייעת: זיוה אוזן
Data Structures, CS, TAU, Perfect Hashing
OOO Execution of Memory Operations
ניהול שינויים במחסן נתונים יש עומק היסטורי הארגון משתנה במשך הזמן
עקרונות תכנות מונחה עצמים תרגול 9:C++ - תרגילים
דוגמא להשערה חד-צדדית ימנית
Java Programming רשימות מקושרות - המשך
Engineering Programming A
בגן" הדס" בעכו משלבת פרלה שטרית הגננת ,בין חנוכה לבין השמירה על איכות הסביבה. פרלה בקשה מהילדים להכין בביתם חנוכייה מחומרים ממוחזרים או מחומרים שאינם.
תמליל מצגת:

Marina Kogan Sadetsky – 05.2015 יסודות מבני נתונים תרגול 7: עץ AVL(Adelson-Velsky and Landis') Marina Kogan Sadetsky – 05.2015

עץ AVL x √ x עץ AVL – עץ חיפוש בינארי שבו לכל צומת v מתקיים: ההפרש בין גובה תת העץ השמאלי של v לבין גובה תת העץ הימני של v הוא לכל היותר 1. |h(left[v]) – h(right[v])| ≤ 1 6 1 8 4 2 3 5 5 1 8 6 1 3 5 4 x √ x

Question 1 Suggest a data structure for storing integers that supports the following operations. Init() Initialize empty data structure O(1) Insert(x) Insert x, if it is not present yet O(log n) Delete(x) Delete x if it exists GetPlace(x) Return x’s place (according to the order of insertion). If x does not exist, return -1 DeletePlace(i) Delete the element in the ith place (according to the order of insertion) Insert(3), Insert(5), Insert(11), Insert(7), Insert(2) דוגמא: נשתמש בעץ AVL 2 5 11 3 7 GetPlace(7) מידע נוסף בעץ AVL של אינדקס הכנסה  returns 4 מיון לפי שני מפתחות צריך 2 עצי AVL הצבעה הדדית DeletePlace(2)  deletes 5

Question 1 We will use two AVL trees: Solution: We will use two AVL trees: T1 stores the elements by their key T2 stores the elements by the order of insertion (using a running counter) two trees connect the nodes with the same key (by pointers) Insert(3), Insert(5), Insert(11), Insert(7), Insert(2) דוגמא: T1: 3 3 3 5 11 5 11 3 5 11 3 7 2 5 11 3 7 5 2 3 1 4 5 2 4 1 5 3 T2: 1 2 3 2 3 1 2 3 1 4 1 1 2

Question 1

Question 3 … דוגמא: 7 9 5 8 11 12 4 פתרון: נסרוק את העץ, רמה אחרי רמה: (סריקה כזו נקראת BFS - Breadth First Search) queue queue queue queue queue queue dequeue (5) enqueue ( 6’s children) dequeue (4) enqueue ( 4’s children) ... 7 9 5 11 8 4 12 insert root dequeue (7) enqueue ( 7’s children) dequeue (12) enqueue ( 12’s children) dequeue (9) enqueue ( 9’s children) dequeue (11) enqueue ( 11’s children) {7} {7,5,9} {7,5,9,4,8,11} {7,5,9,4,8,11,12} נבנה את העץ מהרשימה שקיבלנו. נשים לב שהעץ גדל רמה רמה, ולכן אף פעם לא נצטרך לעדכן גובה. 7 7 7 … 7 7 5 5 9 5 9 5 9 4 8 11 4 8 11 12

Question 4 Suggest a data structure for storing clients by their id, and marked as ‘woman‘ or ‘man’, that supports the following operations. Insert(k) Insert a new client with id=k, and first mark them ‘woman’ O(log n) Update(k) Update client with id=k to be ‘man’ FindDiff(k) Find the difference between number of ‘woman’ and ‘man’ clients whose id < k Solution: נשתמש בעץ AVL 9 1 8 5 7 6 2 ‘man’ = 3 ‘woman’ = 4 FindDiff(5) =1-1=0 דוגמא: איך נענה לדרישה הזו ? 2 1 2 כל צומת צריך לדעת מראש כמה ‘man’ ו ‘woman’ יש בתת העץ שלו (כולל צומת עצמו). 1 1 1 ‘man’

Question 4 Suggest a data structure for storing clients by their id, and marked as ‘woman‘ or ‘man’, that supports the following operations. Insert(k) Insert a new client with id=k, and first mark them ‘woman’ O(log n) Update(k) Update client with id=k to be ‘man’ FindDiff(k) Find the difference between number of ‘woman’ and ‘man’ clients whose id < k Solution: נשתמש בעץ AVL 9 1 8 5 7 6 2 ‘man’ = 3 ‘woman’ = 4 FindDiff(5) =1-1=0 דוגמא: איך נענה לדרישה הזו ? 2 1 2 כל צומת צריך לדעת מראש כמה ‘man’ ו ‘woman’ יש בתת העץ שלו (כולל צומת עצמו). 1 1 1 ‘man’

Question 4

Question 4

Question 4

Question 4

Question 5 דוגמא: MinMax() = min{max(S1),max(S2), max(S3)} = min{7,5,8} = 5 GlobalMax() = max{max(S1),max(S2), max(S3)} = max{7,5,8} = 8

Question 5 מותר להחזיק מספר קבוע של עותקים של אותו איבר. S2 S3 S1 Tsets m קבוצות, n מפתחות בקבוצה Insert(i,k) בזמן O(log n + log m) נחזיק אינדקסים של קבוצות בעץAVL Tsets כל צומת ב Tsets יצביע על הקבוצה שלו נחזיק כל קבוצה בעץ AVL נפרד TSi 4 7 2 TS1 1 6 8 3 TS2 5 TS3

Question 5 √ Tsets TS1 TS2 TS3 m קבוצות, n מפתחות בקבוצה Delete(i,k) בזמן O(log n + log m) √ S2 S3 S1 Tsets TS1 TS2 TS3 4 6 5 2 7 3 8 1

Question 5 Tsets TS1 TS2 TS3 MinMax() בזמן O(1) נחזיק משתנה עזר MMax עבור הערך העדכני של MinMax() Tsets MMax = 5 S2 כמה זמן יקח לנו לעדכן את הערך MMax ? S1 S3 O(m*log n + m) כי נצטרך לחשב את MinMax() מחדש. TS1 TS2 TS3 4 6 5 2 7 3 8 6 1

Question 5 √ Tmax MinMax() בזמן O(1) MMax = 5 MinMax() בזמן O(1) נחזיק משתנה עזר MMax עבור הערך העדכני של MinMax() כמה זמן יקח לנו לעדכן את הערך MMax ? O(m*log n + m) כי נצטרך לחשב את MinMax() מחדש. נחזיק עץ AVL נוסף Tmax המכיל מקסימום של כל עץ TSi. ברגע שמכניסים איבר חדש x לעץ TSi, בודקים האם x גדול מהמקסימום (O(log n)), ואם כן, אז מוציאים מ Tmax את המקסימום הישן של TSi ומכניסים את x במקומו ל Tmax (O(log m)). מחפשים את המינימום החדש של Tmax (O(log m)) ומעדכנים את MMax במידת הצורך. 7 8 5 Tmax √ תוספת של O(log n + log m) זמן להכנסה

Question 5 √ Tmax GlobalMax() בזמן O(1) MMax = 5 GMax = 8 GlobalMax() בזמן O(1) נחזיק משתנה עזר GMax עבור הערך העדכני של GlobalMax() כמה זמן יקח לנו לעדכן את הערך GMax ? ברגע שמכניסים איבר חדש x לעץ TSi, בודקים האם x גדול מהמקסימום (O(log n)), ואם כן, אז מוציאים מ TSi את המקסימום הישן ומכניסים את המקסימום העדכני של TSi(O(log m)). מחפשים את המקסימום החדש של Tmax (O(log m)) ומעדכנים את GMax במידת הצורך. ברגע שמכניסים איבר חדש x לעץ TSi, בודקים האם x גדול מהמקסימום (O(log n)), ואם כן, אז מוציאים מ Tmax את המקסימום הישן של TSi ומכניסים את x במקומו ל Tmax (O(log m)). מחפשים את המקסימום החדש של Tmax (O(log m)) ומעדכנים את GMax במידת הצורך. Tmax 7 √ תוספת של O(log n + log m) זמן להכנסה 5 8

Question 5

Question 5

Question 5

Question 2 Suggest efficient way to implement Join (T1, x, T2). T1 and T2 are AVL trees, and x is an element so that T1< x < T2 . T1 T2 x דוגמא: ? איך לחבר בין שני עצים כך שהתיקון גובה יקח זמן מינימלי ? צריך לעשות תיקון גובה נמצא תת עץ השמאלי ביותר ב 2T עם גובה של 1T נחליף את השורש שלו ב x נחבר אליו את 1T משמאל ואת תת העץ 2T מימין נשים לב שהגובה של העץ הסופי שנוצר הינו 1+ הגובה של העץ T2, לכן אנחנו יכולים להפעיל אלגוריתם תיקון גובה (כמו בהכנסה).

Question 2

Question 2