Design Patterns for Data Structures. Chapter 10. Balanced Trees
|
|
- Claribel Welch
- 6 years ago
- Views:
Transcription
1 Capter 10 Balanced Trees
2 Capter 10 Four eigt-balanced trees: Red-Black binary tree Faster tan AVL for insertion and removal Adelsen-Velskii Landis (AVL) binary tree Faster tan red-black for lookup B-tree n-way balanced tree Nguyen-Wong B-trees Composite pattern n-way balanced tree
3 Demo Insert:
4 Capter 10 Properties of a red-black tree Ared-black tree is a binary searc tree. Every link is eiter red or black. Every cild tat is an empty tree is a leaf wit a black link to its parent. No pat from te root to any leaf as two red links in a row. All pats from eac node to all its leaves ave te same number of black links.
5 Capter 10 Properties of a left-leaning red-black tree A left-leaning red-black tree is a red-black tree. Every red link is to a left cild. Sedgewick, as sown tat tis restriction greatly simplifies te code for bot insertion and deletion.
6 Capter 10 Te number of black links from te root to any leaf is called te black eigt of te tree, denoted b ( ) = b (60) = 3
7 Performance of
8 Lemma 1: No pat from te root to a leaf is more tan twice as long as any oter. In a red-black tree of eigt rooted at x, b(x) /2. x b x =
9 Define n x, as te number of internal nodes in a red-black tree of eigt rooted at node x. Example: n 60, 6 = 16 Example: n20, 4 = =
10 Lemma 2: n x, 2 b(x) 1. Proof : Te proof is by matematical induction on te eigt of te tree. Base case: n x, 2 b(x) 1 = Take as te base case tat te root is n, 2 b() 1 = Wit a root of, tere are no internal nodes 0 2 b() 1 = Wit a root of, te black eigt is = Mat true
11 Induction case: Must prove tatn x, 2 b(x) 1 for a eigt tree using n w, 1 2 b(w) 1 for a eigt 1 tree as te inductive ypotesis. x c Link from x to cild c is red => b(c) = b(x). Link from x to cild c is black => b(c) = b(x) 1. Minimum number of nodes in tree rooted at x => bot cildren ave minimum => links from x to bot are black
12 Induction case: Must prove tatn x, 2 b(x) 1 for a eigt tree using n w, 1 2 b(w) 1 for a eigt 1 tree as te inductive ypotesis. x c n x, = 1 + n l, 1 + n r, b(l) b(r) 1 l r b(x) b(x) 1 1 = 2 2 b(x) 1 1 = 2 b(x) 1
13 n x, 2 /2 1 n x, 2 b(x) 1 2 /2 1
14 Teorem, red-black tree eigt bound: Ared-black tree witn internal nodes as eigt 2lg(n + 1). Proof : Starting wit Lemma 3, n 2 /2 1 = Mat 2 /2 n + 1 = Take lg of bot sides, monotonicity of lg() /2 lg(n + 1) = Mat 2lg(n + 1) For comparison, eigt-balanced AVL trees ave 1.44lg(n+2) Tey are more balanced tan red-black trees and ave faster retrieval (1.44 coefficient compared to 2 for red-black trees) but ave slower insertion and removal.
15 Implementation of
16 template<class T> class { private: Node<T> *_root; public: (); //Constructor // Post: Tis left-leaning red-black tree // is initialized to be empty. ~(); //Destructor // Post: Tis left-leaning red-black tree // is deallocated.
17 bool contains(t const &data); // Post: Returns true if tis tree contains data. void insert(t const &data); // Post: data is stored in tis tree in order // wit no duplicates. bool isempty(); // Post: Returns true if tis tree is empty.
18 void remove(t const &data); // Pre: Tis tree contains data. // Post: data is removed from tis tree. void removemin(); // Pre: Tis tree is not empty. // Post: Te minimum value is removed. }; void tostream(ostream &os) const; // Post: A string representation of tis tree // is streamed to os.
19 template<class T> class Node { friend class <T>; private: Node *_left; T _data; Node *_rigt; bool _color; // Color of link from parent.
20 public: Node(T data); // Post: Tis node is allocated wit _data set to data, // _color set to RED, and _left, _rigt set to nullptr. ~Node(); // Post: Tis node, its left subtree, and its rigt subtree // are deallocated.
21 private: Node<T> *fixup(node<t> *); void flipcolors(node<t> *); Node<T> *insert(node<t> *, T const &data); bool isred(node<t> *); T min(node<t> *); Node<T> *moveredleft(node<t> *); Node<T> *moveredrigt(node<t> *); Node<T> *remove(node<t> *, T const &data); Node<T> *removemin(node<t> *); Node<T> *rotateleft(node<t> *); Node<T> *rotaterigt(node<t> *); void tostream(node<t> *, string prrigt, string prroot, string prleft, ostream &os) const; };
22 const bool RED = true; const bool BLACK = false; template<class T> class Node { private: Node *_left; T _data; Node *_rigt; bool _color; // Color of link from parent. _color _data _left _rigt // ========= isred ========= // Post: Returns false if == nullptr. // Oterwise returns true if node is RED. template<class T> bool Node<T>::isRed(Node<T> *) { return == nullptr? BLACK : ->_color; }
23 // ========= Constructors ========= template<class T> <T>::() { _root = nullptr; // Te empty tree. } template<class T> Node<T>::Node(T data) : _color(red), _data(data), _left(nullptr), _rigt(nullptr) { } 50
24 Te rotate left operation 50 p < 50 > 60 > 50 < 60 (a) Before rotate left. > 60 < 50 > 50 < 60 (b) After rotate left. Te black eigt and te order are maintained.
25 // ========= rotateleft ========= // Pre: ->_rigt is RED. // Post: is rotated left. // Post: A pointer p to te root node of te modified tree is returned. // Post: p->left is RED. template<class T> Node<T> *Node<T>::rotateLeft(Node<T> *) { Node<T> *p = ->_rigt; ->_rigt = p->_left; p->_left = ; p->_color = ->_color; ->_color = RED; return p; }
26 p p 60 < 50 < 50 > 50 < 50 < 60 > 60 > 50 < 60 > 60 > 50 < 60 > 60 (a) Initial tree. (b) p = ->_rigt (c) ->_rigt = p->_left p 60 p 60 p > 60 > 60 > 60 < 50 > 50 < 60 (d) p->_left = < 50 > 50 < 60 (e) p->_color = ->_color < 50 > 50 < 60 (f) ->_color = RED
27 Te rotate rigt operation 60 p > 60 < 50 < 50 > 50 < 60 (a) Before rotate rigt. > 50 < 60 (b) After rotate rigt. > 60 Te black eigt and te order are maintained.
28 // ========= rotaterigt ========= // Pre: ->_left is RED. // Post: is rotated rigt. // Post: A pointer p to te root node of te modified tree is returned. // Post: p->rigt is RED. template<class T> Node<T> *Node<T>::rotateRigt(Node<T> *) { cerr << rotaterigt(): Exercise for te student. << endl; trow -1; }
29 Te flip colors operation (a) Before flip colors. (b) After flip colors. Te black eigt is maintained if is black and ->_left and ->_rigt are bot red.
30 // ========= flipcolors ========= // Pre: as nonempty _left and _rigt. // Post: Te colors of and its cildren are flipped. template<class T> void Node<T>::flipColors(Node<T> *) { ->_color =!->_color; cerr << flipcolors(): Exercise for te student. << endl; trow -1; }
31 Inserting into
32 // ========= insert ========= // Post: data is stored in tis tree in order wit no duplicates. template<class T> void <T>::insert(T const &data) { _root = _root->insert(_root, data); _root->_color = BLACK; } // Post: val is stored in root node in order as a leaf. // Post: A pointer to te root node of te modified tree is returned. template<class T> Node<T> *Node<T>::insert(Node<T> *, T const &data) { if ( == nullptr) { return new Node<T>(data); } if (data < ->_data) { ->_left = insert(->_left, data); } else if (data > ->_data) { ->_rigt = insert(->_rigt, data); } // else no duplicates. return fixup(); }
33 Capter 10 Before calling fixup(), wic properties migt be violated? Ared-black tree is a binary searc tree. Every link is eiter red or black. Every cild tat is an empty tree is a leaf wit a black link to its parent. No pat from te root to any leaf as two red links in a row. All pats from eac node to all its leaves ave te same number of black links. A left-leaning red-black tree is a red-black tree. Every red link is to a left cild.
34 Capter 10 Before calling fixup(), wic properties migt be violated? Ared-black tree is a binary searc tree. Every link is eiter red or black. Every cild tat is an empty tree is a leaf wit a black link to its parent. No pat from te root to any leaf as two red links in a row. All pats from eac node to all its leaves ave te same number of black links. A left-leaning red-black tree is a red-black tree. Every red link is to a left cild.
35 Capter 10 Te purpose of fixup() is to correct two possible problems. Te additional red link migt be to a rigt cild. Te additional red link migt produce two red links in a row.
36 Capter 10 fixup() makes tree adjustments. If te red link is a rigt link, make it a left link. If tere are two red left links in a row, rotate rigt in preparation for te last adjustment. If te left and rigt links are bot red, flip colors.
37 // ========= fixup ========= // Pre: ->_left and ->_rigt are roots of left-leaning red-black trees. // Post: is a root of a left-leaning red-black tree. // Post: A pointer to te root node of te modified tree is returned. template<class T> Node<T> *Node<T>::fixup(Node<T> *) { if (isred(->_rigt)) { = rotateleft(); } if (isred(->_left) && isred(->_left->_left)) { = rotaterigt(); } if (isred(->_left) && isred(->_rigt)) { flipcolors(); } return ; }
38 Inserting as a rigt leaf wit a black sibling (a) Initial tree. (b) Insert 60. (c) Rotate left.
39 Inserting as a left leaf wit a red parent (a) Initial tree. (b) Insert 60. (c) No fixup (d) Rotate rigt. (e) Flip colors.
40 Inserting as a rigt leaf wit a red sibling (a) Initial tree. (b) Insert 60. (c) Rotate left (d) Rotate rigt. (e) Flip colors.
41 Inserting 50 into
42 (a) Initial tree. (b) ->rigt = insert(->rigt, data) (c) = rotateleft() (d) = rotaterigt()
43 (e) flipcolors() (f) = rotateleft()
44 Deleting from
45 Capter 10 Te remove operation Find te node to remove. Find te minimum of te rigt cild of te node to remove, wic is te successor node. Copy te data from te successor to te node to remove wit te min() operation. Remove te minimum of te rigt cild.
46 Capter 10 Te remove operation Find te node to remove. Find te minimum of te rigt cild of te node to remove, wic is te successor node. Copy te data from te successor to te node to remove wit te min() operation. Remove te minimum of te rigt cild.
47 Capter 10 Useful fact Te minimum of a as a left cild. Terefore, it must ave a rigt cild. - Te rigt cild cannot be red because te tree is left-leaning. - If te rigt cild were not, te successor would not ave a unique black eigt. Conclusion: We do not need a remroot operation! We can simply delete te successor.
48 Capter 10 Delete minimum strategy If te node to be deleted as a red link to it, te node can be deleted witout affecting te black eigt requirement. Problem: Te node to be deleted migt ave a black link to it. Solution: Pus red links down on te way to te minimum, wic creates rigt-leaning reds. Fix te rigt-leaning reds on te way up.
49 Capter 10 Te moveredleft operation Te purpose of te moveredleft operation is to pus te red links down on te way to te minimum to guarantee tat te minimum will be connected to its parent wit a red link. It is only called on te way down if tere are two left black links in a row.
50 Guaranteed to ave red link from parent.
51 Called on te way down if two left black links in a row
52 Recursively move down te left to find te minimum.
53 Same fixup as wit insert!
54 // ========= moveredleft ========= // Pre: as nonempty _left and _rigt. // Invariant: Eiter or ->_left is RED. // Post: A pointer to te root node of te modified tree is returned. template<class T> Node<T> *Node<T>::moveRedLeft(Node<T> *) { flipcolors(); Move red left migt only flip te colors. if (isred(->_rigt->_left)) { ->_rigt = rotaterigt(->_rigt); = rotateleft(); flipcolors(); } return ; }
55 // ========= moveredleft ========= // Pre: as nonempty _left and _rigt. // Invariant: Eiter or ->_left is RED. // Post: A pointer to te root node of te modified tree is returned. template<class T> Node<T> *Node<T>::moveRedLeft(Node<T> *) { } flipcolors(); if (isred(->_rigt->_left)) { ->_rigt = rotaterigt(->_rigt); = rotateleft(); flipcolors(); } return ; Tis condition could not be repaired by fixup on te way back up.
56 Deleting minimum. Move red left only flips colors l r l r (a) Initial tree (b) moveredleft() only flips colors
57 Deleting minimum. Move red left only flips colors l r l r (c) moveredleft() only flips colors (d) moveredleft() only flips colors.
58 Deleting minimum. Move red left only flips colors l r l r (e) Delete minimum wit red parent link. (f) Fixup wit rotateleft().
59 Deleting minimum. Move red left only flips colors r l l r (g) Fixup wit rotateleft(). 20 () Fixup wit rotateleft().
60 Deleting minimum. Move red left does more tan flipping colors l r l r (a) Initial tree. (b) moveredleft() only flips colors.
61 Deleting minimum. Move red left does more tan flipping colors l r l r (c) First, moveredleft() flips colors. (d) ->_rigt = rotaterigt(->_rigt).
62 Deleting minimum. Move red left does more tan flipping colors l r l r (e) = rotateleft(). (f) = flipcolors().
63 Deleting minimum. Move red left does more tan flipping colors l r l r (g) moveredleft() is not called () moveredleft() only flips colors.
64 Deleting minimum. Move red left does more tan flipping colors l r l r (i) Delete minimum wit red parent link. (j) After four fixups.
65 Capter 10 Te remove operation Find te node to remove. Find te minimum of te rigt cild of te node to remove, wic is te successor node. Copy te data from te successor to te node to remove wit te min() operation. Remove te minimum of te rigt cild.
66 Used to copy te data from te successor node. // ========= min ========= // Pre:!= nullptr. // Post: Te minimum of tree rooted at is returned. template<class T> T Node<T>::min(Node<T> *) { Node<T> *p = ->_left; cerr << min(): Exercise for te student. << endl; trow -1; }
67 Capter 10 Te remove operation Find te node to remove. Find te minimum of te rigt cild of te node to remove, wic is te successor node. Copy te data from te successor to te node to remove wit te min() operation. Remove te minimum of te rigt cild.
68 Capter 10 Find te node to remove Same strategy: need to pus te red links down. Finding te node to remove may require moving to te rigt as well as to te left. If you move to te left on te way to te node to remove, call moveredleft() as before. If you move to te rigt, call moveredrigt().
69 // ========= moveredrigt ========= // Pre: as nonempty _left and _rigt. // Invariant: Eiter or ->_rigt is RED. // Post: A pointer to te root node of te modified tree is returned. template<class T> Node<T> *Node<T>::moveRedRigt(Node<T> *) { flipcolors(); Move red rigt migt only flip te colors. if (isred(->_left->_left)) { = rotaterigt(); flipcolors(); } return ; }
70 // ========= moveredrigt ========= // Pre: as nonempty _left and _rigt. // Invariant: Eiter or ->_rigt is RED. // Post: A pointer to te root node of te modified tree is returned. template<class T> Node<T> *Node<T>::moveRedRigt(Node<T> *) { } flipcolors(); if (isred(->_left->_left)) { = rotaterigt(); flipcolors(); } return ; Tis condition could not be repaired by fixup on te way back up.
71 Te remove operation // ========= remove ========= // Pre: Tis tree contains data. // Post: data is removed from tis tree. template<class T> void <T>::remove(T const &data) { _root = _root->remove(_root, data); if (_root!= nullptr) { _root->_color = BLACK; } }
72 Move down to te left.
73 Found, or move down to te rigt.
74 Adjust left red link to rigt.
75 Found and can return immediately.
76 Possible adjustment wit moveredrigt.
77 Found te node to remove.
78 Copy data from successor node.
79 Delete successor node.
80 Move down to te rigt.
81
82 Insert fixup, general red-black tree RB-INSERT-FIXUP.T; / Capter 11 wile :p:color == RED if :p == :p:p:left y D :p:p:rigt if y:color == RED :p:color D BLACK y:color D BLACK Case 1 :p:p:color D RED D :p:p else if == :p:rigt D :p LEFT-ROTATE.T; / Case 2 :p:color D BLACK :p:p:color D RED Case 3 RIGHT-ROTATE.T; :p:p/ else (same as ten clause wit rigt and left excanged) T:root:color D BLACK
83 Remove fixup, general red-black tree RB-DELETE-FIXUP.T; x/ wile x T:root and x:color == BLACK if x == x:p:left w D x:p:rigt if w:color == RED w:color D BLACK Cap x:p:color D RED LEFT-ROTATE.T; x:p/ w D x:p:rigt if w:left:color == BLACK and w:rigt:color == BLACK w:color D RED x D x:p else if w:rigt:color == BLACK w:left:color D BLACK w:color D RED RIGHT-ROTATE.T; w/ w D x:p:rigt w:color D x:p:color x:p:color D BLACK w:rigt:color D BLACK LEFT-ROTATE.T; x:p/ x D T:root Case 1 Case 2 Case 3 Case 4 else (same as ten clause wit rigt and left excanged) x:color D BLACK
Design Patterns for Data Structures. Chapter 10. Balanced Trees
Capter 10 Balanced Trees Capter 10 Four eigt-balanced trees: Red-Black binary tree Faster tan AVL for insertion and removal Adelsen-Velskii Landis (AVL) binary tree Faster tan red-black for lookup B-tree
More informationCE 221 Data Structures and Algorithms
CE Data Structures and Algoritms Capter 4: Trees (AVL Trees) Text: Read Weiss, 4.4 Izmir University of Economics AVL Trees An AVL (Adelson-Velskii and Landis) tree is a binary searc tree wit a balance
More informationCS 234. Module 6. October 16, CS 234 Module 6 ADT Dictionary 1 / 33
CS 234 Module 6 October 16, 2018 CS 234 Module 6 ADT Dictionary 1 / 33 Idea for an ADT Te ADT Dictionary stores pairs (key, element), were keys are distinct and elements can be any data. Notes: Tis is
More informationCS 234. Module 6. October 25, CS 234 Module 6 ADT Dictionary 1 / 22
CS 234 Module 6 October 25, 2016 CS 234 Module 6 ADT Dictionary 1 / 22 Case study Problem: Find a way to store student records for a course, wit unique IDs for eac student, were records can be accessed,
More informationCSE 332: Data Structures & Parallelism Lecture 8: AVL Trees. Ruth Anderson Winter 2019
CSE 2: Data Structures & Parallelism Lecture 8: AVL Trees Rut Anderson Winter 29 Today Dictionaries AVL Trees /25/29 2 Te AVL Balance Condition: Left and rigt subtrees of every node ave eigts differing
More informationeach node in the tree, the difference in height of its two subtrees is at the most p. AVL tree is a BST that is height-balanced-1-tree.
Data Structures CSC212 1 AVL Trees A binary tree is a eigt-balanced-p-tree if for eac node in te tree, te difference in eigt of its two subtrees is at te most p. AVL tree is a BST tat is eigt-balanced-tree.
More informationAlgorithms, Spring 2014, CSE, OSU Lecture 5: Red-black trees
6331 - Algorithms, Spring 2014, CSE, OSU Lecture 5: Red-black trees Instructor: Anastasios Sidiropoulos January 17, 2014 Red-black trees For every node x: x.color : red or black x.k : key x.p : pointer
More informationAnnouncements. Lilian s office hours rescheduled: Fri 2-4pm HW2 out tomorrow, due Thursday, 7/7. CSE373: Data Structures & Algorithms
Announcements Lilian s office ours resceduled: Fri 2-4pm HW2 out tomorrow, due Tursday, 7/7 CSE373: Data Structures & Algoritms Deletion in BST 2 5 5 2 9 20 7 0 7 30 Wy migt deletion be arder tan insertion?
More informationLecture 7. Binary Search Trees / AVL Trees
Lecture 7. Binary Searc Trees / AVL Trees T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algoritms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Coo coo@skku.edu Copyrigt
More informationBinary Search Tree - Best Time. AVL Trees. Binary Search Tree - Worst Time. Balanced and unbalanced BST
AL Trees CSE Data Structures Unit Reading: Section 4.4 Binary Searc Tree - Best Time All BST operations are O(d), were d is tree dept minimum d is d = log for a binary tree N wit N nodes at is te best
More informationAdvanced Tree. Structures. AVL Tree. Outline. AVL Tree Recall, Binary Search Tree (BST) is a special case of. Splay Tree (Ch 13.2.
ttp://1...0/csd/ Data tructure Capter 1 Advanced Tree tructures Dr. atrick Can cool of Computer cience and Engineering out Cina Universit of Tecnolog AVL Tree Recall, Binar earc Tree (BT) is a special
More informationDesign Patterns for Data Structures. Chapter 8. The Composite State Binary Tree BiTreeCS
Design Patterns for Data Structures Chapter 8 The Composite State Binary Tree BiTreeCS Design Patterns for Data Structures Chapter 8 The Composite State Binary Tree BiTreeCS In a nonempty node _left is
More informationData Structures and Programming Spring 2014, Midterm Exam.
Data Structures and Programming Spring 2014, Midterm Exam. 1. (10 pts) Order te following functions 2.2 n, log(n 10 ), 2 2012, 25n log(n), 1.1 n, 2n 5.5, 4 log(n), 2 10, n 1.02, 5n 5, 76n, 8n 5 + 5n 2
More informationWrap up Amortized Analysis; AVL Trees. Riley Porter Winter CSE373: Data Structures & Algorithms
CSE 373: Data Structures & Wrap up Amortized Analysis; AVL Trees Riley Porter Course Logistics Symposium offered by CSE department today HW2 released, Big- O, Heaps (lecture slides ave pseudocode tat will
More informationAVL Trees Outline and Required Reading: AVL Trees ( 11.2) CSE 2011, Winter 2017 Instructor: N. Vlajic
1 AVL Trees Outline and Required Reading: AVL Trees ( 11.2) CSE 2011, Winter 2017 Instructor: N. Vlajic AVL Trees 2 Binary Searc Trees better tan linear dictionaries; owever, te worst case performance
More informationWhen a BST becomes badly unbalanced, the search behavior can degenerate to that of a sorted linked list, O(N).
Balanced Binary Trees Binary searc trees provide O(log N) searc times provided tat te nodes are distributed in a reasonably balanced manner. Unfortunately, tat is not always te case and performing a sequence
More informationThe Composite State Visitor Pattern
Design Patterns for Data Structures Chapter 8 he Composite State Visitor Pattern Design Patterns for Data Structures Chapter 8 he Composite State Binary ree with the Visitor Pattern BireeCSV Design Patterns
More informationChapter 3. Graphs CLRS Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 3 Graphs CLRS 12-13 Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 57 CLRS 12 Binary Search Trees Binary Search Trees The search tree data structure supports
More informationRed-Black Trees. 1 Properties of red-black trees
Red-Black Trees Chapter 12 showed that a binary search tree of height h can support any of the basic dynamic-set operations such as SEARCH, PREDECESSOR, SUCCESSOR, MINI- MUM, MAXIMUM, INSERT, anddelete
More information1 Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
CHAPTER 20 AVL Trees Objectives To know wat an AVL tree is ( 20.1). To understand ow to rebalance a tree using te LL rotation, LR rotation, RR rotation, and RL rotation ( 20.2). To know ow to design te
More information15-122: Principles of Imperative Computation, Summer 2011 Assignment 6: Trees and Secret Codes
15-122: Principles of Imperative Computation, Summer 2011 Assignment 6: Trees and Secret Codes William Lovas (wlovas@cs) Karl Naden Out: Tuesday, Friday, June 10, 2011 Due: Monday, June 13, 2011 (Written
More informationTREES. General Binary Trees The Search Tree ADT Binary Search Trees AVL Trees Threaded trees Splay Trees B-Trees. UNIT -II
UNIT -II TREES General Binary Trees Te Searc Tree DT Binary Searc Trees VL Trees Treaded trees Splay Trees B-Trees. 2MRKS Q& 1. Define Tree tree is a data structure, wic represents ierarcical relationsip
More informationAlgorithms. Red-Black Trees
Algorithms Red-Black Trees Red-Black Trees Balanced binary search trees guarantee an O(log n) running time Red-black-tree Binary search tree with an additional attribute for its nodes: color which can
More information2 The Derivative. 2.0 Introduction to Derivatives. Slopes of Tangent Lines: Graphically
2 Te Derivative Te two previous capters ave laid te foundation for te study of calculus. Tey provided a review of some material you will need and started to empasize te various ways we will view and use
More informationSection 2.3: Calculating Limits using the Limit Laws
Section 2.3: Calculating Limits using te Limit Laws In previous sections, we used graps and numerics to approimate te value of a it if it eists. Te problem wit tis owever is tat it does not always give
More informationRed-Black Trees (2) Antonio Carzaniga. April 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga
Red-Black Trees (2) Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana April 23, 2013 Recap on Red-Black Trees 2006 Antonio Carzaniga Recap on Red-Black Trees 12 5 18 2 9 15 19
More informationCS 380 ALGORITHM DESIGN AND ANALYSIS
CS 380 ALGORITHM DESIGN AND ANALYSIS Lecture 12: Red-Black Trees Text Reference: Chapters 12, 13 Binary Search Trees (BST): Review Each node in tree T is a object x Contains attributes: Data Pointers to
More informationAreas of Triangles and Parallelograms. Bases of a parallelogram. Height of a parallelogram THEOREM 11.3: AREA OF A TRIANGLE. a and its corresponding.
11.1 Areas of Triangles and Parallelograms Goal p Find areas of triangles and parallelograms. Your Notes VOCABULARY Bases of a parallelogram Heigt of a parallelogram POSTULATE 4: AREA OF A SQUARE POSTULATE
More informationBounding Tree Cover Number and Positive Semidefinite Zero Forcing Number
Bounding Tree Cover Number and Positive Semidefinite Zero Forcing Number Sofia Burille Mentor: Micael Natanson September 15, 2014 Abstract Given a grap, G, wit a set of vertices, v, and edges, various
More informationProperties of red-black trees
Red-Black Trees Introduction We have seen that a binary search tree is a useful tool. I.e., if its height is h, then we can implement any basic operation on it in O(h) units of time. The problem: given
More information4.2 Binary Search Trees
Binary trees 4. Binary earc Trees Definition. BT is a binary tree in symmetric order. root a left link a subtree binary tree is eiter: mpty. rigt cild of root Two disjoint binary trees (left and rigt).
More informationHaar Transform CS 430 Denbigh Starkey
Haar Transform CS Denbig Starkey. Background. Computing te transform. Restoring te original image from te transform 7. Producing te transform matrix 8 5. Using Haar for lossless compression 6. Using Haar
More informationAVL Trees. CSE260, Computer Science B: Honors Stony Brook University
AVL Trees CSE260, Computer Science B: Honors Stony Brook University ttp://www.cs.stonybrook.edu/~cse260 1 Objectives To know wat an AVL tree is To understand ow to rebalance a tree using te LL rotation,
More informationCSCE476/876 Spring Homework 5
CSCE476/876 Spring 2016 Assigned on: Friday, Marc 11, 2016 Due: Monday, Marc 28, 2016 Homework 5 Programming assignment sould be submitted wit andin Te report can eiter be submitted wit andin as a PDF,
More informationChapter 13. Michelle Bodnar, Andrew Lohr. April 12, 2016
Chapter 13 Michelle Bodnar, Andrew Lohr April 1, 016 Exercise 13.1-1 8 4 1 6 10 14 1 3 5 7 9 11 13 15 We shorten IL to so that it can be more easily displayed in the document. The following has black height.
More informationAlgorithms. AVL Tree
Algorithms AVL Tree Balanced binary tree The disadvantage of a binary search tree is that its height can be as large as N-1 This means that the time needed to perform insertion and deletion and many other
More information19.2 Surface Area of Prisms and Cylinders
Name Class Date 19 Surface Area of Prisms and Cylinders Essential Question: How can you find te surface area of a prism or cylinder? Resource Locker Explore Developing a Surface Area Formula Surface area
More informationLinear Interpolating Splines
Jim Lambers MAT 772 Fall Semester 2010-11 Lecture 17 Notes Tese notes correspond to Sections 112, 11, and 114 in te text Linear Interpolating Splines We ave seen tat ig-degree polynomial interpolation
More informationPiecewise Polynomial Interpolation, cont d
Jim Lambers MAT 460/560 Fall Semester 2009-0 Lecture 2 Notes Tese notes correspond to Section 4 in te text Piecewise Polynomial Interpolation, cont d Constructing Cubic Splines, cont d Having determined
More informationRed-Black Trees. Based on materials by Dennis Frey, Yun Peng, Jian Chen, and Daniel Hood
Red-Black Trees Based on materials by Dennis Frey, Yun Peng, Jian Chen, and Daniel Hood Quick Review of Binary Search Trees n Given a node n... q All elements of n s left subtree are less than n.data q
More information4.1 Tangent Lines. y 2 y 1 = y 2 y 1
41 Tangent Lines Introduction Recall tat te slope of a line tells us ow fast te line rises or falls Given distinct points (x 1, y 1 ) and (x 2, y 2 ), te slope of te line troug tese two points is cange
More informationMulti-Stack Boundary Labeling Problems
Multi-Stack Boundary Labeling Problems Micael A. Bekos 1, Micael Kaufmann 2, Katerina Potika 1 Antonios Symvonis 1 1 National Tecnical University of Atens, Scool of Applied Matematical & Pysical Sciences,
More informationVOLUMES. The volume of a cylinder is determined by multiplying the cross sectional area by the height. r h V. a) 10 mm 25 mm.
OLUME OF A CYLINDER OLUMES Te volume of a cylinder is determined by multiplying te cross sectional area by te eigt. r Were: = volume r = radius = eigt Exercise 1 Complete te table ( =.14) r a) 10 mm 5
More information4.2 The Derivative. f(x + h) f(x) lim
4.2 Te Derivative Introduction In te previous section, it was sown tat if a function f as a nonvertical tangent line at a point (x, f(x)), ten its slope is given by te it f(x + ) f(x). (*) Tis is potentially
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 11: Binary Search Trees MOUNA KACEM mouna@cs.wisc.edu Fall 2018 General Overview of Data Structures 2 Introduction to trees 3 Tree: Important non-linear data structure
More informationRed-Black Trees (2) Antonio Carzaniga. Faculty of Informatics University of Lugano. April 26, Antonio Carzaniga 1
Red-lack Trees (2) ntonio arzaniga Faculty of Informatics University of Lugano pril 26, 2012 2006 ntonio arzaniga 1 Recap on Red-lack Trees 12 5 18 2 9 15 19 4 13 17 Red-black-tree property 2. 4. 5. 1.
More informationCOMP251: Red-black trees
COMP251: Red-black trees Jérôme Waldispühl School of Computer Science McGill University Based on (Cormen et al., 2002) Based on slides from D. Plaisted (UNC) The running Rme of inserrons in BST trees with
More informationData Structures and Algorithms CMPSC 465
Data Structures and Algorithms CMPSC 465 LECTURE 24 Balanced Search Trees Red-Black Trees Adam Smith 4/18/12 A. Smith; based on slides by C. Leiserson and E. Demaine L1.1 Balanced search trees Balanced
More informationDesign Patterns for Data Structures. Chapter Nguyen-Wong B-Trees
Chapter 10.3 Nguyen-Wong B-Trees Chapter 10.3 A B-tree is an n-way tree with the following characteristics It is balanced. It is ordered. It has a node size restriction. Chapter 10.3 A balanced n-way tree
More informationBalanced search trees
Balanced search trees Ordinary binary search trees have expected height Θ(log n) if items are inserted and deleted in random order, but for other orders the height can be Θ(n). This is undesirable, since
More informationFast Calculation of Thermodynamic Properties of Water and Steam in Process Modelling using Spline Interpolation
P R E P R N T CPWS XV Berlin, September 8, 008 Fast Calculation of Termodynamic Properties of Water and Steam in Process Modelling using Spline nterpolation Mattias Kunick a, Hans-Joacim Kretzscmar a,
More informationLecture 6: Analysis of Algorithms (CS )
Lecture 6: Analysis of Algorithms (CS583-002) Amarda Shehu October 08, 2014 1 Outline of Today s Class 2 Traversals Querying Insertion and Deletion Sorting with BSTs 3 Red-black Trees Height of a Red-black
More informationHash-Based Indexes. Chapter 11. Comp 521 Files and Databases Spring
Has-Based Indexes Capter 11 Comp 521 Files and Databases Spring 2010 1 Introduction As for any index, 3 alternatives for data entries k*: Data record wit key value k
More informationBalanced Trees. Nate Foster Spring 2019
Balanced Trees Nate Foster Spring 2019 Today s music: Get the Balance Right by Depeche Mode Review Previously in 3110: Streams Today: Balanced trees Running example: Sets module type Set = sig type 'a
More informationCS350: Data Structures Red-Black Trees
Red-Black Trees James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Red-Black Tree An alternative to AVL trees Insertion can be done in a bottom-up or
More informationHash-Based Indexes. Chapter 11. Comp 521 Files and Databases Fall
Has-Based Indexes Capter 11 Comp 521 Files and Databases Fall 2012 1 Introduction Hasing maps a searc key directly to te pid of te containing page/page-overflow cain Doesn t require intermediate page fetces
More informationSearch Trees. Undirected graph Directed graph Tree Binary search tree
Search Trees Undirected graph Directed graph Tree Binary search tree 1 Binary Search Tree Binary search key property: Let x be a node in a binary search tree. If y is a node in the left subtree of x, then
More informationBST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams
Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr mahmoud.sakr@cis.asu.edu.eg Cairo, Egypt, October 2012 Binary Search Trees (BST) 1. Hierarchical data structure with a single reference to root
More information, 1 1, A complex fraction is a quotient of rational expressions (including their sums) that result
RT. Complex Fractions Wen working wit algebraic expressions, sometimes we come across needing to simplify expressions like tese: xx 9 xx +, xx + xx + xx, yy xx + xx + +, aa Simplifying Complex Fractions
More informationClassify solids. Find volumes of prisms and cylinders.
11.4 Volumes of Prisms and Cylinders Essential Question How can you find te volume of a prism or cylinder tat is not a rigt prism or rigt cylinder? Recall tat te volume V of a rigt prism or a rigt cylinder
More informationLECTURE 18 AVL TREES
DATA STRUCTURES AND ALGORITHMS LECTURE 18 AVL TREES IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD PROTOTYPICAL EXAMPLES These two examples demonstrate how we can correct for imbalances: starting
More informationBalanced Trees. Nate Foster Spring 2018
Balanced Trees Nate Foster Spring 2018 Prelim I Tonight! 5:30 7:30 Bring your Cornell ID Card If you have a letter allowing you special accommodations for the exam, send mail to cs3110-profs-l@list.cornell.edu
More informationNote that this is a rep invariant! The type system doesn t enforce this but you need it to be true. Should use repok to check in debug version.
Announcements: Prelim tonight! 7:30-9:00 in Thurston 203/205 o Handed back in section tomorrow o If you have a conflict you can take the exam at 5:45 but can t leave early. Please email me so we have a
More informationModels & Implementations
:* :+ Legend: :* :+ Legend: 72 Intro to Programming and Algoritms 2 (Adv.) 215 Uwe R. Zimmer - Te Australian National University 74 Algebraic types foundations: Recursive types Lists Verbal definition:
More informationChapter K. Geometric Optics. Blinn College - Physics Terry Honan
Capter K Geometric Optics Blinn College - Pysics 2426 - Terry Honan K. - Properties of Ligt Te Speed of Ligt Te speed of ligt in a vacuum is approximately c > 3.0µ0 8 mês. Because of its most fundamental
More informationIntroduction to Computer Graphics 5. Clipping
Introduction to Computer Grapics 5. Clipping I-Cen Lin, Assistant Professor National Ciao Tung Univ., Taiwan Textbook: E.Angel, Interactive Computer Grapics, 5 t Ed., Addison Wesley Ref:Hearn and Baker,
More informationCS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya
CS62: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Binary Search Tree - Best Time All BST operations are O(d), where d is tree depth minimum d is d = ëlog for a binary tree
More informationCS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya
CS62: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Balanced search trees Balanced search tree: A search-tree data structure for which a height of O(lg n) is guaranteed when
More information3.6 Directional Derivatives and the Gradient Vector
288 CHAPTER 3. FUNCTIONS OF SEVERAL VARIABLES 3.6 Directional Derivatives and te Gradient Vector 3.6.1 Functions of two Variables Directional Derivatives Let us first quickly review, one more time, te
More informationSymmetric Tree Replication Protocol for Efficient Distributed Storage System*
ymmetric Tree Replication Protocol for Efficient Distributed torage ystem* ung Cune Coi 1, Hee Yong Youn 1, and Joong up Coi 2 1 cool of Information and Communications Engineering ungkyunkwan University
More informationAll truths are easy to understand once they are discovered; the point is to discover them. Galileo
Section 7. olume All truts are easy to understand once tey are discovered; te point is to discover tem. Galileo Te main topic of tis section is volume. You will specifically look at ow to find te volume
More informationTHANK YOU FOR YOUR PURCHASE!
THANK YOU FOR YOUR PURCHASE! Te resources included in tis purcase were designed and created by me. I ope tat you find tis resource elpful in your classroom. Please feel free to contact me wit any questions
More informationBinary Search Trees. Analysis of Algorithms
Binary Search Trees Analysis of Algorithms Binary Search Trees A BST is a binary tree in symmetric order 31 Each node has a key and every node s key is: 19 23 25 35 38 40 larger than all keys in its left
More informationPart 2: Balanced Trees
Part 2: Balanced Trees 1 AVL Trees We could dene a perfectly balanced binary search tree with N nodes to be a complete binary search tree, one in which every level except the last is completely full. A
More informationBinary Tree Node Relationships. Binary Trees. Quick Application: Expression Trees. Traversals
Binary Trees 1 Binary Tree Node Relationships 2 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the
More informationCS102 Binary Search Trees
CS102 Binary Search Trees Prof Tejada 1 To speed up insertion, removal and search, modify the idea of a Binary Tree to create a Binary Search Tree (BST) Binary Search Trees Binary Search Trees have one
More informationBinary Trees. For example: Jargon: General Binary Trees. root node. level: internal node. edge. leaf node. Data Structures & File Management
Binary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from
More informationWhen the dimensions of a solid increase by a factor of k, how does the surface area change? How does the volume change?
8.4 Surface Areas and Volumes of Similar Solids Wen te dimensions of a solid increase by a factor of k, ow does te surface area cange? How does te volume cange? 1 ACTIVITY: Comparing Surface Areas and
More informationSorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min
Binary Search Trees FRIDAY ALGORITHMS Sorted Arrays Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min 6 10 11 17 2 0 6 Running Time O(1) O(lg n) O(1) O(1)
More informationBalanced Trees. Prof. Clarkson Fall Today s music: Get the Balance Right by Depeche Mode
Balanced Trees Prof. Clarkson Fall 2017 Today s music: Get the Balance Right by Depeche Mode Prelim See Piazza post @422 Makeup: Thursday night 5:30 pm Wed noon: All requests for other makeup/conflict
More informationYou should be able to visually approximate the slope of a graph. The slope m of the graph of f at the point x, f x is given by
Section. Te Tangent Line Problem 89 87. r 5 sin, e, 88. r sin sin Parabola 9 9 Hperbola e 9 9 9 89. 7,,,, 5 7 8 5 ortogonal 9. 5, 5,, 5, 5. Not multiples of eac oter; neiter parallel nor ortogonal 9.,,,
More informationMATH 5a Spring 2018 READING ASSIGNMENTS FOR CHAPTER 2
MATH 5a Spring 2018 READING ASSIGNMENTS FOR CHAPTER 2 Note: Tere will be a very sort online reading quiz (WebWork) on eac reading assignment due one our before class on its due date. Due dates can be found
More information2.3 Additional Relations
3 2.3 Additional Relations Figure 2.3 identiies additional relations, indicating te locations o te object and image, and te ratio o teir eigts (magniication) and orientations. Ray enters te lens parallel
More information2-3 Tree. Outline B-TREE. catch(...){ printf( "Assignment::SolveProblem() AAAA!"); } ADD SLIDES ON DISJOINT SETS
Outline catch(...){ printf( "Assignment::SolveProblem() AAAA!"); } Balanced Search Trees 2-3 Trees 2-3-4 Trees Slide 4 Why care about advanced implementations? Same entries, different insertion sequence:
More informationDistributed and Optimal Rate Allocation in Application-Layer Multicast
Distributed and Optimal Rate Allocation in Application-Layer Multicast Jinyao Yan, Martin May, Bernard Plattner, Wolfgang Mülbauer Computer Engineering and Networks Laboratory, ETH Zuric, CH-8092, Switzerland
More informationvoid insert( Type const & ) void push_front( Type const & )
6.1 Binary Search Trees A binary search tree is a data structure that can be used for storing sorted data. We will begin by discussing an Abstract Sorted List or Sorted List ADT and then proceed to describe
More informationRed-Black trees are usually described as obeying the following rules :
Red-Black Trees As we have seen, the ideal Binary Search Tree has height approximately equal to log n, where n is the number of values stored in the tree. Such a BST guarantees that the maximum time for
More informationECE 250 Data Structures and Algorithms MID-TERM EXAMINATION B /13:30-14:50 MC-4021/RCH-211
ECE 250 Data Structures and Algorithms MID-TERM EXAMINATION B 2011-02-15/13:30-14:50 MC-4021/RCH-211 Instructions: There are 63 marks. It will be marked out of 55. No aides. Turn off all electronic media
More informationCS211 Spring 2004 Lecture 06 Loops and their invariants. Software engineering reason for using loop invariants
CS211 Spring 2004 Lecture 06 Loops and teir invariants Reading material: Tese notes. Weiss: Noting on invariants. ProgramLive: Capter 7 and 8 O! Tou ast damnale iteration and art, indeed, ale to corrupt
More informationCMPS 2200 Fall 2015 Red-black trees Carola Wenk
CMPS 2200 Fall 2015 Red-black trees Carola Wenk Slides courtesy of Charles Leiserson with changes by Carola Wenk 9/9/15 CMPS 2200 Intro. to Algorithms 1 ADT Dictionary / Dynamic Set Abstract data type
More informationLecture 16 AVL Trees
Lecture 16 AVL Trees 15-122: Principles of Imperative Computation (Fall 2018) Frank Pfenning Binary search trees are an excellent data structure to implement associative arrays, maps, sets, and similar
More informationCS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY
CS 251, LE 2 Fall 2016 MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY W1.) (i) Show one possible valid 2-3 tree containing the nine elements: 1 3 4 5 6 8 9 10 12. (ii) Draw the final binary search
More informationLecture: Analysis of Algorithms (CS )
Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 1 Binary Search Trees Traversals, Querying, Insertion, and Deletion Sorting with BSTs 2 Example: Red-black Trees Height of a Red-black
More information12.2 Investigate Surface Area
Investigating g Geometry ACTIVITY Use before Lesson 12.2 12.2 Investigate Surface Area MATERIALS grap paper scissors tape Q U E S T I O N How can you find te surface area of a polyedron? A net is a pattern
More informationModule 4: Dictionaries and Balanced Search Trees
Module 4: Dictionaries and Balanced Search Trees CS 24 - Data Structures and Data Management Jason Hinek and Arne Storjohann Based on lecture notes by R. Dorrigiv and D. Roche David R. Cheriton School
More informationSection 1: True / False (1 point each, 15 pts total)
Section : True / False ( point each, pts total) Circle the word TRUE or the word FALSE. If neither is circled, both are circled, or it impossible to tell which is circled, your answer will be considered
More informationRedundancy Awareness in SQL Queries
Redundancy Awareness in QL Queries Bin ao and Antonio Badia omputer Engineering and omputer cience Department University of Louisville bin.cao,abadia @louisville.edu Abstract In tis paper, we study QL
More informationMTH-112 Quiz 1 - Solutions
MTH- Quiz - Solutions Words in italics are for eplanation purposes onl (not necessar to write in te tests or. Determine weter te given relation is a function. Give te domain and range of te relation. {(,
More informationVideoText Interactive
VideoText Interactive Homescool and Independent Study Sampler Print Materials for Geometry: A Complete Course Unit I, Part C, Lesson 3 Triangles ------------------------------------------ Course Notes
More informationChapter 20: Binary Trees
Chapter 20: Binary Trees 20.1 Definition and Application of Binary Trees Definition and Application of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two other
More information