Download presentation
Presentation is loading. Please wait.
Published byTeresa Gilmore Modified over 9 years ago
1
Data Structures Lakshmish Ramaswamy
2
Tree Hierarchical data structure Several real-world systems have hierarchical concepts –Physical and biological systems –Organizations Many other applications –Sorting –Searching –Databases –Internet
3
Tree – Informal Definition Each node has a single parent node except for root which has no parent 9 6 5 3 8 7 root parent nodes children nodes leaf nodes
4
Examples 6 382 7 6 3 7 8 5 7 4 8 a tree a binary tree a Binary search Tree not a tree 7 5 6 a tree and a... 9 6 5 3 8 7
5
Basics of Graph Theory Graph is a set of vertices V = {v 1, v 2,,, v n } and a set of edges connecting them E = {e 1, e 2, …, e M } –Each edge is a tuple of vertices e l = (v i, v j ) A graph is directed if edges are directed (pair of vertices is ordered) Connected graph – Graph where any pair of vertices have a path b/w them Acyclic Graph: A graph with no cycles Tree is a connected acyclic graph
6
Rooted Tree A directed graph with following properties –One node is distinguished as root –Every node c, except root, has exactly one incoming edge from another node p. p is c’s parent. –There exists a unique path from root to any node
7
Tree Properties and Definitions A tree with N nodes has N-1 edges Siblings – Nodes with same parent Ancestor & descendant –If there is a path from u to v, v is the descendant of u & u is the ancestor of v –If u ≠ v, v is proper descendant of u & u is proper ancestor of v
8
Definitions (Contd.) Depth of a node – Length of path from root to node –Depth of root is 0 –Depth of any node is one more than its parent’s depth Height of a node – Length of path from node to deepest descendant leaf Size of a node – Number of descendants of the node (including itself) Height of a tree – Height of the root of the tree
9
Example
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.