0% found this document useful (0 votes)
111 views12 pages

Class 5: Data Structures 2S2019

Tree is a non-linear data structure that stores data hierarchically with nodes linked together. A binary tree restricts each node to have at most two children, called left and right children. A binary search tree (BST) is a binary tree where the left subtree of a node contains values less than the node's value and the right subtree contains values greater than the node's value, allowing for efficient searching. An AVL tree is a self-balancing BST where the heights of left and right subtrees can differ by at most one, guaranteeing O(log n) time for operations. Trees can be traversed in preorder, inorder, and postorder manners.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views12 pages

Class 5: Data Structures 2S2019

Tree is a non-linear data structure that stores data hierarchically with nodes linked together. A binary tree restricts each node to have at most two children, called left and right children. A binary search tree (BST) is a binary tree where the left subtree of a node contains values less than the node's value and the right subtree contains values greater than the node's value, allowing for efficient searching. An AVL tree is a self-balancing BST where the heights of left and right subtrees can differ by at most one, guaranteeing O(log n) time for operations. Trees can be traversed in preorder, inorder, and postorder manners.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CLASS 5

Data Structures 2S2019


Tree

Is a non-linear data structure, used to store data in a hierarchically way. It can be


defined recursively as a collection of nodes (starting at the root node), where each node
is a data structure consisting of values or attributes, and can have pointers linking to
other nodes often called children .
Binary Tree

Is a special case of the Tree data structure, in which a node can only have at most 2
children hence the name binary. Since a binary tree can only have 2 nodes they are
usually called left and right child.
Binary Search Tree (BST)

Is a special case of the Binary tree which is Ordered sometimes called Sorted Binary
Tree. In this tree the left subtree of any node only contains nodes with keys lesser than
the node’s key and the right subtree of any node only contains nodes with keys greater
than the node’s key. In this case the nodes “key” is a special attribute of each node that
is used to keep their keys in sorted order, this tree is often used to make searching
more efficiently (fast lookup) hence the name Binary Search Tree. This tree allows every
operation to skip about half of the tree thus making the average complexity of a search
operation of O(log n).
AVL Tree

Is a modification of the Balanced Search Tree (BST) where the difference between
heights of left and right subtrees of any node cannot be more than one for all nodes,
this is referred as “Self-balancing”. AVL trees solve the problem with normal Binary
Search Trees which commonly take O(h) time where h is the height of the Binary each
Tree, by making sure that the height of the tree always remains O(log n) after every
insertion or deletion, we guarantee O(log n) time for all these operations.
■ Height (of a tree): The number of edges between the tree’s root and its furthest leaf.
■ Depth (of a node): The number of edges from the root to the node.
■ Level (of a node): Depth + 1.
Other Trees

■ Red-Black Tree
■ AA Tree
■ Splay Tree
■ B Tree
Tree Traversal

Unlike linear data structures, which can only be traversed in one logical way, Trees can
be traversed in 3 main different ways.
■ Inorder: Left -> Root -> Right
■ Preorder: Root -> Left -> Right
■ Postorder: Left -> Right -> Root
■ Inorder: 1,2,3,5,6,7,8
■ Preorder: 5,2,1,3,7,6,8
■ Postorder: 1,3,2,6,8,7,5

You might also like