Sie sind auf Seite 1von 6

Data Structures and Algorithms Analysis

1 _________________ Data Structures and Algorithms Analysis


3 __________________
___________________ ___________________
Types of Binary Search Trees Red-Black Tree
___________________ ___________________
Balanced tree - equal items on each subtree of a special type of BST that organizes pieces of
node to minimize the maximum path from the
root to any leaf node
___________________ comparable data such as numbers
two characteristics that this tree comprises
___________________
Height-balanced - left and right subtree
height of each node is within 1 ___________________

The nodes are colored
During insertion and deletion, rules are
followed that preserve various
___________________
___________________ arrangements of these colors
Red-Black Rules
___________________
Unbalanced tree - root has more left
___________________

Every node is red or black.
The root is always black. ___________________
If a node is red, its children must be
descendants than its right descendants or vice-
versa ___________________
black.
Both children of every red node are
___________________
Self-balancing tree - attempt to keep its
height, the number of levels of nodes
___________________
black.
Every path from the root to a leaf, or to
a null child, must contain the same
___________________
underneath the root, as small as possible
___________________ number of black nodes.
things should be done when tree is not
___________________
balanced or the color rules are violated
Tree rotation - changes the structure of the
tree without intervening any element in the
tree especially its order
___________________

Change the colors of the nodes
Perform rotations
___________________
Binary Search Tree Types *Property of STI
Page 1 of 24
___________________ Binary Search Tree Types *Property of STI
Page 3 of 24
___________________

Data Structures and Algorithms Analysis


2 _________________ Data Structures and Algorithms Analysis
4 __________________
___________________ ___________________
AVL Tree Red-Black Tree
___________________ ___________________
named after G.M. Adelso-Velsky and E.M.
Landis
can also be called as height balanced
___________________ Rotations are designed to: ___________________
Raise some nodes and lower others to help
Balance factor - done by right subtree less the
height of its left subtree ___________________ balance the tree
Ensure that the characteristics of a binary
___________________
Insertion - as it is inserting in an unbalanced
BST and retraces the ones steps toward the
root
___________________ search tree are not violated
To maintain the properties of red-black trees
when inserting a node
___________________
Deletion same with BST
Search - no provisions will be taken and will not ___________________ Enter a new element on a tree as a red leaf
node
___________________
change the structure of the tree

an AVL tree because it


___________________


Maintain the root as a black node
When moving down the path to look on
where to insert, update the colors of the
___________________
shows that each left
subtree has a height of 1
greater than each right
___________________ nodes when you find a black parent with two
red children ___________________
Inserting a node at the bottom may result in

not an AVL tree for the


subtree
___________________ two successive red nodes; employ rotation
to reorder the coloring of the tree
___________________
subtree of E has the
height of 4 and the
subtree of I has the
___________________ ___________________
height of 2
Binary Search Tree Types *Property of STI
Page 2 of 24
___________________ Binary Search Tree Types *Property of STI
Page 4 of 24
___________________
Data Structures and Algorithms Analysis
5 _________________ Data Structures and Algorithms Analysis
7 __________________
___________________ ___________________
Splay Trees 2-3-4 Trees
___________________ ___________________
elements in the tree that have been accessed
recently can be accessed very quickly
___________________ ___________________
invented by Daniel Sleator and Robert Tarjan
it performs an operation called splaying also
___________________ ___________________
know as rotation
___________________ Multiway tree - allowing having more data
___________________
Advantages:
Faster performance

Easier implementation
___________________ items and children per node
2-3-4 tree a multiway tree that can have up to
___________________
4 children and 3 data items per node
Efficient with identical keys
___________________ Possible arrangement for non-leaf nodes
A node with one data item always has two
___________________
___________________ children
A node with two data items always has
___________________
three children
___________________ A node with three data items always has
four children
___________________
___________________ ___________________
Binary Search Tree Types *Property of STI
Page 5 of 24
___________________ Binary Search Tree Types *Property of STI
Page 7 of 24
___________________

Data Structures and Algorithms Analysis


6 _________________ Data Structures and Algorithms Analysis
8 __________________
___________________ ___________________
Splay Trees 2-3-4 Trees
Three splay steps:
___________________ ___________________
Zig step
___________________ ___________________
___________________ ___________________
Zig-zig step
___________________ ___________________
___________________ ___________________
___________________ ___________________
Zig-zag step
___________________ ___________________
___________________ ___________________
___________________ ___________________
Binary Search Tree Types *Property of STI
Page 6 of 24
___________________ Binary Search Tree Types *Property of STI
Page 8 of 24
___________________
Data Structures and Algorithms Analysis
9 _________________ Data Structures and Algorithms Analysis
11 _________________
___________________ ___________________
2-3-4 Trees 2-3-4 Trees
___________________ Insert operations
___________________
Principle ___________________ ___________________
All children in the subtree rooted at child 0
have key values less than key 0
All children in the subtree rooted at child 1
___________________ ___________________
have key values greater than 0 but less than
key 2
All children in the subtree rooted at child 2
___________________ ___________________
have key values greater than key 1 but less
than key 2 ___________________ ___________________
All children in the subtree rooted at child 3
have key values greater than key 2
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
Binary Search Tree Types *Property of STI
Page 9 of 24
___________________ Binary Search Tree Types *Property of STI
Page 11 of 24
___________________

Data Structures and Algorithms Analysis


10 ________________ Data Structures and Algorithms Analysis
12 _________________
___________________ ___________________
2-3-4 Trees 2-3-4 Trees
___________________ ___________________
Splitting a node
Find key value 64 ___________________ A new, empty node is created. Its a sibling
of the node being split, and is placed to its
___________________
___________________ right.
Data item C is moved into a new node. ___________________
Data item B is moved into the parent of the

___________________ node being split.


Data item A remains where it is.
___________________
___________________ The rightmost two children are disconnected
from the node being split and connected to
the new node
___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
Binary Search Tree Types *Property of STI
Page 10 of 24
___________________ Binary Search Tree Types *Property of STI
Page 12 of 24
___________________
Data Structures and Algorithms Analysis
13 ________________ Data Structures and Algorithms Analysis
15 _________________
___________________ ___________________
2-3-4 Trees B-Trees
___________________ ___________________
___________________ B balanced, Boieng, Bayer ___________________
keeps data in a sorted order
___________________ Database and file systems applications that
uses this data structure
___________________
___________________ require that all leaf nodes are at the same depth
Search, insert, delete are operations that can be ___________________
performed
___________________ overflowed - adding on a full leaf node
To make nodes in order:
___________________
Split a root
A new node is created that becomes the new
root and the parent of the node being split.
___________________ Half the leaf node making it the left child

Pick the middle and place it on the root


___________________
A second new node is created that becomes a
sibling of the node being split. ___________________ Create a new node placing the remaining
values ___________________
Data item C is moved into the new sibling.

Data item B is moved into the new root.

Data item A remains where it is.


___________________ ___________________
The two rightmost children of the node being
split are disconnected from it and connected to
the new righthand node.
___________________ ___________________
Binary Search Tree Types *Property of STI
Page 13 of 24
___________________ Binary Search Tree Types *Property of STI
Page 15 of 24
___________________

Data Structures and Algorithms Analysis


14 ________________ Data Structures and Algorithms Analysis
16 _________________
___________________ ___________________
2-3-4 trees B-Trees
___________________ ___________________
Insert 18
___________________ ___________________
___________________ ___________________
___________________ Simply move the values of the middle leaf node
to insert 18 ___________________
___________________ ___________________
___________________ ___________________
___________________ Insert 46
___________________
___________________ ___________________
___________________ ___________________
Binary Search Tree Types *Property of STI
Page 14 of 24
___________________ Binary Search Tree Types *Property of STI
Page 16 of 24
___________________
Data Structures and Algorithms Analysis
17 ________________ Data Structures and Algorithms Analysis
19 _________________
___________________ ___________________
Exercise Heap
___________________ a partial sorted binary tree
___________________
From the tree below, insert the following values:
67

54
___________________ Complete ___________________
39
___________________ ___________________
Incomplete
___________________ ___________________
___________________ Implemented as array ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
Satisfies the heap condition

Binary Search Tree Types *Property of STI


Page 17 of 24
___________________ Binary Search Tree Types *Property of STI
Page 19 of 24
___________________

Data Structures and Algorithms Analysis


18 ________________ Data Structures and Algorithms Analysis
20 _________________
___________________ ___________________
Answers Heap
Inserting 67 ___________________ ___________________
___________________ Removal of node in heap means to remove the
maximum key, which this node is always the
___________________
___________________ root
Remove the root
___________________
Inserting 54
___________________ Move the last node into the root

Trickle (bubble) the last node down until its


below a larger node and above a smaller
___________________
___________________ one
___________________
___________________ ___________________
Inserting 39
___________________ ___________________
___________________ ___________________
___________________ ___________________
Binary Search Tree Types *Property of STI
Page 18 of 24
___________________ Binary Search Tree Types *Property of STI
Page 20 of 24
___________________
Data Structures and Algorithms Analysis
21 ________________ Data Structures and Algorithms Analysis
23 _________________
___________________ ___________________
Heap Heap
___________________ ___________________
___________________ Insertion use trickle up ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
Binary Search Tree Types *Property of STI
Page 21 of 24
___________________ Binary Search Tree Types *Property of STI
Page 23 of 24
___________________

Data Structures and Algorithms Analysis


22 ________________ Data Structures and Algorithms Analysis
24 _________________
___________________ ___________________
Heap Heap
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
___________________ ___________________
Binary Search Tree Types *Property of STI
Page 22 of 24
___________________ Binary Search Tree Types *Property of STI
Page 24 of 24
___________________

Das könnte Ihnen auch gefallen