This document discusses various non-linear data structures including AVL trees, splay trees, B-trees, and red-black trees. It provides information on their properties, rotations, insertion, deletion, and search operations. AVL trees are self-balancing binary search trees that balance after each insertion or deletion. Splay trees dynamically balance trees by rotating nodes to the root after access. B-trees are balanced m-way search trees used for external storage, with nodes containing multiple sorted keys. Red-black trees are self-balancing binary search trees that use color attributes to balance rotations.
Search tree,Tree and binary tree and heap treezia eagle
This document contains definitions and explanations of search trees and heaps. It defines search trees as data structures used for locating specific keys within a set where each node's key must be greater than keys in its left subtree and less than keys in its right subtree. It provides examples of constructing and performing operations on binary search trees like insertion, searching, and deletion. It defines heaps as binary trees that follow the shape and order property, with max heaps having each node greater than its children and min heaps having each node less than its children. It explains representing heaps in arrays and operations like deleting and inserting elements through reheapifying.
Red-Black trees are self-balancing binary search trees where each node is colored red or black. This helps ensure the tree remains balanced during insertions and deletions, keeping operations like search at O(log n) time. Key properties include: (1) the root is black, (2) red nodes cannot have red children, and (3) all paths from root to leaf contain the same number of black nodes. Insertions add new nodes as red leaves then perform rotations and recolorings to maintain balance. Deletions similarly remove nodes and rebalance the tree through rotations and recolorings.
This document discusses different types of trees including binary search trees, AVL trees, B-trees, heap trees, and red-black trees. It focuses on explaining the properties and operations of B-trees and heap trees. B-trees are self-balancing search trees where each node can contain multiple keys and have multiple children. Heap trees are binary trees that store data based on max-heap or min-heap ordering properties, where insertion and deletion involve comparing nodes to their parents.
A binary search tree (BST) is a binary tree where the key in each internal node is greater than or equal to any key in its left subtree and less than the key in its right subtree. The document defines BSTs and describes their basic operations like searching, inserting, deleting, and traversing nodes. It provides algorithms for each operation, such as comparing the search key to the root node then recursively searching left or right subtrees, inserting new nodes at leaf locations, and traversing trees in pre-order, in-order, and post-order sequences.
Tree representations can be list-based or use left child and right sibling pointers. Binary search trees store values such that all left descendants are less than the node value and all right descendants are greater. Common operations on binary search trees are search, insertion, and deletion through comparing node values, replacing nodes, or restructuring subtrees.
This document describes binary trees, including their definition, applications, operations like insertion, deletion and traversal. Binary trees store data in nodes that can have up to two child nodes. Common operations include inserting nodes, searching for values, and traversing the tree in different orders like inorder, preorder and postorder. The document provides code examples for implementing a binary tree class including functions for these operations.
This document discusses various non-linear data structures including AVL trees, splay trees, B-trees, and red-black trees. It provides information on their properties, rotations, insertion, deletion, and search operations. AVL trees are self-balancing binary search trees that balance after each insertion or deletion. Splay trees dynamically balance trees by rotating nodes to the root after access. B-trees are balanced m-way search trees used for external storage, with nodes containing multiple sorted keys. Red-black trees are self-balancing binary search trees that use color attributes to balance rotations.
Search tree,Tree and binary tree and heap treezia eagle
This document contains definitions and explanations of search trees and heaps. It defines search trees as data structures used for locating specific keys within a set where each node's key must be greater than keys in its left subtree and less than keys in its right subtree. It provides examples of constructing and performing operations on binary search trees like insertion, searching, and deletion. It defines heaps as binary trees that follow the shape and order property, with max heaps having each node greater than its children and min heaps having each node less than its children. It explains representing heaps in arrays and operations like deleting and inserting elements through reheapifying.
Red-Black trees are self-balancing binary search trees where each node is colored red or black. This helps ensure the tree remains balanced during insertions and deletions, keeping operations like search at O(log n) time. Key properties include: (1) the root is black, (2) red nodes cannot have red children, and (3) all paths from root to leaf contain the same number of black nodes. Insertions add new nodes as red leaves then perform rotations and recolorings to maintain balance. Deletions similarly remove nodes and rebalance the tree through rotations and recolorings.
This document discusses different types of trees including binary search trees, AVL trees, B-trees, heap trees, and red-black trees. It focuses on explaining the properties and operations of B-trees and heap trees. B-trees are self-balancing search trees where each node can contain multiple keys and have multiple children. Heap trees are binary trees that store data based on max-heap or min-heap ordering properties, where insertion and deletion involve comparing nodes to their parents.
A binary search tree (BST) is a binary tree where the key in each internal node is greater than or equal to any key in its left subtree and less than the key in its right subtree. The document defines BSTs and describes their basic operations like searching, inserting, deleting, and traversing nodes. It provides algorithms for each operation, such as comparing the search key to the root node then recursively searching left or right subtrees, inserting new nodes at leaf locations, and traversing trees in pre-order, in-order, and post-order sequences.
Tree representations can be list-based or use left child and right sibling pointers. Binary search trees store values such that all left descendants are less than the node value and all right descendants are greater. Common operations on binary search trees are search, insertion, and deletion through comparing node values, replacing nodes, or restructuring subtrees.
This document describes binary trees, including their definition, applications, operations like insertion, deletion and traversal. Binary trees store data in nodes that can have up to two child nodes. Common operations include inserting nodes, searching for values, and traversing the tree in different orders like inorder, preorder and postorder. The document provides code examples for implementing a binary tree class including functions for these operations.
This document provides information about different tree data structures including binary trees, binary search trees, AVL trees, red-black trees, splay trees, and B-trees. Binary search trees allow for fast searching and maintain an ordered structure. AVL and red-black trees are self-balancing binary search trees that ensure fast search, insert, and delete times by keeping the tree balanced. B-trees are multiway search trees that allow for efficient storage and retrieval of data in databases and file systems.
The document discusses binary search trees and AVL trees. It defines binary search trees as binary trees where all left descendants of a node are less than or equal to the node and all right descendants are greater than or equal. Search, insertion and deletion operations in binary search trees have logarithmic time complexity. AVL trees are binary search trees where the heights of left and right subtrees differ by at most one, ensuring logarithmic time operations. The document outlines algorithms for insertion, deletion and balancing rotations in AVL trees.
introduction to binary tree , binary search tree, operations of binary search tree, insertion, deletions, search. 3 cases of deletions, graph tree of binary search tree, complaxcity, notations,algorithms, Data Analysis
Trees are fundamental data structures that combine advantages of ordered arrays and linked lists. They consist of nodes connected by edges, where nodes often represent entities and edges represent relationships between nodes. Common tree operations include traversing to visit all nodes in order, searching for a node by its key, and inserting or deleting nodes. These operations have O(log N) time complexity where N is the number of nodes. Binary trees restrict each node to at most two children while Huffman trees are used to compress data by assigning variable-length binary codes to characters based on their frequency.
Splay trees by NIKHIL ARORA (www.internetnotes.in)nikhilarora2211
Splay trees are self-adjusting binary search trees that improve access speed for frequently accessed nodes. They achieve this by moving recently accessed nodes closer to the root through rotations. The splay tree algorithm was developed in 1985 and offers logarithmic-time performance on average. It is well-suited for applications like network routing that see frequent repeats of certain data accesses. Splay trees perform surgery on the tree through six different rotation operations called splaying steps. The appropriate step depends on whether the node has a grandparent and its position relative to its parent and grandparent.
Red black trees are binary search trees where nodes are colored red or black. New nodes are always inserted as red nodes. The properties of red black trees, including that every path from root to leaf contains the same number of black nodes, must be maintained during insertion. If properties are violated after insertion, recoloring or a rotation followed by recoloring is performed to restore the properties and make the tree a valid red black tree again.
This document discusses different tree and graph data structures and algorithms. It begins by defining trees and their key properties like nodes, roots, parents, children, levels. It then discusses binary trees and their representations. Next, it covers binary search trees, their properties and operations like search, insert, delete. It also discusses different tree traversals. Finally, it discusses heaps, graphs and their representations and operations.
The document discusses data structures and algorithms related to trees. It begins by defining key terms related to trees such as root, parent, child, leaf, etc. It then discusses binary trees and binary search trees, including their representations, basic operations like search and insert, and algorithms for those operations. It also covers tree traversal methods like preorder, inorder and postorder traversal. Finally, it discusses heaps and Huffman coding.
Trees are hierarchical data structures used to represent data with parent-child relationships. A tree has a root node with child nodes, and each non-root node has one parent. Trees allow fast search, insertion, and deletion similar to linked lists but can also maintain ordering like arrays. Binary trees restrict nodes to at most two children, enabling efficient search, storage of expressions, and routing algorithms. Binary search trees organize nodes to enable fast lookups based on key values.
This PPT is all about the Tree basic on fundamentals of B and B+ Tree with it's Various (Search,Insert and Delete) Operations performed on it and their Examples...
Binary search trees organize data hierarchically, with each node having at most two children. The left child contains a value smaller than the parent and the right child contains a larger value. Searching is efficient as half of remaining nodes can be eliminated at each step by comparing the search value to the current node. Traversals such as inorder give elements in sorted order. Insertion and deletion are flexible but trees can become imbalanced affecting performance.
Binary search trees are binary trees where all left descendants of a node are less than the node's value and all right descendants are greater. This structure allows for efficient search, insertion, and deletion operations. The document provides definitions and examples of binary search tree properties and operations like creation, traversal, searching, insertion, deletion, and finding minimum and maximum values. Applications include dynamically maintaining a sorted dataset to enable efficient search, insertion, and deletion.
The document discusses tree data structures and binary trees. It introduces binary trees and their terminology like root, left and right subtrees, nodes, levels. It describes different types of binary trees like strictly binary trees, complete binary trees and operations on binary trees like insertion. It explains using a binary search tree to efficiently search for duplicates in a list by inserting elements in the tree and comparing search cost to linear data structures. Traversing methods like preorder, inorder and postorder are also mentioned.
The document discusses various methods for traversing binary trees, including pre-order, in-order, post-order, and level-order traversals. It also describes how to construct a binary tree from two traversal results, such as in-order and pre-order traversals. Key steps include using the pre-order sequence to identify the root node and using the in-order sequence to identify left and right subtrees.
In computer science, a tree is a widely used abstract data type (ADT)—or data structure implementing this ADT—that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node, represented as a set of linked nodes.
This document discusses binary trees and binary search trees. It defines key tree terms like root, child, parent, leaf nodes. It explains tree traversal methods like preorder, inorder and postorder. It also covers basic BST operations like insertion, search and deletion of nodes. Code snippets are provided to implement these operations and traversal methods on a sample binary search tree. Examples of traversing a sample tree in different orders are given.
Tree and graph data structures are used to represent hierarchical data. A tree has nodes connected by edges in a parent-child relationship where each node can have zero or more children but only one parent, forming a rooted tree. Common tree types include binary trees where each node has at most two children, binary search trees where the left child is less than the parent which is less than the right child, and B-trees where nodes can have multiple children. Trees are traversed using in-order, pre-order and post-order algorithms.
This document defines and explains various tree data structures, including binary trees and binary search trees. It begins by defining a tree as a non-linear hierarchical data structure and lists key tree terminology such as root, parent, child, leaf nodes, and levels. It then explains different types of binary trees like complete, full, skewed, and expression trees. Various tree traversal methods including preorder, inorder and postorder are also defined. Finally, it provides the definition of a binary search tree as a binary tree where all left descendants of a node are less than or equal to the node and all right descendants are greater than or equal.
This document discusses arrays and linked lists. It provides information on:
- What arrays and linked lists are and how they are used to store data in memory. Arrays use indexes to access data while linked lists use nodes connected through pointers.
- Common operations for each including insertion, deletion, and searching. For arrays this includes shifting elements, while for linked lists it involves manipulating the pointers between nodes.
- Specific implementation details for single linked lists, including defining node structures and performing operations at different points in the list.
This document provides information about different tree data structures including binary trees, binary search trees, AVL trees, red-black trees, splay trees, and B-trees. Binary search trees allow for fast searching and maintain an ordered structure. AVL and red-black trees are self-balancing binary search trees that ensure fast search, insert, and delete times by keeping the tree balanced. B-trees are multiway search trees that allow for efficient storage and retrieval of data in databases and file systems.
The document discusses binary search trees and AVL trees. It defines binary search trees as binary trees where all left descendants of a node are less than or equal to the node and all right descendants are greater than or equal. Search, insertion and deletion operations in binary search trees have logarithmic time complexity. AVL trees are binary search trees where the heights of left and right subtrees differ by at most one, ensuring logarithmic time operations. The document outlines algorithms for insertion, deletion and balancing rotations in AVL trees.
introduction to binary tree , binary search tree, operations of binary search tree, insertion, deletions, search. 3 cases of deletions, graph tree of binary search tree, complaxcity, notations,algorithms, Data Analysis
Trees are fundamental data structures that combine advantages of ordered arrays and linked lists. They consist of nodes connected by edges, where nodes often represent entities and edges represent relationships between nodes. Common tree operations include traversing to visit all nodes in order, searching for a node by its key, and inserting or deleting nodes. These operations have O(log N) time complexity where N is the number of nodes. Binary trees restrict each node to at most two children while Huffman trees are used to compress data by assigning variable-length binary codes to characters based on their frequency.
Splay trees by NIKHIL ARORA (www.internetnotes.in)nikhilarora2211
Splay trees are self-adjusting binary search trees that improve access speed for frequently accessed nodes. They achieve this by moving recently accessed nodes closer to the root through rotations. The splay tree algorithm was developed in 1985 and offers logarithmic-time performance on average. It is well-suited for applications like network routing that see frequent repeats of certain data accesses. Splay trees perform surgery on the tree through six different rotation operations called splaying steps. The appropriate step depends on whether the node has a grandparent and its position relative to its parent and grandparent.
Red black trees are binary search trees where nodes are colored red or black. New nodes are always inserted as red nodes. The properties of red black trees, including that every path from root to leaf contains the same number of black nodes, must be maintained during insertion. If properties are violated after insertion, recoloring or a rotation followed by recoloring is performed to restore the properties and make the tree a valid red black tree again.
This document discusses different tree and graph data structures and algorithms. It begins by defining trees and their key properties like nodes, roots, parents, children, levels. It then discusses binary trees and their representations. Next, it covers binary search trees, their properties and operations like search, insert, delete. It also discusses different tree traversals. Finally, it discusses heaps, graphs and their representations and operations.
The document discusses data structures and algorithms related to trees. It begins by defining key terms related to trees such as root, parent, child, leaf, etc. It then discusses binary trees and binary search trees, including their representations, basic operations like search and insert, and algorithms for those operations. It also covers tree traversal methods like preorder, inorder and postorder traversal. Finally, it discusses heaps and Huffman coding.
Trees are hierarchical data structures used to represent data with parent-child relationships. A tree has a root node with child nodes, and each non-root node has one parent. Trees allow fast search, insertion, and deletion similar to linked lists but can also maintain ordering like arrays. Binary trees restrict nodes to at most two children, enabling efficient search, storage of expressions, and routing algorithms. Binary search trees organize nodes to enable fast lookups based on key values.
This PPT is all about the Tree basic on fundamentals of B and B+ Tree with it's Various (Search,Insert and Delete) Operations performed on it and their Examples...
Binary search trees organize data hierarchically, with each node having at most two children. The left child contains a value smaller than the parent and the right child contains a larger value. Searching is efficient as half of remaining nodes can be eliminated at each step by comparing the search value to the current node. Traversals such as inorder give elements in sorted order. Insertion and deletion are flexible but trees can become imbalanced affecting performance.
Binary search trees are binary trees where all left descendants of a node are less than the node's value and all right descendants are greater. This structure allows for efficient search, insertion, and deletion operations. The document provides definitions and examples of binary search tree properties and operations like creation, traversal, searching, insertion, deletion, and finding minimum and maximum values. Applications include dynamically maintaining a sorted dataset to enable efficient search, insertion, and deletion.
The document discusses tree data structures and binary trees. It introduces binary trees and their terminology like root, left and right subtrees, nodes, levels. It describes different types of binary trees like strictly binary trees, complete binary trees and operations on binary trees like insertion. It explains using a binary search tree to efficiently search for duplicates in a list by inserting elements in the tree and comparing search cost to linear data structures. Traversing methods like preorder, inorder and postorder are also mentioned.
The document discusses various methods for traversing binary trees, including pre-order, in-order, post-order, and level-order traversals. It also describes how to construct a binary tree from two traversal results, such as in-order and pre-order traversals. Key steps include using the pre-order sequence to identify the root node and using the in-order sequence to identify left and right subtrees.
In computer science, a tree is a widely used abstract data type (ADT)—or data structure implementing this ADT—that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node, represented as a set of linked nodes.
This document discusses binary trees and binary search trees. It defines key tree terms like root, child, parent, leaf nodes. It explains tree traversal methods like preorder, inorder and postorder. It also covers basic BST operations like insertion, search and deletion of nodes. Code snippets are provided to implement these operations and traversal methods on a sample binary search tree. Examples of traversing a sample tree in different orders are given.
Tree and graph data structures are used to represent hierarchical data. A tree has nodes connected by edges in a parent-child relationship where each node can have zero or more children but only one parent, forming a rooted tree. Common tree types include binary trees where each node has at most two children, binary search trees where the left child is less than the parent which is less than the right child, and B-trees where nodes can have multiple children. Trees are traversed using in-order, pre-order and post-order algorithms.
This document defines and explains various tree data structures, including binary trees and binary search trees. It begins by defining a tree as a non-linear hierarchical data structure and lists key tree terminology such as root, parent, child, leaf nodes, and levels. It then explains different types of binary trees like complete, full, skewed, and expression trees. Various tree traversal methods including preorder, inorder and postorder are also defined. Finally, it provides the definition of a binary search tree as a binary tree where all left descendants of a node are less than or equal to the node and all right descendants are greater than or equal.
This document discusses arrays and linked lists. It provides information on:
- What arrays and linked lists are and how they are used to store data in memory. Arrays use indexes to access data while linked lists use nodes connected through pointers.
- Common operations for each including insertion, deletion, and searching. For arrays this includes shifting elements, while for linked lists it involves manipulating the pointers between nodes.
- Specific implementation details for single linked lists, including defining node structures and performing operations at different points in the list.
Similar to B Tree, Introduction ,example,Splay tree (20)
Build the Next Generation of Apps with the Einstein 1 Platform.
Rejoignez Philippe Ozil pour une session de workshops qui vous guidera à travers les détails de la plateforme Einstein 1, l'importance des données pour la création d'applications d'intelligence artificielle et les différents outils et technologies que Salesforce propose pour vous apporter tous les bénéfices de l'IA.
Open Channel Flow: fluid flow with a free surfaceIndrajeet sahu
Open Channel Flow: This topic focuses on fluid flow with a free surface, such as in rivers, canals, and drainage ditches. Key concepts include the classification of flow types (steady vs. unsteady, uniform vs. non-uniform), hydraulic radius, flow resistance, Manning's equation, critical flow conditions, and energy and momentum principles. It also covers flow measurement techniques, gradually varied flow analysis, and the design of open channels. Understanding these principles is vital for effective water resource management and engineering applications.
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELijaia
As digital technology becomes more deeply embedded in power systems, protecting the communication
networks of Smart Grids (SG) has emerged as a critical concern. Distributed Network Protocol 3 (DNP3)
represents a multi-tiered application layer protocol extensively utilized in Supervisory Control and Data
Acquisition (SCADA)-based smart grids to facilitate real-time data gathering and control functionalities.
Robust Intrusion Detection Systems (IDS) are necessary for early threat detection and mitigation because
of the interconnection of these networks, which makes them vulnerable to a variety of cyberattacks. To
solve this issue, this paper develops a hybrid Deep Learning (DL) model specifically designed for intrusion
detection in smart grids. The proposed approach is a combination of the Convolutional Neural Network
(CNN) and the Long-Short-Term Memory algorithms (LSTM). We employed a recent intrusion detection
dataset (DNP3), which focuses on unauthorized commands and Denial of Service (DoS) cyberattacks, to
train and test our model. The results of our experiments show that our CNN-LSTM method is much better
at finding smart grid intrusions than other deep learning algorithms used for classification. In addition,
our proposed approach improves accuracy, precision, recall, and F1 score, achieving a high detection
accuracy rate of 99.50%.
Blood finder application project report (1).pdfKamal Acharya
Blood Finder is an emergency time app where a user can search for the blood banks as
well as the registered blood donors around Mumbai. This application also provide an
opportunity for the user of this application to become a registered donor for this user have
to enroll for the donor request from the application itself. If the admin wish to make user
a registered donor, with some of the formalities with the organization it can be done.
Specialization of this application is that the user will not have to register on sign-in for
searching the blood banks and blood donors it can be just done by installing the
application to the mobile.
The purpose of making this application is to save the user’s time for searching blood of
needed blood group during the time of the emergency.
This is an android application developed in Java and XML with the connectivity of
SQLite database. This application will provide most of basic functionality required for an
emergency time application. All the details of Blood banks and Blood donors are stored
in the database i.e. SQLite.
This application allowed the user to get all the information regarding blood banks and
blood donors such as Name, Number, Address, Blood Group, rather than searching it on
the different websites and wasting the precious time. This application is effective and
user friendly.
Applications of artificial Intelligence in Mechanical Engineering.pdfAtif Razi
Historically, mechanical engineering has relied heavily on human expertise and empirical methods to solve complex problems. With the introduction of computer-aided design (CAD) and finite element analysis (FEA), the field took its first steps towards digitization. These tools allowed engineers to simulate and analyze mechanical systems with greater accuracy and efficiency. However, the sheer volume of data generated by modern engineering systems and the increasing complexity of these systems have necessitated more advanced analytical tools, paving the way for AI.
AI offers the capability to process vast amounts of data, identify patterns, and make predictions with a level of speed and accuracy unattainable by traditional methods. This has profound implications for mechanical engineering, enabling more efficient design processes, predictive maintenance strategies, and optimized manufacturing operations. AI-driven tools can learn from historical data, adapt to new information, and continuously improve their performance, making them invaluable in tackling the multifaceted challenges of modern mechanical engineering.
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...PriyankaKilaniya
Energy efficiency has been important since the latter part of the last century. The main object of this survey is to determine the energy efficiency knowledge among consumers. Two separate districts in Bangladesh are selected to conduct the survey on households and showrooms about the energy and seller also. The survey uses the data to find some regression equations from which it is easy to predict energy efficiency knowledge. The data is analyzed and calculated based on five important criteria. The initial target was to find some factors that help predict a person's energy efficiency knowledge. From the survey, it is found that the energy efficiency awareness among the people of our country is very low. Relationships between household energy use behaviors are estimated using a unique dataset of about 40 households and 20 showrooms in Bangladesh's Chapainawabganj and Bagerhat districts. Knowledge of energy consumption and energy efficiency technology options is found to be associated with household use of energy conservation practices. Household characteristics also influence household energy use behavior. Younger household cohorts are more likely to adopt energy-efficient technologies and energy conservation practices and place primary importance on energy saving for environmental reasons. Education also influences attitudes toward energy conservation in Bangladesh. Low-education households indicate they primarily save electricity for the environment while high-education households indicate they are motivated by environmental concerns.
Digital Twins Computer Networking Paper Presentation.pptxaryanpankaj78
A Digital Twin in computer networking is a virtual representation of a physical network, used to simulate, analyze, and optimize network performance and reliability. It leverages real-time data to enhance network management, predict issues, and improve decision-making processes.
Supermarket Management System Project Report.pdfKamal Acharya
Supermarket management is a stand-alone J2EE using Eclipse Juno program.
This project contains all the necessary required information about maintaining
the supermarket billing system.
The core idea of this project to minimize the paper work and centralize the
data. Here all the communication is taken in secure manner. That is, in this
application the information will be stored in client itself. For further security the
data base is stored in the back-end oracle and so no intruders can access it.
OOPS_Lab_Manual - programs using C++ programming language
B Tree, Introduction ,example,Splay tree
1. B - Trees
In a binary search tree, AVL Tree, Red-Black tree etc., every node can have only one value
(key) and maximum of two children but there is another type of search tree called B-Tree in
which a node can store more than one value (key) and it can have more than two children. B-
Tree was developed in the year of 1972 by Bayer and McCreight with the name Height
Balanced m-way Search Tree. Later it was named as B-Tree
B-Tree can be defined as follows...
B-Tree is a self-balanced search tree with multiple keys in every node and more than two
children for every node.
Here, number of keys in a node and number of children for a node is depend on the order of
the B-Tree. Every B-Tree has order.
B-Tree of Order m has the following properties...
• Property #1 - All the leaf nodes must be at same level.
• Property #2 - All nodes except root must have at least [m/2]-1 keys and maximum
of m-1 keys.
• Property #3 - All non leaf nodes except root (i.e. all internal nodes) must have at
least m/2 children.
• Property #4 - If the root node is a non leaf node, then it must have at least 2 children.
• Property #5 - A non leaf node with n-1 keys must have n number of children.
• Property #6 - All the key values within a node must be in Ascending Order.
For example, B-Tree of Order 4 contains maximum 3 key values in a node and maximum 4
children for a node.
2.
3. Operations on a B-Tree
The following operations are performed on a B-Tree...
• Search
• Insertion
• Deletion
Search Operation in B-Tree
• In a B-Ttree, the search operation is similar to that of Binary Search Tree. In a Binary
search tree, the search process starts from the root node and every time we make a 2-
way decision (we go to either left subtree or right subtree). In B-Tree also search
process starts from the root node but every time we make n-way decision where n is
the total number of children that node has. In a B-Ttree, the search operation is
performed with O(log n) time complexity. The search operation is performed as
follows...
Step 1: Read the search element from the user
• Step 2: Compare, the search element with first key value of root node in the tree.
• Step 3: If both are matching, then display "Given node found!!!" and terminate the
function
• Step 4: If both are not matching, then check whether search element is smaller or
larger than that key value.
• Step 5: If search element is smaller, then continue the search process in left subtree
Step 6: If search element is larger, then compare with next key value in the same node
and repeate step 3, 4, 5 and 6 until we found exact match or comparision completed
with last key value in a leaf node.
• Step 7: If we completed with last key value in a leaf node, then display "Element is not
found" and terminate the function.
Insertion Operation in B-Tree
In a B-Tree, the new element must be added only at leaf node. That means, always the new
keyValue is attached to leaf node only. The insertion operation is performed as follows...
• Step 1: Check whether tree is Empty.
• Step 2: If tree is Empty, then create a new node with new key value and insert into the
tree as a root node.
4. • Step 3: If tree is Not Empty, then find a leaf node to which the new key value cab be
added using Binary Search Tree logic.
• Step 4: If that leaf node has an empty position, then add the new key value to that leaf
node by maintaining ascending order of key value within the node.
• Step 5: If that leaf node is already full, then split that leaf node by sending middle
value to its parent node. Repeat tha same until sending value is fixed into a node.
• Step 6: If the spilting is occuring to the root node, then the middle value becomes new
root node for the tree and the height of the tree is increased by one
Construct a B-Tree of Order 3 by inserting numbers from 1 to 10.
5.
6.
7.
8. Splay Tree
• Splay tree is another variant of binary search tree. In a splay tree, the recently accessed
element is placed at the root of the tree. A splay tree is defined as follows...
• Splay Tree is a self - adjusted Binary Search Tree in which every operation on an
element rearrange the tree so that the element is placed at the root position of the tree.
• In a splay tree, every operation is performed at root of the tree. All the operations on a
splay tree are involved with a common operation called "Splaying".
• Splaying an element is the process of bringing it to the root position by performing
suitable rotation operations.
• In a splay tree, splaying an element rearrange all the elements in the tree so that
splayed element is placed at root of the tree.
With the help of splaying an element we can bring most frequently used element closer to the
root of the tree so that any operation on those element performed quickly. That means the
splaying operation automatically brings more frequently used elements closer to the root of
the tree.
Every operation on a splay tree performs the splaying operation. For example, the insertion
operation first inserts the new element as it inserted into the binary search tree, after insertion
the newly inserted element is splayed so that it is placed at root of the tree. The search
operation in a splay tree is search the element using binary search process then splay the
searched element so that it placed at the root of the tree.
In a splay tree, to splay any element we use the following rotation operations...
Rotations in Splay Tree
1. Zig Rotation
2. Zag Rotation
3. Zig - Zig Rotation
4. Zag - Zag Rotation
5. Zig - Zag Rotation
6. Zag - Zig Rotation
9. Zig Rotation
The Zig Rotation in a splay tree is similar to the single right rotation in AVL Tree rotations.
In zig rotation every node moves one position to the right from its current position. Consider
the following example..
Zag Rotation
The Zag Rotation in a splay tree is similar to the single left rotation in AVL Tree rotations. In
zag rotation every node moves one position to the left from its current position. Consider the
following example..
Zig-Zig Rotation
The Zig-Zig Rotation in a splay tree is a double zig rotation. In zig-zig rotation every node
moves two position to the right from its current position. Consider the following example...
10. Zag-Zag Rotation
The Zag-Zag Rotation in a splay tree is a double zag rotation. In zag-zag rotation every node
moves two position to the left from its current position. Consider the following example...
Zig-Zag Rotation
The Zig-Zag Rotation in a splay tree is a sequence of zig rotation followed by zag rotation. In
zig-zag rotation every node moves one position to the right followed by one position to the
left from its current position. Consider the following example..
11. The Zag-Zig Rotation in a splay tree is a sequence of zag rotation followed by zig rotation. In
zag-zig rotation every node moves one position to the left followed by one position to the
right from its current position. Consider the following example...
Note
Every Splay tree must be a binary search tree but it is need not to be balanced tree.
Insertion Operation in Splay Tree
The insertion operation in Splay tree is performed using following steps...
• Step 1: Check whether tree is Empty.
• Step 2: If tree is Empty then insert the newNode as Root node and exit from the
operation.
• Step 3: If tree is not Empty then insert the newNode as a leaf node using Binary Search
tree insertion logic.
• Step 4: After insertion, Splay the newNode
Deletion Operation in Splay Tree
In a Splay Tree, the deletion operation is similar to deletion operation in Binary Search Tree.
But before deleting the element first we need to splay that node then delete it from the root
position then join the remaining tree.
12. Red-Black Trees
• Red - Black Tree is another variant of Binary Search Tree in which every node is
colored either RED or BLACK. We can define a Red Black Tree as follows...
• Red Black Tree is a Binary Search Tree in which every node is colored eigther RED
or BLACK.
• In a Red Black Tree the color of a node is decided based on the Red Black Tree
properties. Every Red Black Tree has the following properties.
Properties of Red Black Tree
• Property #1: Red - Black Tree must be a Binary Search Tree.
• Property #2: The ROOT node must colored BLACK.
• Property #3: The children of Red colored node must colored BLACK. (There should
not be two consecutive RED nodes).
• Property #4: In all the paths of the tree there must be same number of BLACK colored
nodes.
• Property #5: Every new node must inserted with RED color.
• Property #6: Every leaf (e.i. NULL node) must colored BLACK.
Example
The following is a Red Black Tree which created by inserting numbers from 1 to 9.
The above tree is a Red Black tree and every node is satisfying all the properties of Red Black
Tree.
13. Every Red Black Tree is a binary search tree but all the Binary Search Trees need not to be
Red Black trees.
Insertion into RED BLACK Tree:
• In a Red Black Tree, every new node must be inserted with color RED.
• The insertion operation in Red Black Tree is similar to insertion operation in Binary
Search Tree. But it is inserted with a color property.
After every insertion operation, we need to check all the properties of Red Black Tree.
If all the properties are satisfied then we go to next operation otherwise we need to
perform following operation to make it Red Black Tree.
o Recolor
o Rotation followed by Recolor
The insertion operation in Red Black tree is performed using following steps...
• Step 1: Check whether tree is Empty.
• Step 2: If tree is Empty then insert the newNode as Root node with color Black and
exit from the operation.
• step 3: If tree is not Empty then insert the newNode as a leaf node with Red color.
• Step 4: If the parent of newNode is Black then exit from the operation.
• Step 5: If the parent of newNode is Red then check the color of parent node's sibling of
newNode.
• Step 6: If it is Black or NULL node then make a suitable Rotation and Recolor it.
• Step 7: If it is Red colored node then perform Recolor and Recheck it. Repeat the same
until tree becomes Red Black Tree.
14.
15.
16.
17.
18. Deletion Operation in Red Black Tree
In a Red Black Tree, the deletion operation is similar to deletion operation in BST. But after
every deletion operation we need to check with the Red Black Tree properties. If any of the
property is violated then make suitable operation like Recolor or Rotation & Recolor.