An enhanced fuzzy rough set based clustering algorithm for categorical dataeSAT Journals
Abstract In today’s world everything is done digitally and so we have lots of data raw data. This data are useful to predict future events if we proper use it. Clustering is such a technique where we put closely related data together. Furthermore we have types of data sequential, interval, categorical etc. In this paper we have shown what is the problem with clustering categorical data with rough set and who we can overcome with improvement.
VALIDATION METHOD OF FUZZY ASSOCIATION RULES BASED ON FUZZY FORMAL CONCEPT AN...cscpconf
In order to treat and analyze real datasets, fuzzy association rules have been proposed. Several
algorithms have been introduced to extract these rules. However, these algorithms suffer from
the problems of utility, redundancy and large number of extracted fuzzy association rules. The
expert will then be confronted with this huge amount of fuzzy association rules. The task of
validation becomes fastidious. In order to solve these problems, we propose a new validation
method. Our method is based on three steps. (i) We extract a generic base of non redundant
fuzzy association rules by applying EFAR-PN algorithm based on fuzzy formal concept analysis.
(ii) we categorize extracted rules into groups and (iii) we evaluate the relevance of these rules
using structural equation model.
An enhanced fuzzy rough set based clustering algorithm for categorical dataeSAT Journals
Abstract In today’s world everything is done digitally and so we have lots of data raw data. This data are useful to predict future events if we proper use it. Clustering is such a technique where we put closely related data together. Furthermore we have types of data sequential, interval, categorical etc. In this paper we have shown what is the problem with clustering categorical data with rough set and who we can overcome with improvement.
VALIDATION METHOD OF FUZZY ASSOCIATION RULES BASED ON FUZZY FORMAL CONCEPT AN...cscpconf
In order to treat and analyze real datasets, fuzzy association rules have been proposed. Several
algorithms have been introduced to extract these rules. However, these algorithms suffer from
the problems of utility, redundancy and large number of extracted fuzzy association rules. The
expert will then be confronted with this huge amount of fuzzy association rules. The task of
validation becomes fastidious. In order to solve these problems, we propose a new validation
method. Our method is based on three steps. (i) We extract a generic base of non redundant
fuzzy association rules by applying EFAR-PN algorithm based on fuzzy formal concept analysis.
(ii) we categorize extracted rules into groups and (iii) we evaluate the relevance of these rules
using structural equation model.
Students will be able to learn the concepts of advanced trees like Splay Tree, B Tree, Red Black Tree, Priority Queue or Heap. In Heap Data Structure the following methods are covered: Binary Heap, d-heap, Leftist Heap and Skew Heap.
Splay trees balance trees in a different way from AVL trees. A.docxmckellarhastings
Splay trees balance trees in a different way from AVL trees. An AVL tree always has height
O(log n) meaning that every operation will require O(log n) time which is as good as you can possibly
expect fro a BST. Splay trees allow some operations to take much longer, but the slow operations are
balanced out by a sufficient number of faster ones. This is referred to as amortized complexity where
over a total of n operations on a splay tree the average amount of time spent on each operation is O(log
n). You will see an example of this later.
Pretty much everything you need to know about splay trees is here. You only need to read the first 3
sections. Some important points you will read are: (1) It is possible to have a splay tree with height
O(n) but on average the height will be O(log n). (2) Splay trees require no extra storage so they are
space efficient. AVL trees require a balance factor in each node, so this less true for AVL trees. (3)
Somewhat surprisingly, an element after insertion is moved (splayed) to the root of the tree. His may
sound inefficient but it is during this splaying process that the tree is balanced. (4) The main operations
performed while balancing a splay tree are zig-zig and zig-zag. It’s also possible for there to be a single
zig when the element moves to the root of the tree.
Looking at section 3 on operations, the simple zig step should look familiar to you. It is a simple right
or left rotation. So, looking at the zig step diagram you can see that moving x to the root is just a right
rotation.
When splaying up from further down the tree we always go two steps at once. If the node being splayed
up is either left–left or right–right of its grandparent then a zig-zig splay is performed. Looking at the
zig-zig diagram you can see to accomplish this you must first rotate g to the right, then rotate p to the
right, bringing x two levels higher in the tree. If you do it in the other order you will not end up with
the same tree. I suggest you try it to confirm what I say.
If when splaying up a node it is either left–right or right–left of the grandparent then a zig-zag is
performed. Looking at the zig-zag diagram we this this is done by rotating p left, then g right. Even
though both of these were two separate single rotations, to help remember the algorithm I suggest you
think of them both as different but easy to remember double rotations – just as you should have done
with AVL trees.
Here is an example with some explanations.
Start with an empty tree.
Now insert 10. This is a 1-node tree, 10 is already at the root so no splaying necessary.
10
Insert 20. First insert as you would with any BST, giving
10
20
Now splay 20 to the root. It is just one step away, so a zig brings it to the root.
https://en.wikipedia.org/wiki/Splay_tree
20
10
Now insert 30.
20
10 30
Again, it is one step from the root, so zig it up.
30
20
10
Now insert 4.
Coding Assignment 3CSC 330 Advanced Data Structures, Spri.docxmary772
Coding Assignment 3
CSC 330: Advanced Data Structures, Spring 2019
Released Monday, April 15, 2019
Due on Canvas on Wednesday, May 1, at 11:59pm
Overview
In this assignment, you’ll implement another variant of a height-balancing tree known as a
splay tree. The assignment will also give you an opportunity to work with Java inheritance;
in particular, the base code that you’ll amend is structured so that your SplayTree class
extends from an abstract class called HeightBalancingTree, which gives a general template
for how a height-balancing tree should be defined.
As always, please carefully read the entire write-up before you begin coding your submission.
Splay Trees
As mentioned above, a splay tree is another example of a height-balancing tree — a binary
search tree that, upon either an insertion or deletion, modifies the tree through a sequence
of rotations in order to reduce the overall height of the tree.
However, splay trees differ from the other height-balancing trees we’ve seen (AVL trees,
red-black trees) in terms of the type of guarantees that they provide. In particular, recall
that both AVL trees and red-black trees maintain the property that after any insertion or
deletion, the height of the tree is O(log n), where n is the number of elements in the tree.
Splay trees unfortunately do not provide this (fairly strong) guarantee; namely, it is possible
for the height of a splay tree to become greater than O(log n) over a sequence of insertions
and deletions.
Instead, splay trees provide a slightly weaker (though still meaningful) guarantee known as
an amortized bound, which is essentially just a bound on the average time of a single opera-
tion over the course of several operations. In the context of splay trees, one can show that
over the course of, say, n insertions to build a tree with n elements, the average time of each
of these operations is O(log n) (but again, keeping in mind it is possible for any single one
of these operations to take much longer than this).
Showing this guarantee is beyond the scope of this course (although the details of the analy-
sis can be found in your textbook). Instead, in this assignment, we will just be in interested
1
r splay:
N
root
root
2
1
1
2
l splay:
N
1
2
rr splay:
N
N
N
ll splay:
rl splay:
1
2
N
lr splay:
Figure 1: Illustration of the six possible cases for on a given step of a splay operation.
in writing an implementation of a splay tree in Java that is structured using inheritance.
Splay Tree Insertions and Deletions
To insert or delete an element from the tree, splay trees use the same approach as the other
height-balancing trees we’ve discussed in class — first we insert/deletion an element using
standard BST procedures, and then perform a “height-fixing” procedure that rebalances the
tree. Thus, what distinguishes each of these height-balancing trees from one another is how
they define their height-fixing procedures.
To fix the tree after both inser.
Students will be able to learn the concepts of advanced trees like Splay Tree, B Tree, Red Black Tree, Priority Queue or Heap. In Heap Data Structure the following methods are covered: Binary Heap, d-heap, Leftist Heap and Skew Heap.
Splay trees balance trees in a different way from AVL trees. A.docxmckellarhastings
Splay trees balance trees in a different way from AVL trees. An AVL tree always has height
O(log n) meaning that every operation will require O(log n) time which is as good as you can possibly
expect fro a BST. Splay trees allow some operations to take much longer, but the slow operations are
balanced out by a sufficient number of faster ones. This is referred to as amortized complexity where
over a total of n operations on a splay tree the average amount of time spent on each operation is O(log
n). You will see an example of this later.
Pretty much everything you need to know about splay trees is here. You only need to read the first 3
sections. Some important points you will read are: (1) It is possible to have a splay tree with height
O(n) but on average the height will be O(log n). (2) Splay trees require no extra storage so they are
space efficient. AVL trees require a balance factor in each node, so this less true for AVL trees. (3)
Somewhat surprisingly, an element after insertion is moved (splayed) to the root of the tree. His may
sound inefficient but it is during this splaying process that the tree is balanced. (4) The main operations
performed while balancing a splay tree are zig-zig and zig-zag. It’s also possible for there to be a single
zig when the element moves to the root of the tree.
Looking at section 3 on operations, the simple zig step should look familiar to you. It is a simple right
or left rotation. So, looking at the zig step diagram you can see that moving x to the root is just a right
rotation.
When splaying up from further down the tree we always go two steps at once. If the node being splayed
up is either left–left or right–right of its grandparent then a zig-zig splay is performed. Looking at the
zig-zig diagram you can see to accomplish this you must first rotate g to the right, then rotate p to the
right, bringing x two levels higher in the tree. If you do it in the other order you will not end up with
the same tree. I suggest you try it to confirm what I say.
If when splaying up a node it is either left–right or right–left of the grandparent then a zig-zag is
performed. Looking at the zig-zag diagram we this this is done by rotating p left, then g right. Even
though both of these were two separate single rotations, to help remember the algorithm I suggest you
think of them both as different but easy to remember double rotations – just as you should have done
with AVL trees.
Here is an example with some explanations.
Start with an empty tree.
Now insert 10. This is a 1-node tree, 10 is already at the root so no splaying necessary.
10
Insert 20. First insert as you would with any BST, giving
10
20
Now splay 20 to the root. It is just one step away, so a zig brings it to the root.
https://en.wikipedia.org/wiki/Splay_tree
20
10
Now insert 30.
20
10 30
Again, it is one step from the root, so zig it up.
30
20
10
Now insert 4.
Coding Assignment 3CSC 330 Advanced Data Structures, Spri.docxmary772
Coding Assignment 3
CSC 330: Advanced Data Structures, Spring 2019
Released Monday, April 15, 2019
Due on Canvas on Wednesday, May 1, at 11:59pm
Overview
In this assignment, you’ll implement another variant of a height-balancing tree known as a
splay tree. The assignment will also give you an opportunity to work with Java inheritance;
in particular, the base code that you’ll amend is structured so that your SplayTree class
extends from an abstract class called HeightBalancingTree, which gives a general template
for how a height-balancing tree should be defined.
As always, please carefully read the entire write-up before you begin coding your submission.
Splay Trees
As mentioned above, a splay tree is another example of a height-balancing tree — a binary
search tree that, upon either an insertion or deletion, modifies the tree through a sequence
of rotations in order to reduce the overall height of the tree.
However, splay trees differ from the other height-balancing trees we’ve seen (AVL trees,
red-black trees) in terms of the type of guarantees that they provide. In particular, recall
that both AVL trees and red-black trees maintain the property that after any insertion or
deletion, the height of the tree is O(log n), where n is the number of elements in the tree.
Splay trees unfortunately do not provide this (fairly strong) guarantee; namely, it is possible
for the height of a splay tree to become greater than O(log n) over a sequence of insertions
and deletions.
Instead, splay trees provide a slightly weaker (though still meaningful) guarantee known as
an amortized bound, which is essentially just a bound on the average time of a single opera-
tion over the course of several operations. In the context of splay trees, one can show that
over the course of, say, n insertions to build a tree with n elements, the average time of each
of these operations is O(log n) (but again, keeping in mind it is possible for any single one
of these operations to take much longer than this).
Showing this guarantee is beyond the scope of this course (although the details of the analy-
sis can be found in your textbook). Instead, in this assignment, we will just be in interested
1
r splay:
N
root
root
2
1
1
2
l splay:
N
1
2
rr splay:
N
N
N
ll splay:
rl splay:
1
2
N
lr splay:
Figure 1: Illustration of the six possible cases for on a given step of a splay operation.
in writing an implementation of a splay tree in Java that is structured using inheritance.
Splay Tree Insertions and Deletions
To insert or delete an element from the tree, splay trees use the same approach as the other
height-balancing trees we’ve discussed in class — first we insert/deletion an element using
standard BST procedures, and then perform a “height-fixing” procedure that rebalances the
tree. Thus, what distinguishes each of these height-balancing trees from one another is how
they define their height-fixing procedures.
To fix the tree after both inser.
Jan vitek distributedrandomforest_5-2-2013Sri Ambati
- Powered by the open source machine learning software H2O.ai. Contributors welcome at: https://github.com/h2oai
- To view videos on H2O open source machine learning software, go to: https://www.youtube.com/user/0xdata
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
UiPath Test Automation using UiPath Test Suite series, part 3
Sienna 6 bst
1. Computer Science 385
Analysis of Algorithms
Siena College
Spring 2011
Topic Notes: Binary Search Trees
Possibly the most common usage of a binary tree is to store data for quick retrieval.
Definition: A binary tree is a binary search tree (BST) iff it is empty or if the value of every node
is both greater than or equal to every value in its left subtree and less than or equal to every value
in its right subtree.
6
4 9
2 5 7 10
1 3 8
Note that a BST is an ordered structure. That is, it maintains all of its elements in order. This
restriction allows us to build more efficient implementations of the most important operations on
the tree.
We will refer to the implementation of binary search trees in the structure package, the same
package we have been using for graph implementations.
Any interesting operation in a BST (get, add, remove) has to begin with a search for the correct
place in the tree to do the operation. Our implementation has a helper method used by all of these
to do just that. We want to find the BinaryTree whose root either contains the value, or, if the
value is not to be found, the node whose non-existent child would contain the value.
This is just a binary search, and is performed in the protected method locate.
Next, let’s consdier the add method. We will be creating a new BinaryTree with the given
value, and setting parent and child links in the tree to place this new value appropriately.
We need to consider several cases:
1. We are adding to an empty binary tree, in which case we just make the new node the root of
the BST.
2. We add the new value as a new leaf at the appropriate place in the tree as the child of a
current leaf. For example, add 5.5 to this tree:
2. CS 385 Analysis of Algorithms Spring 2011
6
4 9
2 5 7 10
1 3 8
to get
6
4 9
2 5 7 10
1 3 5.5 8
3. If the value is one that is already in the tree, the search may stop early, in which case we
need to add the new item as a child of the predecessor of the node found.
For example, adding 9 to the tree above:
6
4 9
2 5 7 10
1 3 5.5 8
9
We can choose to add duplicate values as either left or right children as long as we’re con-
sistent. Our implementation chooses to put them at the left.
Our add implementation used a helper method predecessor. We have this, plus a helper
method to find the successor.
These are pretty straightforward. Our predecessor is the rightmost entry in our left subtree, and the
successor is the leftmost entry in the right subtree.
The get method is very simple. It’s just a locate, followed by a check to make sure the value
was found at the location.
remove is more interesting.
Again, there are a number of possibilities:
1. We are removing a leaf, which is very straightforward.
2
3. CS 385 Analysis of Algorithms Spring 2011
2. We are removing the root of the entire tree, in which case we need to change the root of the
BST.
3. We are removing an internal node, in which case we need to merge the children into a single
subtree to replace the removed internal node.
4. The item is not found, so the tree is unmodified and we return null.
The implementation separates out three important cases: removing the root, removing a node
which is a left subtree, or removing a node which is a right subtree. In each case, we replace the
removed node with a tree equivalent to its two subtrees, merged together. This is accomplished
through the removeTop method.
This method is also broken into a number of cases:
1. Easy cases: If either child of top is empty, just use the other child as the new top. Done.
2. Another easy case: top’s left child has no right child. Here, just assign top’s right to be the
right child of left child and call the left child the new top.
3. The more complex case remains: left child has a right child.
Here, we will proceed by locating the predecessor of the top node, make that the new top,
and rearrange the subtrees in the only way that retains the order of the entire tree.
What about complexity of these operations?
add, get, contains, and remove are all proportional to the height of the tree. So if the tree is
well-balanced, these are Θ(log n), but all are Θ(n) in the worst case.
Tree Sort
One of many ways we can use a BST is for sorting.
We can build a BST containing our data and then do an inorder traversal to retrieve them in sorted
order. Since the cost of entering an element into a (balanced) binary tree of size n is log n, the cost
of building the tree is
(log 1) + (log 2) + (log 3) + · · · + (log n) = Θ(n log n) compares.
The inorder traversal is Θ(n). The total cost is Θ(n log n) in both the best and average cases.
The worst case occurs if the input data is in order. In this case, we’re essentially doing an insertion
sort, creating a tree with one long branch. This results in a tree search as bad as Θ(n2 ).
Balanced Trees
3
4. CS 385 Analysis of Algorithms Spring 2011
Just having the same height on each child of the root is not enough to maintain a Θ(log n) height
for a binary tree.
We can define a balance condition, some set of rules about how the subtrees of a node can differ.
Maintaining a perfectly strict balance (minimum height for the given number of nodes) is often too
expensive. Maintaining too loose a balance can destroy the Θ(log n) behaviors that often motivate
the use of tree structures in the first place.
For a strict balance, we could require that all levels except the lowest are full.
How could we achieve this? Let’s think about it by inserting the values 1,2,3,4,5,6,7 into a BST
and seeing how we could maintain strict balance.
First, insert 1:
1
Next, insert 2:
1
2
We’re OK there. But when we insert 3:
1
2
3
we have violated our strict balance condition. Only one tree with these three values satisies the
condition:
4
5. CS 385 Analysis of Algorithms Spring 2011
2
/
1 3
We will see how to “rotate” the tree to achieve this shortly.
Now, add 4:
2
/
1 3
4
Then add 5:
2
/
1 3
4
5
Again, we need to fix the balance condition. Here, we can apply one of these rotations on the right
subtree of the root:
2
/
1 4
/
3 5
Now, add 6:
2
/
1 4
/
3 5
6
5
6. CS 385 Analysis of Algorithms Spring 2011
It’s not completely obvious how to fix this one up, and we won’t worry about it just now. We do
know that after we insert the 7, there’s only one permissible tree:
4
/
2 6
/ /
1 3 5 7
So maintaining strict balance can be very expensive. The tree adjustments can be more expensive
than the benefits.
There are several options to deal with potentially unbalanced trees without requiring a perfect
balance.
1. Red-black trees – nodes are colored red or black, and place restrictons on when red nodes
and black nodes can cluster.
2. AVL Trees - Adelson-Velskii and Landis developed these in 1962. We will look at these.
3. Splay trees – every reference to a node causes that node to be relocated to the root of the tree.
This is very unusual! We have a contains() operation that actually modifies the structure.
This works very well in cases where the same value or a small group of values are likely to
be accessed repeatedly.
We may talk more later about splay trees as well.
AVL Trees
We consider AVL Trees, developed by and named for Adelson-Velskii and Landis, who invented
them in 1962.
Balance condition: the heights of the left and right subtrees of any node can differ by at most 1.
To see that this is less strict than perfect balance, let’s consider two trees:
5
/
2 8
/ /
1 4 7
/
3
6
7. CS 385 Analysis of Algorithms Spring 2011
This one satisfies the AVL condition (to decide this, we check the heights at each node), but is not
perfectly balanced since we could store these 7 values in a tree of height 2.
But...
7
/
2 8
/
1 4
/
3 5
This one does not satisfy the AVL condition – the root node violates it!
So the goal is to maintain the AVL balance condition each time there is an insertion (we will ignore
deletions, but similar techniques apply).
When inserting into the tree, a node in the tree can become a violator of the AVL condition. Four
cases can arise which characterize how the condition came to be violated. Let’s call the violating
node A.
1. Insertion into the left subtree of the left child of A.
2. Insertion into the right subtree of the left child of A.
3. Insertion into the left subtree of the right child of A.
4. Insertion into the right subtree of the right child of A.
In reality, however, there are only two really different cases, since cases 1 and 4 and cases 2 and 3
are mirror images of each other and similar techniques apply.
First, we consider a violation of case 1.
We start with a tree that satisfies AVL:
k2
k1
Z
level n−1
X Y
level n
7
8. CS 385 Analysis of Algorithms Spring 2011
After an insert, the subtree X increases in height by 1:
k2
k1
Z
level n−1
Y
X level n
level n+1
So now node k2 violates the balance condition.
We want to perform a single rotation to obtain an equivalent tree that satisfies AVL.
Essentially, we want to switch the roles of k1 and k2 , resulting in this tree:
k1
k2
X Y Z
level n
For this insertion type (left subtree of a left child – case 1), this rotation has restored balance.
We can think of this like you have a handle for the subtree at the root and gravity determines the
tree.
If we switch the handle from k2 to k1 and let things fall where they want (in fact, must), we have
rebalanced.
Consider insertion of 3,2,1,4,5,6,7 into an originally empty tree.
Insert 3:
3
8
9. CS 385 Analysis of Algorithms Spring 2011
Insert 2:
3
/
2
Insert 1:
3 2
/ /
2 ---> 1 3
/
1
Here, we had to do a rotation. We essentially replaced the root of the violating subtree with the
root of the taller of its children.
Now, we insert 4:
2
/
1 3
4
Then insert 5:
2
/
1 3 <-- AVL violated here (case 4)
4
5
and we have to rotate at 3:
2
/
1 4
/
3 5
9
10. CS 385 Analysis of Algorithms Spring 2011
Now insert 6:
2 <-- AVL violated here (case 4)
/
1 4
/
3 5
6
Here, our rotation moves 4 to the root and everything else falls into place:
4
/
2 5
/
1 3 6
Finally, we insert 7:
4
/
2 5 <-- AVL violated here (case 4 again)
/
1 3 6
7
4
/
2 6
/ /
1 3 5 7
We achieve perfect balance in this case, but this is not guaranteed in general.
This example demonstrates the application of cases 1 and 4, but not cases 2 and 3.
Here’s case 2:
We start again with the good tree:
10
11. CS 385 Analysis of Algorithms Spring 2011
k2
k1
Z
level n−1
X Y
level n
But now, our inserted item ends up in subtree Y :
k2
k1
Z
level n−1
level n X
Y
level n+1
We can attempt a single rotation:
k1
k2
X
level n−1 Z
Y level n
level n+1
This didn’t get us anywhere. We need to be able to break up Y .
We know subtree Y is not empty, so let’s draw our tree as follows:
11
12. CS 385 Analysis of Algorithms Spring 2011
k3
k1
k2
D
A level n−1
level n B C
level n+1
Here, only one of B or C is at level n + 1, since it was a single insert below k2 that resulted in the
AVL condition being violated at k3 with respect to its shorter child D.
We are guaranteed to correct it by moving D down a level and both B and C up a level:
k2
k1 k3
A B C D
level n
We’re essentially rearranging k1 , k2 , and k3 to have k2 at the root, and dropping in the subtrees in
the only locations where they can fit.
In reality, only one of B and C is at level n – the other only descends to level n − 1.
Case 3 is the mirror image of this.
To see examples of this, let’s pick up the previous example, which had constructed a perfectly-
balanced tree of the values 1–7.
4
/
2 6
/ /
1 3 5 7
At this point, we insert a 16, then a 15 to get:
12
13. CS 385 Analysis of Algorithms Spring 2011
4
/
2 6
/ /
1 3 5 7
16
/
15
Node 7 violates AVL and this happened because of an insert into the left subtree of its right child.
Case 3.
So we let k1 be 7, k2 be 15, and k3 be 16 and rearrange them to have k2 at the root of the subtree,
with children k1 and k3 . Here, the subtrees A, B, C, and D are all empty.
We get:
4
/
2 6
/ /
1 3 5 15
/
7 16
Now insert 14.
4
/
2 6
/ /
1 3 5 15
/
7 16
14
This violates AVL at node 6 (one child of height 0, one of height 2).
This is again an instance of case 3: insertion into the left subtree of the right child of the violating
node.
So we let k1 be 6, k2 be 7, and k3 be 15 and rearrange them again. This time, subtrees A is the 5,
B is empty, C is the 14, and D is the 16.
13
14. CS 385 Analysis of Algorithms Spring 2011
The double rotation requires that 7 become the root of that subtree, the 6 and the 15 its children,
and the other subtrees fall into place:
4
/
2 7
/ /
1 3 6 15
/ /
5 14 16
Insert 13:
4
/
2 7
/ /
1 3 6 15
/ /
5 14 16
/
13
What do we have here? Looking up from the insert location, the first element that violates the
balance condition is the root, which has a difference of two between its left and right child heights.
Since this is an insert into the right subtree of the right child, we’re dealing with case 4. This
requires just a single rotation, but one done all the way at the root. We get:
7
/
4 15
/ /
2 6 14 16
/ / /
1 3 5 13
Now adding 12:
7
/
4 15
/ /
14
15. CS 385 Analysis of Algorithms Spring 2011
2 6 14 16
/ / /
1 3 5 13
/
12
The violation this time is at 14, which is a simple single rotation (case 1):
7
/
4 15
/ /
2 6 13 16
/ / /
1 3 5 12 14
Inserting 11:
7
/
4 15
/ /
2 6 13 16
/ / /
1 3 5 12 14
/
11
Here, we have a violation at 15, case 1, so another single rotation there, promoting 13:
7
/
4 13
/ /
2 6 12 15
/ / / /
1 3 5 11 14 16
(Almost done)
Insert 10:
15
16. CS 385 Analysis of Algorithms Spring 2011
7
/
4 13
/ /
2 6 12 15
/ / / /
1 3 5 11 14 16
/
10
The violator here is 12, case 1:
7
/
4 13
/ /
2 6 11 15
/ / / /
1 3 5 10 12 14 16
Then we finally add 8 (no rotations needed) then 9:
7
/
4 13
/ /
2 6 11 15
/ / / /
1 3 5 10 12 14 16
/
8
9
Finally we see case 2 and do a double rotation with 8, 9, and 10 to get our final tree:
7
/
4 13
/ /
2 6 11 15
/ / / /
1 3 5 9 12 14 16
/
8 10
16
17. CS 385 Analysis of Algorithms Spring 2011
This tree is not strictly balanced – we have a hole under 6’s right child, but it does satisfy AVL.
You can think about how we might implement an AVL tree, but we will not consider an actual
implementation. However, AVL insert operations make excellent exam questions, so keep that in
mind when preparing for the final.
The whole point of considering AVL trees is to maintain a reasonable balance, and hopefully, a
tree height that looks like log n. We will not do a detailed analysis, but the height n of an AVL tree
is guaranteed to satisfy the inequality:
⌊log2 n⌋ ≤ h < 1.44.05 log2 (n + 2) − 1.3277.
We have log factors on both sides, leading to Θ(log n) worst case behavior of search and insert
operations.
17