The Red Black Tree is one of the most popular implementation of sets and dictionaries. A red-black tree is a binary search tree in which each node is coloured red or black.
Decision Tree Algorithm | Decision Tree in Python | Machine Learning Algorith...Edureka!
** Machine Learning with Python : https://www.edureka.co/machine-learning-certification-training **
This Edureka tutorial on Decision Tree Algorithm in Python will take you through the fundamentals of decision tree machine learning algorithm concepts and its demo in Python. Below are the topics covered in this tutorial:
1. What is Classification?
2. Types of Classification
3. Classification Use Case
4. What is Decision Tree?
5. Decision Tree Terminology
6. Visualizing a Decision Tree
7 Writing a Decision Tree Classifier fro Scratch in Python using CART Algorithm
Check out our Python Machine Learning Playlist: https://goo.gl/UxjTxm
Decision Tree Algorithm | Decision Tree in Python | Machine Learning Algorith...Edureka!
** Machine Learning with Python : https://www.edureka.co/machine-learning-certification-training **
This Edureka tutorial on Decision Tree Algorithm in Python will take you through the fundamentals of decision tree machine learning algorithm concepts and its demo in Python. Below are the topics covered in this tutorial:
1. What is Classification?
2. Types of Classification
3. Classification Use Case
4. What is Decision Tree?
5. Decision Tree Terminology
6. Visualizing a Decision Tree
7 Writing a Decision Tree Classifier fro Scratch in Python using CART Algorithm
Check out our Python Machine Learning Playlist: https://goo.gl/UxjTxm
Homogeneous function is one with multiplicative scaling behaviour - if all its arguments are multiplied by a factor, then its value is multiplied by some power of this factor.
Factor analysis is a technique that is used to reduce a large number of variables into fewer numbers of factors. This technique extracts maximum common variance from all variables and puts them into a common score.
AVL tree Named after their inventor Adelson, Velski & Landis, is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for all nodes.
Maxima and Minima of Functions of Two Independent Variables.
As the name suggests, this topic is devoted to the method of finding the maximum and the minimum values of a function in a given domain.
Engineering mathematics is a branch of applied mathematics concerning mathematical methods and techniques that are typically used in engineering.
At http://www.isquareit.edu.in/ we hope you will be able to explore your full potential as a student and eventually make a remarkable mark in your professional life.
Adapter pattern works as a bridge between two incompatible interfaces. This type of design pattern comes under structural pattern as this pattern combines the capability of two independent interfaces.
The theory of computation is a branch of computer science and mathematics combined. It deals with how efficiently problems can be solved on a model of computation, using an algorithm.
The main idea of fusion is to combine a set of models each of which solves the same original task in order to obtain a better model with more accuracy.
Lex is officially known as a "Lexical Analyser". It's main job is to break up an input stream into more usable elements.
Yacc is officially known as a "parser". In the course of it's normal work, the parser also verifies that the input is syntactically sound.
All these acronyms are often loosely used in the field of technology. It is important to understand that all these acronyms are part of Artificial Intelligence (AI) umbrella.
The process of reducing a given DFA to its minimal form is called as minimization of DFA. DFA minimization is also called as Optimization of DFA and uses partitioning algorithm.
NLP is a tool for computers to analyse, comprehend, and derive meaning from natural language in an intelligent and useful way. Natural language processing helps computers communicate with humans in their own language and scales other language-related tasks.
Smart computing, next-generation computing, is a combination of hardware, software, and network to provide real-time awareness of real-time systems. The real world gets smart by connecting it to a computer, and computer get smart by connecting to the real world.
As a student, you should be developing work ethic and etiquette skill sets to prepare you for the work environment. Developing professional habits and manners is more important now than ever before.
Writing skills include all the knowledge and abilities related to expressing yourself through the written word. Here you can find activities to practise your writing skills.
Professional communication in written form requires skill and expertise. And whether you're starting a new job, introducing yourself at a networking event or pitching for new work, here are some things to consider ...
Servlets work on the server-side. Servlets are capable of handling complex requests obtained from the web-server. There are many (competing) server-side technologies available: Java-based (servlet, JSP, JSF, Struts, Spring, Hibernate), ASP, PHP, CGI Script, and many others.
Jenkin is an open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.
Data science, Know as data-driven science, is also an interdisciplinary field of scientific methods, processes, algorithms, and systems to extract knowledge or insights from data in various forms, either structured or unstructured, similar to data mining.
Sentiment Analysis has become a hot-trend topic of scientific and market research; it is a natural language processing technique used to determine whether data is positive, negative or neutral.
The popular object-oriented languages are Java, C#, PHP, Python, C++, etc. The main aim of object-oriented programming is to implement real-world entities.
High speed computing was implemented in supercomputer for scientific research. HPC clusters provide the most efficient, flexible, cost effective computing environments for HPC simulations.
Power BI is a business analytics service by Microsoft. BI
Microsoft Power BI is a suite of business intelligence (BI), reporting, and data visualization products and services for individuals and teams. You can access your data from anywhere with the Power BI app.
Yoga — a mind-body practice — is considered one of many types of complementary and integrative health approaches. Yoga brings together physical and mental disciplines that may help you achieve peacefulness of body and mind.
LR parsing is one type of bottom up parsing. In the LR parsing, "L" stands for left-to-right scanning of the input.
"R" stands for constructing a right most derivation in reverse.
Lex is called as lexical analyzer, it is a first phase of compiler design.
YACC is a parser generator that takes an input file with an attribute-enriched BNF grammar specification.
More from International Institute of Information Technology (I²IT) (20)
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.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
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.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
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
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.
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.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Red Black Tree Insertion & Deletion
1. Red Black Tree
Prof. Keshav Tambre
Assistant Professor
Department of Information Technology
Hope Foundation’s
International Institute of Information
Technology, I²IT
www.isquareit.edu.in
2. Insertion Example
Insert 65
47
7132
93
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
3. Insertion Example
Insert 65
47
7132
65 93
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
4. Insertion Example
Insert 65
47
7132
65 93
Insert 82
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
5. 82
Insertion Example
Insert 65
47
7132
65 93
Insert 82
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
6. 82
Insertion Example
Insert 65
47
7132
65 93
Insert 82
65
71
93
change nodes’ colors
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
7. 65 93
71
82
Insertion Example
Insert 65
47
32
Insert 82
Insert 87
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
8. 9365
71
82
Insertion Example
Insert 65
47
32
Insert 82
Insert 87
87
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
9. 9365
71
82
Insertion Example
Insert 65
47
32
Insert 82
Insert 87
87
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
10. 9365
71
87
Insertion ExampleInsert 65
47
32
Insert 82
Insert 87
82
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
11. 9365
87
Insertion Example
Insert 65 47
32
Insert 82
Insert 87
82
71
87
93
change nodes’ colors
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
12. 87
93
65
Insertion Example
Insert 65
47
32
Insert 82
Insert 87
82
71
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
13. Left Rotation:
Modified algorithm
TreeNode<T> leftRotate(TreeNode<T> root,TreeNode<T> x)
//returns a new root; Pre: right child of x is a proper node (with value)
{
TreeNode<T> z = x.getRight();
x.setRight(z.getLeft());
// Set parent reference
if (z.getLeft() != null)
z.getLeft().setParent(x);
z.setLeft(x); //move x down
z.setParent(x.getParent());
// Set parent reference of x
if (x.getParent() != null) //x is not the root
if (x == x.getParent().getLeft()) //left child
x.getParent().setLeft(z);
else
x.getParent().setRight(z);
else
root=z;
x.setParent(z);
return root;
}
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
14. RB Tree: Insertion Algorithm
TreeNode<T> rbInsert(TreeNode<T> root,TreeNode<T> x)
// returns a new root
{
root=bstInsert(root,x); // a modification of BST insertItem
x.setColor(red);
while (x != root and x.getParent().getColor() == red) {
if (x.getParent() == x.getParent().getParent().getLeft()) {
//parent is left child
y = x.getParent().getParent().getRight() //uncle of x
if (y.getColor() == red) {// uncle is red
x.getParent().setColor(black);
y.setColor(black);
x.getParent().getParent().setColor(red);
x = x.getParent().getParent();
} else { // uncle is black
// ................
}
} else
// ... symmetric to if
} // end while
root.setColor(black);
return root;
}
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
15. x
p
left_rotateonp
right_rotate on p^2[x]
x
p
left_rotateonp
right_rotate on p^2[x]
RB Tree: Insertion AlgorithmTreeNode<T> rbInsert(TreeNode<T> root,TreeNode<T> newNode)
// returns a new root
{
root=bstInsert(root,newNode); // a modification of BST insertItem
x.setColor(red);
while (x != root and x.getParent().getColor() == red) {
if (x.getParent() == x.getParent().getParent().getLeft()) {
//parent is left
y = x.getParent().getParent().getRight() //uncle of x
if (y.getColor() == red) {// uncle is red
// ................
} else { // uncle is black
if (x == x.getParent().getRight()) {
x = x.getParent();
root = left_rotate(root,x);
}
x.getParent().setColor(black);
x.getParent().getParent().setColor(red);
root = right_rotate(root,x.getParent().getParent());
}
} else
// ... symmetric to if
} // end while
root.setColor(black);
return root;
}
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
16. Red-black Tree Deletion
First use the standard BST tree deletion algorithm
If the node to be deleted is replaced by its
successor/predecessor (if it has two non-null children), consider
the deleted node’s data as being replaced by it’s
successor/predecessor's, and its color remaining the same
The successor/predecessor node is then removed
Let y be the node to be removed
If the removed node was red, no property could get violated, so
just remove it.
Otherwise, remove it and call the tree-fix algorithm on y’s child x
(the node which replaced the position of y)
Remember, the removed node can have at most one real (non-null)
child
If it has one real child, call the tree-fix algorithm on it
If it has no real children (both children are null), Note that this child
may be a (black) pretend (null) child
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
17. Fixing a red-black Tree
The tree-fix algorithm considers the parameter (x)
as having an “extra” black token
This corrects the violation of property 4 caused by
removing a black node
If x is red, just color it black
But if x is black then it becomes “doubly black”
This is a violation of property 1
The extra black token is pushed up the tree until
a red node is reached, when it is made black
the root node is reached or
it can be removed by rotating and recoloring
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
18. 87
93
65
Deletion Example 1
Delete 87
47
32
82
71
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
19. 87
93
65
Deletion Example 1
Delete 87
47
32
82
71
Replace data with predecessor
Predecessor red: no violation
82
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
20. 87
93
65
Deletion Example 2
Delete 71
47
32
82
71
51
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
21. 87
93
65
Deletion Example 2
Delete 71
47
32
82
71
51
Replace with predecessor
65
Attach predecessor’s child
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
22. 65
87
93
Deletion Example 2
Delete 71
47
32
8251
Replace with predecessor
Fix tree by coloring
predecessor’s child black
51
Attach predecessor’s child
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
23. 87
93
65
Deletion Example 3
Delete 32
47
32
82
71
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
24. 87
93
65
Deletion Example 3
Delete 32
47
32
82
71
x
Identify x – the removed
node’s left child
Attach x to parent of target
Remove target node
x
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
25. 87
93
65
Deletion Example 3
Delete 32
47
82
71x
Identify x – the removed
node’s left child
Call rbTreeFix on x
Attach x to parent of target
Remove target node
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
26. RB Tree Deletion Algorithm
TreeNode<T> rbDelete(TreeNode<T> root,TreeNode<T> z)
//return new root, z contains item to be deleted
{
TreeNode<T> x,y;
// find node y, which is going to be removed
if (z.getLeft() == null || z.getRight() == null)
y = z;
else {
y = successor(z); // or predecessor
z.setItem(y.getItem); // move data from y to z
}
// find child x of y
if (y.getRight() != null)
x = y.getRight();
else
x = y.getLeft();
// Note x might be null; create a pretend node
if (x == null) {
x = new TreeNode<T>(null);
x.setColor(black);
}
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
27. RB Tree Deletion Algorithm
x.setParent(y.getParent()); // detach x from y
if (y.getParent() == null)
// if y was the root, x is a new root
root = x;
else
// Atttach x to y’s parent
if (y == y.getParent().getLeft()) // left child
y.getParent().setLeft(x);
else
y.getParent().setRight(x);
if (y.getColor() == black)
root=rbTreeFix(root,x);
if (x.getItem() == null) // x is a pretend node
if (x==x.getParent().getLeft())
x.getParent().setLeft(null);
else
x.getParent().setRight(null);
return root;
}
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
28. Make y black and y’s parent
red
87
93
65
Deletion Example 3
(continued)
After deleting 32,
x is a node with
black token
47
82
71x
y
71
47
Identify y, x’s sibling
Left rotate x’s parent
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
29. Identify y, x’s sibling
9382
71
8747
Deletion Example 3
x
y
65
new y
Identify y – x’s new sibling
Make y black and
y’s parent red
Left rotate x’s parent
After deleting 32,
x is a node with
black token
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
30. Identify y – x’s new sibling
9382
71
8747
Deletion Example 3
x
65
y
65
new x
47
Identify y, x’s sibling
Make y black and
y’s parent red
Left rotate x’s parent
Color y red
Assign x it’s parent, and color it black
After deleting 32,
x is a node with
black token
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
31. Tree Fix algorithm cases: case (1)
x is red
The simplest case
x has a black token and is colored red, so just
color it black and remove token a we are
done!
In the remaining cases, assume x is black
(and has the black token, i.e., it’s double
black)
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
32. Tree Fix algorithm cases: case (2)
x’s sibling is red
Remarks:
the roots of subtrees C and D are black
the second is the symmetric case, when x is the right child
in the next step (case (3) or (4)) the algorithm will finish!
Left_rotate(y)
Right_rotate(y)
Colors of y and z
were swapped
Colors of x and y
were swapped
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
33. Tree Fix algorithm cases: case (3)
x’s sibling is black and both nephews are black
Remarks:
nephews are roots of subtrees C and D
the black token is passed one level up
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
34. Tree Fix algorithm cases: case (4)
x’s sibling is black and at least one nephew is red
Remarks:
in this case, the black token is removed completely
if the “far” nephew is black (subcase (i)), rotate its parent, so that
a new “far” nephew is red; otherwise start in subcase(ii)
Left_rotate(x)
Left_rotate(y)Right_rotate(w)
Right_rotate(z)
Colors of z and w
were swapped
Colors of x and y
were swapped
Colors of y and z
were swapped.
Far nephew is
colored black and
black token is removed.
Colors of z and y
were swapped.
Far nephew is
colored black and
black token is removed.
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
35. Left_rotate(y)
Right_rotate(y)
Colors of y and z
were swapped
Colors of x and y
were swapped
Left_rotate(y)
Right_rotate(y)
Colors of y and z
were swapped
Colors of x and y
were swapped
Left_rotate(y)
Right_rotate(y)
Colors of y and z
were swapped
Colors of x and y
were swapped
Tree Fix Algorithm
TreeNode<T> rbTreeFix(TreeNode<T> root,TreeNode<T> x)
//return new root; x is a node with the black token
{
while (x != root && x.getColor() == black) // not case (1)
if (x == x.getParent().getLeft()) { // x is left child
y = x.getParent().getRight(); // y is x’s sibling
if (y.getColor() == red) { // case (2)
y.setColor(black);
x.getParent().setColor(red); // p was black
root = left_rotate(root,x.getParent());
y = x.getParent().getRight(); // new sibling
}
if (y.getLeft().getColor() == black &&
y.getRight().getColor() == black) {
// nephews are black - case (3)
y.setColor(red);
x = x.getParent();
} else { // case (4)
// ..........
}
} else {
… // x is right child - symmetric
}
// end while loop
x.setColor(black);
return root;
} Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
36. Tree Fix Algorithm (continued)
} else { // case (4)
if (y.getRight().getColor() == black) {
// subcase (i)
y.getLeft().setColor(black);
y.setColor(red);
root = right_rotate(root,y);
y = x.getParent().getRight();
}
// subcase (ii)
y.setColor(x.getParent().getColor());
x.getParent().setColor(black);
y.getRight().setColor(black);
root = left_rotate(root, x.getParent());
x = root; // we can finish
}
Left_rotate(x)
Left_rotate(y)Right_rotate(w)
Right_rotate(z)
Colors of z and w
were swapped
Colors of z and y
were swapped.
Left_rotate(x)
Left_rotate(y)Right_rotate(w)
Right_rotate(z)
Colors of z and w
were swapped
Colors of z and y
were swapped.
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
37. RB Trees efficiency
All operations work in time O(height)
and we have proved that heigh is O(log n)
hence, all operations work in time O(log n)! – much more
efficient than linked list or arrays implementation of sorted list!
Sorted List Search Insertion Deletion
with arrays O(log n) O(n) O(n)
with linked list O(n) O(n) O(n)
with RB trees O(log n) O(log n) O(log n)
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
38. THANK YOU
For further details, please contact
Keshav Tambre
keshavt@isquareit.edu.in
Department of Information Technology
Hope Foundation’s
International Institute of Information Technology, I²IT
P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057
Tel - +91 20 22933441/2/3
www.isquareit.edu.in | info@isquareit.edu.in