AVL Trees
Adelson-Velskii and Landis
Binary Search Tree - Best Time
All BST operations are O(d), where d is tree depth
minimum d is for a binary tree with N nodes
What is the best case tree?
What is the worst case tree?
So, best case running time of BST operations is O(log N)
Binary Search Tree - Worst Time
Worst case running time is O(N)
What happens when you Insert elements in ascending order?
Insert: 2, 4, 6, 8, 10, 12 into an empty BST
Problem: Lack of balance:
compare depths of left and right subtree
Unbalanced degenerate tree
Balanced and unbalanced BST
Approaches to balancing trees
Don't balance
May end up with some nodes very deep
Strict balance
The tree must always be balanced perfectly
Pretty good balance
Only allow a little out of balance
Adjust on access
Self-adjusting
Balancing Binary Search Trees
Many algorithms exist for keeping binary search trees balanced
Adelson-Velskii and Landis (AVL) trees (height-balanced trees)
Splay trees and other self-adjusting trees
B-trees and other multiway search trees
Perfect Balance
Want a complete tree after every operation
tree is full except possibly in the lower right
This is expensive
For example, insert 2 in the tree on the left and then rebuild as a complete tree
AVL - Good but not Perfect Balance
AVL trees are height-balanced binary search trees
Balance factor of a node
height(left subtree) - height(right subtree)
An AVL tree has balance factor calculated at every node
For every node, heights of left and right subtree can differ by no more than 1
Store current heights in each node
Height of an AVL Tree
N(h) = minimum number of nodes in an AVL tree of height h.
Basis
N(0) = 1, N(1) = 2
Induction
N(h) = N(h-1) + N(h-2) + 1
Solution (recall Fibonacci analysis)
N(h) > h ( 1.62)
Height of an AVL Tree
N(h) > h ( 1.62)
Suppose we have n nodes in an AVL tree of height h.
n > N(h) (because N(h) was the minimum)
n > h hence log n > h (relatively well balanced tree!!)
h < 1.44 log2n (i.e., Find takes O(logn))
Node Heights
Node Heights after Insert 7
Insert and Rotation in AVL Trees
Insert operation may cause balance factor to become 2 or 2 for some node
only nodes on the path from insertion point to root node have possibly changed in height
So after the Insert, go back up to the root node by node, updating heights
If a new balance factor is 2 or 2, adjust tree by rotation around the node
Single Rotation in an AVL Tree
Implementation
Single Rotation
Double Rotation
Implement Double Rotation in two lines.
Insertion in AVL Trees
Insert at the leaf (as for all BST)
only nodes on the path from insertion point to root node have possibly changed in height
So after the Insert, go back up to the root node by node, updating heights
If a new balance factor is 2 or 2, adjust tree by rotation around the node
Insert in BST
Insert in AVL trees
Example of Insertions in an A
This document provides an overview of cloud computing. It defines cloud computing as network-based computing that takes place over the Internet, providing hardware, software, and networking services to clients. Key characteristics of cloud computing include on-demand services that are available anywhere and anytime, elastic scaling, and pay-as-you-go pricing. The document discusses different cloud service models including Software as a Service (SaaS), Platform as a Service (PaaS), and Infrastructure as a Service (IaaS). It also covers advantages such as lower costs, improved performance and collaboration, and unlimited storage, as well as disadvantages like reliance on internet connectivity and potential security and data loss issues.
This document provides an introduction and overview of cloud computing and related topics. It discusses web-scale problems involving large amounts of data, the use of large data centers to process this data in parallel, and different models for cloud computing including utility computing, platform as a service, and software as a service. It also covers challenges in parallel and distributed processing like assigning work units across workers and managing shared resources and synchronization.
Thus cloud computing provides super-computing power by connecting hundreds or thousands of computers together in a cloud. This cloud of computers extends beyond a single company or enterprise, making the applications and data accessible to a broad group of users across different companies and platforms. Users can access documents, software programs, and other data from any Internet-connected computer rather than just their own personal computer.
AVL Trees
Adelson-Velskii and Landis
Binary Search Tree - Best Time
All BST operations are O(d), where d is tree depth
minimum d is for a binary tree with N nodes
What is the best case tree?
What is the worst case tree?
So, best case running time of BST operations is O(log N)
Binary Search Tree - Worst Time
Worst case running time is O(N)
What happens when you Insert elements in ascending order?
Insert: 2, 4, 6, 8, 10, 12 into an empty BST
Problem: Lack of balance:
compare depths of left and right subtree
Unbalanced degenerate tree
Balanced and unbalanced BST
Approaches to balancing trees
Don't balance
May end up with some nodes very deep
Strict balance
The tree must always be balanced perfectly
Pretty good balance
Only allow a little out of balance
Adjust on access
Self-adjusting
Balancing Binary Search Trees
Many algorithms exist for keeping binary search trees balanced
Adelson-Velskii and Landis (AVL) trees (height-balanced trees)
Splay trees and other self-adjusting trees
B-trees and other multiway search trees
Perfect Balance
Want a complete tree after every operation
tree is full except possibly in the lower right
This is expensive
For example, insert 2 in the tree on the left and then rebuild as a complete tree
AVL - Good but not Perfect Balance
AVL trees are height-balanced binary search trees
Balance factor of a node
height(left subtree) - height(right subtree)
An AVL tree has balance factor calculated at every node
For every node, heights of left and right subtree can differ by no more than 1
Store current heights in each node
Height of an AVL Tree
N(h) = minimum number of nodes in an AVL tree of height h.
Basis
N(0) = 1, N(1) = 2
Induction
N(h) = N(h-1) + N(h-2) + 1
Solution (recall Fibonacci analysis)
N(h) > h ( 1.62)
Height of an AVL Tree
N(h) > h ( 1.62)
Suppose we have n nodes in an AVL tree of height h.
n > N(h) (because N(h) was the minimum)
n > h hence log n > h (relatively well balanced tree!!)
h < 1.44 log2n (i.e., Find takes O(logn))
Node Heights
Node Heights after Insert 7
Insert and Rotation in AVL Trees
Insert operation may cause balance factor to become 2 or 2 for some node
only nodes on the path from insertion point to root node have possibly changed in height
So after the Insert, go back up to the root node by node, updating heights
If a new balance factor is 2 or 2, adjust tree by rotation around the node
Single Rotation in an AVL Tree
Implementation
Single Rotation
Double Rotation
Implement Double Rotation in two lines.
Insertion in AVL Trees
Insert at the leaf (as for all BST)
only nodes on the path from insertion point to root node have possibly changed in height
So after the Insert, go back up to the root node by node, updating heights
If a new balance factor is 2 or 2, adjust tree by rotation around the node
Insert in BST
Insert in AVL trees
Example of Insertions in an A
This document provides an overview of cloud computing. It defines cloud computing as network-based computing that takes place over the Internet, providing hardware, software, and networking services to clients. Key characteristics of cloud computing include on-demand services that are available anywhere and anytime, elastic scaling, and pay-as-you-go pricing. The document discusses different cloud service models including Software as a Service (SaaS), Platform as a Service (PaaS), and Infrastructure as a Service (IaaS). It also covers advantages such as lower costs, improved performance and collaboration, and unlimited storage, as well as disadvantages like reliance on internet connectivity and potential security and data loss issues.
This document provides an introduction and overview of cloud computing and related topics. It discusses web-scale problems involving large amounts of data, the use of large data centers to process this data in parallel, and different models for cloud computing including utility computing, platform as a service, and software as a service. It also covers challenges in parallel and distributed processing like assigning work units across workers and managing shared resources and synchronization.
Thus cloud computing provides super-computing power by connecting hundreds or thousands of computers together in a cloud. This cloud of computers extends beyond a single company or enterprise, making the applications and data accessible to a broad group of users across different companies and platforms. Users can access documents, software programs, and other data from any Internet-connected computer rather than just their own personal computer.
50. 畛p m畉t ti畛n v b畉c tam c畉p 叩 hoa c動董ng 畛p 叩 hoa c動董ng m畉t ti畛n
B畉c tam c畉p 叩 hoa c動董ng c滴ng l m畛t trong nh畛ng v畛 tr鱈 動畛c thi c担ng nhi畛u. C叩c gia
狸nh th動畛ng lm b畉c tam c畉p k畉t h畛p v畛i 畛p m畉t ti畛n 叩 hoa c動董ng, lm cho m畉t ti畛n tr畛
n棚n sang tr畛ng, c畛ng c叩p v 畉p h董n r畉t nhi畛u. B畉n c坦 th畛 xem qua m畛t s畛 nh, c畛a hng
c坦 b畉c tam c畉p 畛p 叩 hoa c動董ng v kh担ng 畛p 叩 hoa c動董ng 畛 c坦 th畛 so s叩nh tr畛c quan
h董n.
51. C嘆n b棚n trong nh b畉p th狸 sao? 叩 hoa c動董ng th動畛ng 動畛c d湛ng 叩p l叩t ph嘆ng t畉m, ph嘆ng
v畛 sinh, m畉t b畉p bn bar, lavabo
Nh畉n 畛p m畉t bn b畉p 叩 hoa c動董ng v lavabo b畉ng
叩 hoa c動董ng gi叩 r畉 畛 tphcm
Ngy nay c叩c gian b畉p hi畛n 畉i th動畛ng lm m畉t b畉p b畉ng 叩 hoa c動董ng v c畉 lavabo 叩
hoa c動董ng. Nh畉m t畉o c畉m gi叩c m叩t m畉 v s畉ch cho cn b畉p, nhi畛u gia 狸nh li棚n h畛 v畛i
ch炭ng t担i 畛 thi c担ng b畉p 叩 hoa c動董ng. D動畛i 但y l m畛t s畛 m畉u bn b畉p 叩 hoa c動董ng
畉p m b畉n c坦 th畛 tham kh畉o tr動畛c.