0% found this document useful (0 votes)
12 views35 pages

Not Avl Tree: Sorted (Order) : Yes

The document provides an overview of tree data structures, including definitions of various tree types such as general trees, forests, binary trees, and binary search trees. It explains key concepts like root nodes, leaf nodes, tree traversal methods, and the properties of AVL trees and B-trees. Additionally, it discusses the importance of tree height and balance in relation to search efficiency.

Uploaded by

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

Not Avl Tree: Sorted (Order) : Yes

The document provides an overview of tree data structures, including definitions of various tree types such as general trees, forests, binary trees, and binary search trees. It explains key concepts like root nodes, leaf nodes, tree traversal methods, and the properties of AVL trees and B-trees. Additionally, it discusses the importance of tree height and balance in relation to search efficiency.

Uploaded by

sreedharonedrive
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Not AVL

Tree
Sorted (Order): Yes

Height: No
AVL Tree or Not

Not AVL
Tree
AVL Tree

AVL Tree
AVL Tree
Not AVL
Tree
Inserting node
MISC Slides
Tree
 A tree is recursively defined
as a set of one or more
nodes where one node is
designated as the root of the
tree and all the remaining
nodes can be partitioned into
non-empty sets each of
which is a sub-tree of the
root
Tree
 Root node: The root node A is the topmost
node in tree. If A = NULL, then it means tree is
empty.
 Sub-trees: If root node A is not NULL, then the
trees T1, T2, and T3 are called sub-trees of A.
 Leaf node: A node that has no children is
called the leaf node or the terminal node
(E,FJ,K,H,I).
 Path: A sequence of consecutive edges is
called a path. Path from root node A to node I
is given as: A, D, and I
 Ancestor node: An ancestor of a node is
any predecessor node on the path from root
to that node. The root node does not have
any ancestors. nodes A, C, and G are the
ancestors of node K.
 Descendant node: A descendant node is
any successor node on any path from the
node to a leaf node. Leaf nodes do not have
any descendants. Nodes C, G, J, and K are
the descendants of node A.
 Level number: Every node in the tree is
assigned a level number in such a way that
the root node is at level 0, children of the
root node are at level number 1. Thus,
every node is at one level higher than its
parent. So, all child nodes have a level
number given by parent’s level number + 1
 Degree: Degree of a node is
equal to the number of
children that a node has. The
degree of a leaf node is zero.
 In-degree: In-degree of a
node is the number of edges
arriving at that node.
 Out-degree: Out-degree of a
node is the number of edges
leaving that node
Types of Trees
 1. General trees: Stores elements hierarchically
 2. Forests: ordered set of zero or more general
trees
 3. Binary trees: every node in tree contains a left sub-
tree and a right sub-tree
 4. Binary search trees
 5. Expression trees
 6. Tournament trees
General Trees
 Stores elements hierarchically.
 top node of a tree is the root node and
each node, except the root, has a
parent.
 General trees which have 3 sub-trees
per node are called ternary trees
Forests
 A forest is a disjoint union of trees. A set of disjoint trees (or forests)
is obtained by deleting the root and the edges connecting the root
node to nodes at level 1.
 every node of a tree is the root of some sub-tree. Therefore, all the
sub-trees immediately below a node form a forest.
 A forest can also be defined as an ordered set of zero or more general
trees.
 a general tree must have a root, a forest on the other hand may be
empty because by definition it is a set, and sets can be empty.
 we can convert a general tree into a forest by deleting the root node
of the tree
Binary Trees
 A binary tree is a data structure that is defined as a collection
of elements called nodes.
 In a binary tree, the topmost element is called the root node,
and each node has 0, 1, or at the most 2 children.
 A node that has zero children is called a leaf node or a
terminal node.
 A binary tree is recursive by definition as every node in tree
contains a left sub-tree and a right sub-tree. Even terminal
nodes contain an empty left sub-tree and an empty right sub-
tree
InOrder Tree Traversal
InOrder Tree
Traversal

1. Go to the left subtree.


2. Visit node.
3. Go to the right subtree.
PreOrder
Tree
Traversal
1. Visit node.
2. Go to the left subtree.
3. Go to the right subtree.
PostOrder
Tree
Traversal
1. Go to the left subtree.
2. Go to the right subtree.
3. Visit the node.
Binary Search Trees
 A binary search tree has these
properties for each of its nodes
 All the values in the node's left subtree is
less than the value of the node itself.
 All the values in the node's right subtree is
greater than the value of the node itself.
BST: Arranging keys
BST Vs AVL
 The cost of lookup is determined by
 how far down the tree we need to go
  if the key is in the tree, the worst case
 is when it is in a leaf
AVL Tree: Intro
 balanced tree: One whose subtrees differ in
height by at most 1 and are themselves
balanced.
 The runtime of adding to / searching a BST is
closely related to height.
 The number of nodes on the longest path
from the root to a leaf is called the height of
the tree
Height of tree: Mathematical
definition
 A tree is balanced if h ε O(log n)
 where h is its height and
 n is the number of nodes
 On a balanced tree, lookup, insert and find_min cost O(log n)
 Height is max number of nodes in path
from root to any leaf.
AVL Tree: Height
Height of leaf nodes is 0
ie., nodes 25, 65,85,125 and 175 heights
are 0
Node 75 height?
Height of left subtree-height of right subtree
=1-1
=0

Node 50 height?
Height of left subtree-height of right subtree
=1-2
= -1
B - tree
 B-tree is a special type of self-balancing search tree in which each node
can contain more than one key and can have more than two children.
 B- tree is a multiway search tree. A node in B-tree of order n can have at
most n-1 values and n children.
 All values that appear on the left sub-tree are smaller than left most
value in the parent node.
 All values that appear on the right sub-tree are greater than right most
value in the parent node.
 All values that appear on the middle sub-tree are greater than leftmost
value in parent node and smaller than right most value in parent node.
•For each node x, the keys are stored in increasing order.
•In each node, there is a boolean value [Link] which is true if x is

a leaf.
•If n is the order of the tree, each internal node can contain at

most n - 1 keys along with a pointer to each child.


•Each node except root can have at most n children and at least

n/2 children.
•All leaves have the same depth (i.e. height-h of the tree).
•The root has at least 2 children and contains a minimum

of 1 key.
•If n ≥ 1, then for any n-key B-tree of height h and

minimum degree t ≥ 2, h ≥ log (n+1)/2.


t

You might also like