Status: Tags: #cards/cmpt225/dataStructures/adt/trees Links: Data Structures - Mathematical Induction
Rooted Tree
Principles
-
No cycles/loops, only 1 path to get from a node to another
-
Vertices are either root, node, or leaf
-
Height/depth of tree is maximal depth of node in a tree
- If n vertices, must be at least log(N)-1, must be at most N-1
- Therefore d+1>$log_2(N)$, hence d>$log_2(N)-1$
-
Considered full if for all k<=depth, it has 2k notes in level k
-
Size of tree is number of nodes in the tree
Big O Notation
Properties
Property of tree: unique path from root node to any other node Max height of a tree with n nodes is ;; n-1
Minimum height of a tree with n nodes is ;; floor(log2n)
Number of nodes in a h tall binary tree can range from ;; h to $2^h-1$
Nodes
Height of a node v ?
- Length of longest path from node v to a leaf
Level of a node v ?
- Root is 1, down from there
Depth ?
- length of path from v to root
Degree of a node ? Number of edges that touch a node v
- Internal has deg > 1
- External node = 1 or < 1
Types
Full tree ?
- All nodes at level < h have max number of children
Complete tree ?
- Full all way to h-1 with level h filled in from left to right without any gap
- Can only be far left with H nodes but would be complete since no gap
Balanced tree ?
- N-ary tree with all n subtrees of any nodes have height that differ by at most 1
Operations
Overview
|
|
InsertR
Examples
Implementation
struct BTnode {
int data; //struct BTnode* left; // left child
struct BTnode* right; // right child
struct BTnode* parent;
}
typedef struct BTnode BTnode_t;
struct binary_tree {
struct BTnode* root;
}
Inserting
|
|
Retrieving
|
|
Backlinks
|
|
References:
Created:: 2021-11-04 08:56