0% found this document useful (0 votes)
14 views3 pages

Ass 2

An AVL tree is a self-balancing binary search tree that maintains the AVL property at each node: the heights of the left and right subtrees differ by at most one. This ensures the tree has height O(log n), providing efficient search, insert, and delete operations in O(log n) time. When an insertion or removal violates the AVL property, subtrees are rebalanced. A Red-Black tree is also a self-balancing binary search tree that uses color properties (red or black nodes) to ensure balancing, providing efficient access like an AVL tree.

Uploaded by

Rao Afrasiab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Ass 2

An AVL tree is a self-balancing binary search tree that maintains the AVL property at each node: the heights of the left and right subtrees differ by at most one. This ensures the tree has height O(log n), providing efficient search, insert, and delete operations in O(log n) time. When an insertion or removal violates the AVL property, subtrees are rebalanced. A Red-Black tree is also a self-balancing binary search tree that uses color properties (red or black nodes) to ensure balancing, providing efficient access like an AVL tree.

Uploaded by

Rao Afrasiab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

AVL TREE

An AVL (Adelson-Velski/Landis) tree is a binary search tree which


maintains the following height-balanced "AVL property" at each node in
the tree:

abs( (height of left subtree) – (height of right subtree) ) ≤ 1

Namely, the left and right subtrees are of equal height, or their heights
differ by 1. Recall that the height of a tree is the maximum depth (from
the root) of any node. A tree with one node has height 0. We will say
that the empty (null) tree has height -1.

It can be proved that an AVL tree with n nodes has height O(log(n)), and
so any n search/insert/delete operations ensuring worst-case search
cost of O(log(n)). The key idea behind the AVL tree is how a subtree is
re-balanced when a node insertion or removal causes the AVL property
to fail. Like the textbook, we will consider only insertions.

FOR EXAMPLE

Following tree is an example of AVL tree-


This tree is an AVL tree because-
It is a binary search tree.
The difference between height of left subtree and right subtree of every
node is at most one.

Red-back tree

Red-Black Tree is a self-balancing Binary Search Tree (BST) where


every node follows following rules.
1) Every node has a color either red or black.
2) Root of tree is always black.
3) There are no two adjacent red nodes (A red node cannot have a red
parent or red child).
4) Every path from a node (including root) to any of its descendant
NULL node has the same number of black nodes.
FOR EXAMPLE
A chain of 3 nodes is nodes is not possible in Red-Black Trees.
Following are NOT Red-Black Trees
30 30 30
/\ / \ / \
20 NIL 20 NIL 20 NIL
/\ /\ / \
10 NIL 10 NIL 10 NIL
Violates Violates Violates
Property 4. Property 4 Property 3

Following are different possible Red-Black Trees with above 3 keys


20 20
/ \ / \
10 30 10 30
/ \ / \ / \ / \
NIL NIL NIL NIL NIL NIL NIL NI

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy